lundi 30 mars 2015

C++ metaprogramming assign unique ID to tree structures

I have an odd problem. I have a metaprogramming type defined like so:



template <int N, typename... Args>
struct mytype {
...
};


By default, I create them like this:



using type = mytype<-1, mytype<-1, mytype<-1, ...>>>;


Later on, I need to recurse through the type and recursively set each number to a unique ID. The IDs need to be sequential and start at 0 for long technical reasons. For instance, if I had this:



mytype<-1
mytype<-1, a, b>
>


I want it to become something like this:



mytype<0,
mytype<1, a, b>
>


It doesn't matter the order for the numbers' assignment.


I don't quite know how to approach this problem and have tried several things that didn't get anywhere. Any help would be greatly appreciated.


Aucun commentaire:

Enregistrer un commentaire