Boost mpl - append an element for each element in a vector

83 Views Asked by At

I have a boost mpl vector with types in it (obviously). I want to, after declaring this vector, iterate over it and append each type, wrapped in another template, to that vector. I have tried many things but for the life of me I can't figure this one out. I'm not sure if it's even possible to change an mpl vector when iterating over it, like, does iterator invalidation work the same as in the STL? Basically, what I have is this:

typedef boost::mpl::vector<int, float, double> MyTypes;
template<typename T> struct wrapper { T _value; };

and then I want to add wrapper<int>, wrapper<float> and wrapper<double> to MyTypes. Of course in my real code I have many more types that I don't want to duplicate.

So I'm thinking this should be possible, like by combining boost::mpl::fold with boost::mpl::back_inserter in some way, but I can't figure it out... Thanks.

0

There are 0 best solutions below