vendredi 3 février 2017

c++: how to create a variadic sequence from struct members

Suppose I have a templated class that is supposed to be called like this:

struct mystruct
{
   int    member1;
   long   member2;
   string member3;
};

Now I want to create a boost::mpl::vector that will effectively contain types of all the members in the struct (preferably in the same order):

using membervector1 = boost::mpl::vector<int, long, string>;

Of course I want the syntax to templated with respect to my struct, like this:

using membervector2 = some_smart_template<mystruct>;
static_assert(std::is_same<membervector1, membervector2>::value);

Aucun commentaire:

Enregistrer un commentaire