Boost logo

Boost Users :

From: Ares Lagae (ares.lagae_at_[hidden])
Date: 2007-05-10 04:11:34


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<int8, int16, int32, uint8, uint16, uint32,
float32, float64> types;

// a typedef of a fusion map with a variable for each type
typedef boost::fusion::map<
  boost::fusion::pair<int8, my_type_depending_on<int8> >
  boost::fusion::pair<int16, my_type_depending_on<int16> >
  boost::fusion::pair<int32, my_type_depending_on<int32> >
  boost::fusion::pair<uint8, my_type_depending_on<uint8> >
  boost::fusion::pair<uint16, my_type_depending_on<uint16> >
  boost::fusion::pair<uint32, my_type_depending_on<uint32> >
  boost::fusion::pair<float32, my_type_depending_on<float32> >
  boost::fusion::pair<float64, my_type_depending_on<float64> >
> 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<uint8, uint16, uint32> size_types;

// an mpl vector containing all the scalar types
typedef boost::mpl::vector<int8, int16, int32, uint8, uint16, uint32,
float32, float64> scalar_types;

now i need a variable for each combination of size_types and scalar types.
Something like

typedef boost::fusion::map<
  boost::fusion::pair<uint8, int8, my_type_depending_on<uint8, int8> >
  boost::fusion::pair<uint8, int16, my_type_depending_on<uint8, int16> >
  boost::fusion::pair<uint8, int32, my_type_depending_on<uint8, int32> >
  boost::fusion::pair<uint8, uint8, my_type_depending_on<uint8, uint8> >
  boost::fusion::pair<uint8, uint16, my_type_depending_on<uint8, uint16> >
  boost::fusion::pair<uint8, uint32, my_type_depending_on<uint8, uint32> >
  boost::fusion::pair<uint8, float32, my_type_depending_on<uint8, float32> >
  boost::fusion::pair<uint8, float64, my_type_depending_on<uint8, float64> >

  boost::fusion::pair<uint16, int8, my_type_depending_on<uint16, int8> >
  boost::fusion::pair<uint16, int16, my_type_depending_on<uint16, int16> >
  boost::fusion::pair<uint16, int32, my_type_depending_on<uint16, int32> >
  boost::fusion::pair<uint16, uint8, my_type_depending_on<uint16, uint8> >
  boost::fusion::pair<uint16, uint16, my_type_depending_on<uint16, uint16> >
  boost::fusion::pair<uint16, uint32, my_type_depending_on<uint16, uint32> >
  boost::fusion::pair<uint16, float32, my_type_depending_on<uint16, float32>
>
  boost::fusion::pair<uint16, float64, my_type_depending_on<uint16, float64>

  boost::fusion::pair<uint32, int8, my_type_depending_on<uint32, int8> >
  boost::fusion::pair<uint32, int16, my_type_depending_on<uint32, int16> >
  boost::fusion::pair<uint32, int32, my_type_depending_on<uint32, int32> >
  boost::fusion::pair<uint32, uint8, my_type_depending_on<uint32, uint8> >
  boost::fusion::pair<uint32, uint16, my_type_depending_on<uint32, uint16> >
  boost::fusion::pair<uint32, uint32, my_type_depending_on<uint32, uint32> >
  boost::fusion::pair<uint32, float32, my_type_depending_on<uint32, float32>
>
  boost::fusion::pair<uint32, float64, my_type_depending_on<uint32, float64>
>

> 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/

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