Re: [Boost-users] [boost.mpl] Implementing a numeric index access to fields of a composite class created with mpl::inherit_linearly
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
Hi!
you could use an mpl::pair type to produce a static mapping of int value to type:
mpl::pair
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@austin.rr.com _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
With Kind Regards, Ovanes
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
Ahh, sorry I also forget to mention, to make linear derivation as you wish,
you must always produce a unique type, which is ensured with the pair_c
construct.
Otherwise you get the following simplified scenario:
template <class T>
struct DataField {
T data;
};
class SomeClass : public DataField<int>, DataField<int>, DataField<int>
{
...
};
In such a case compiler will produce a warning, which states that it will
only derive once from DataField<int>.
With Kind Regards,
Ovanes
-----Original Message-----
From: Ovanes Markarian [mailto:om_boost@keywallet.com]
Sent: Wednesday, January 10, 2007 9:30 PM
To: boost-users@lists.boost.org
Subject: Re: [Boost-users] [boost.mpl] Implementing a numeric index access
to fields of a composite class created with mpl::inherit_linearly
Hi!
you could use an mpl::pair type to produce a static mapping of int value to
type:
mpl::pair
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@austin.rr.com _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
With Kind Regards, Ovanes _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (1)
-
Ovanes Markarian