Boost logo

Boost Users :

From: Khalil Shalish (kshalish_at_[hidden])
Date: 2007-01-09 15:51:34


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.

Thank you,
Khalil Shalish
kshalish_at_[hidden]


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