
I have a list of fundamental types (known at compile time). For each of
these types I want to declare a templated member in a class.
So, instead of
class foo {
private:
int int_variable;
double double_variable;
... /* rest of types */
};
I want something like
class foo {
private:
variable_list

Ares Lagae wrote:
Hi, you could try: Boost.Fusion (only in CVS) or Boost.Tuple (http://boost.org/libs/tuple/doc/tuple_users_guide.html). -- HTH, dave

David Klein wrote:
Boost.Tuple (http://boost.org/libs/tuple/doc/tuple_users_guide.html).
Boost.Tuple is close to what I want. However, I want to access based on type
rather than index. E.g. I when I have a typelist
typedef boost::mpl::vector
Boost.Fusion (only in CVS)
I will have a look at the Fusion library. -- Ares Lagae Computer Graphics Research Group, Katholieke Universiteit Leuven http://www.cs.kuleuven.be/~ares/

Jeffrey Holle wrote:
Union-like containers are not suited, because I want a variable for _each_ of the types. See my other post about boost::fusion::map. -- Ares Lagae Computer Graphics Research Group, Katholieke Universiteit Leuven http://www.cs.kuleuven.be/~ares/

Joaquín, Mª López Muñoz wrote:
Joaquín,
Thank you very much! This is (almost) exactly what I want. I have a couple
of questions though.
1/
Consider
typedef variable_list_seq

Ares Lagae ha escrito: [...]
Yep, this can be done adding an optional template parameter to variable_list_seq, as shown in the example attached. Note that variable_list_member is not elminated, but merely supplemented with your my_type metafunction so as to be able to customize member types.
Again, starting from the simpler variable_list_seq one can write a new
product_variable_list_seq working on the cartesian product of two MPL
sequences:
template<typename T> struct pair_with:boost::mpl::pair
{}; The file attached also exercises a possible implementation. Things are a little more complex now, I strongly suspect this kind of stuff can be more easily done with fusion, but alas I haven't had time to learn about that lib. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

Thanks, This is how I thought it could be done, but I don't have enough experience with the Boost::MPL library yet to actually code it and get it compiled without errors :-) I have the template metaprogramming book at home. That should help me to understand the code in detail. Best regards, -- Ares Lagae Computer Graphics Research Group, Katholieke Universiteit Leuven http://www.cs.kuleuven.be/~ares/

I thing the first problem can be solved using Boost.Fusion:
// the names of the types in the application
typedef char int8;
typedef short int16;
typedef int int32;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef float float32;
typedef double float64;
// an mpl vector containing all the types
typedef boost::mpl::vector
map_type;
// the variables
map_type variables;
// use a variable
at<int8>(variables)
However, there is a lot of redundancy in the boost::fusion::map typedef. Is
there any way to obtain the boost::fusion::map typedef automatically from
the boost::mpl::vector?
I have the following related problem.
// an mpl vector containing all the size types
typedef boost::mpl::vector
boost::fusion::pair
boost::fusion::pair
map_type;
Again, I want to obtain the boost::fusion::map typedef automatically from the two boost::mpl::vectors. -- Ares Lagae Computer Graphics Research Group, Katholieke Universiteit Leuven http://www.cs.kuleuven.be/~ares/
participants (4)
-
Ares Lagae
-
David Klein
-
Jeffrey Holle
-
Joaquín Mª López Muñoz