I want to compile a list (actually: a set) of types at compile time by adding types one by one. Something like that:
struct HeadOfList; struct Item1; [ addToList<Item1, HeadOfList> ] struct Item2; [ addToList<Item2, HeadOfList> ]
I don't care how the list is stored. I am thinking of something like this:
template<typename T> struct NextInList { typedef void type; }; template<> struct NextInList<HeadOfList> { typedef Item1 type; }; template<> struct NextInList<Item1> { typedef Item2 type; }; template<> struct NextInList<Item2> { typedef Item3 type; };
but a boost::mpl::list
just as good. The type order is also irrelevant, I just want them to be able to go through them and add new elements to them.
I have a bad idea about this, because such a construction will mean that, for example, LastElementOf<MyList>::type
will be compiled for different types at different points in the source file (before and after adding a new element), and it seems fictitious to me. However, this is exactly what I want now.
Do you think this is possible? Allowed C ++ 11.
Update: I just want to add that I do not know the last element added to the list when adding a new element, but I know the list itself (for example, the head of the list)
source share