Re: [Boost-users] Generating a large number of class member variables: PP vs mpl

I just realized you can instantiate fusion vector objects (forgot fusion is about runtime too) So I have this example: struct A { explicit A(int) {} }; struct B { explicit B(int) {} }; struct C { explicit C(int) {} }; class Derived1 { public: Derived1 () : members( A(5), B(5), C(5) ) {} private: const boost::fusion::vector< A, B, C > members; }; All members are constructed with the same argument(s) : 5 Now: 1. I may have 20 members in vector.... Is there a way not to explicitly construct them in the Derived1 ctor 2. Derived3 and Derived7 have the same vector of members. Is there a way, inside Derived3 and 7, to take the vector from Derived1?
----- Original Message ----- From: "Joel Falcou"
To: boost-users@lists.boost.org Subject: Re: [Boost-users] Generating a large number of class member variables: PP vs mpl Date: Tue, 20 Jan 2009 11:25:30 +0100 Hicham Mouline a écrit :
But once I have my mpl::vector or fusion::vector, how do i apply a meta function like for_each to generate the class members automatically.
fusion::vector does generate the members for you.

AMDG Hicham Mouline wrote:
I just realized you can instantiate fusion vector objects (forgot fusion is about runtime too)
So I have this example:
struct A { explicit A(int) {} };
struct B { explicit B(int) {} };
struct C { explicit C(int) {} };
class Derived1 { public: Derived1 () : members( A(5), B(5), C(5) ) {} private: const boost::fusion::vector< A, B, C > members; };
All members are constructed with the same argument(s) : 5
Now: 1. I may have 20 members in vector.... Is there a way not to explicitly construct them in the Derived1 ctor
You need to create a fusion sequence that consists of the same arguments repeated many times. template<class T> struct constant { constant(const T& v) : value(v) {} T value; typedef T result_type; template<class U> T operator()(const U&) const { return(value); } }; ... members(boost::fusion::transform_view(boost::mpl::range_c<0, 20>(), constant<int>(5)))
2. Derived3 and Derived7 have the same vector of members. Is there a way, inside Derived3 and 7, to take the vector from Derived1?
fusion containers can be copied from each other. The copy will be done member wise. In Christ, Steven Watanabe
participants (2)
-
Hicham Mouline
-
Steven Watanabe