Khalil Shalish wrote:
Hello,
I created the following composite class using mpl::inherit_linearly:
template <class T> struct DataField { T data; }
typedef mpl::inherit_linearly< mpl::vector< int, int, int> mpl::inherit< DataField<_2>, _1 >
Int3Composite;
Int3Composite int3comp;
Since the type of each data field is an int, I cannot use the type of the field to access the data in the field.
Q: Is there a way to write a template (call it get_field) to access the data using numeric position in the type sequence. Something like this:
int field_0 = get_field<0>(in3comp); //This returns the first int data field. int field_1 = get_field<1>(int3comp);
I am very new to C++ template programming and any help on this will be very much appreciated.
Is the use of mpl::inherit_linearly merely to create a structure with
data from an MPL type sequence? If yes, you can simply use Fusion.
Example:
typedef mpl::vector