Boost logo

Boost Users :

Subject: Re: [Boost-users] class composition
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-01-13 13:19:52


AMDG

Hicham Mouline wrote:
> There is an example listed in "C++ template metaprogramming" to generate a class with its members from an mpl sequence:
>
> template <typename T>
> struct wrap { typedef T value; };
>
> typedef mpl::vector< type1, type2, type3 > member_types;
> mpl::inherit_linearly< member_types, mpl::inherit< wrap<_2>, _1 > >::type generated;
>
>
> but then, the generated class did not look like this:
>
> class C {
> type1 t1;
> type2 t2;
> type3 t3;
> };
>
>
> Can one do that with BOOST_PP and sequences from preprocessor libs instead?
>

You can--or you can just use fusion.

boost::fusion::as_vector<member_types>::type v;

boost::fusion::at_c<0>(v); // object of type type1
boost::fusion::at_c<1>(v); // object of type type2

In Christ,
Steven Watanabe


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net