Recursive templates

J

Jon Slaughter

For anyone, though I doubt anyone, who as been following my recent
adventures with trying to do recursive templates it seems that I have finaly
got everything to work out right.

It actually ends up being very "elegant" one I was able to get a certain
template to do most of the work.

Anyways, wheres some code that shows the results(though ofcourse its just
the basics, still much work to do):


#include <iostream>
#include <string>
using namespace std;

#include <Loki/TypeList.h>
#include <Mine/nTree.h>
using namespace Loki;
using namespace nTree;


// Creates a list of classes having the appropriate base class give in the
Typelist
template <int I, class TList>
struct Tree : NodeWithLoc<TList, I, 0>::Result::Class
{
Tree<I-1, TList> List;
void TreeFunc() { cout << I << " - TreeFunc()\n"; };
};

// Ends the recursive process
template <class TList>
struct Tree<0, TList> : NodeWithLoc<TList, 0, 0>::Result::Class
{
void EndList();
};


struct MyClass1 { void Func1(){ cout << "Func1()\n"; }; };
struct MyClass2 { void Func2(){ cout << "Func2()\n"; }; };

void main()
{
typedef Node<2, 0, MyClass1> N1;
typedef Node<1, 0, MyClass2> N2;
typedef TYPELIST_2(N1, N2) Q;
Tree<4, Q> S;


// Shows a little of the structure
S.TreeFunc();
S.List.TreeFunc();
S.List.List.TreeFunc();
S.List.List.List.TreeFunc();
S.Null();
S.List.Null();
S.List.List.Func1();
S.List.List.List.Func2();



///////////////////////////////////
cout << endl;
system("PAUSE");
return;
};


Null is a method in the NullNode that is returned when no match is found...
I put it in only for testing. You can find the nTree code in my previous
post so I won't post it again(only difference is name space and Null()
added).


Anyways, the MAIN damn problem is that this has broken the damn intellisense
in VS2k5 ;/ really sucks because else it can get confusing real quick
without having a list of methods that S provides. Wondering if there is an
"intellisense" that might work on this that I could use... also, where would
I report this or does anyone know how it could be fixed(maybe my coding
method is bad and its confusing the thing)? The intellisense is pretty
integral in my project and if this breaks it I'm not sure if I should use
this method since my other method of having a utility do the "recursion"
doesn't screw up anything. Its not as general but it does work. I can't
live without intellisense ;/ Brain is to small ;/

Thanks,
Jon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top