Boost logo

Boost Users :

Subject: [Boost-users] Generating a large number of class member variables: PP vs mpl
From: Hicham Mouline (hicham_at_[hidden])
Date: 2009-01-19 05:16:18


Hello,
I have a base class with a number of derived classes. Derived classes might have large number of private member variables, each with a different type. Some of these derived classes may have identical lists of member names and types.

I seem to have 2 possibilities to generate the list of member variables:

class Derived1 {
...
typedef mpl::vector< Type1, Type2, Type3, Type4, Type5, Type6 > memberTypes;
// then try to generate automatically from memberTypes, as:
// const Type1& mType1;
// const Type2& mType2;...
// const Type6& mType6;
// with some meta function
};

or // use only PP

class Derived1 {
...
#define MYNAMESPACE_MEMBER_TYPES (Type1)(Type2)(Type3)(Type4)(Type5)(Type6)
// use PP macros to generate the members
};

Is it possible to generate the members from the mpl::vector<> ?
in particular, willing to use the mpl::size meta function will forbid me from using PP...
The advantage I think is a cleaner definition of types, and other derived classes
may use the same type memberTypes.
The code generating the member types could isolated in some user meta function.

regards,


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