Register variadic template as tags in a boost::mpl::map
In the following code, why can't I look up BB and CC in the mpl::map type_map?
I would expect the map to look like this:
map <
pair
::type type_map;
template <typename T> int get_offset() {
return boost::mpl::at
Ahh.... found it. Just a typo
template<int OFFSET> struct B { typedef AA T; // ! Must be BB... enum O { offset = OFFSET }; enum S { size = 4 }; };
Sorry for wasting your time On Sat, Jan 7, 2012 at 12:55 PM, Allan Nielsen wrote:
In the following code, why can't I look up BB and CC in the mpl::map type_map?
I would expect the map to look like this:
map < pair
>, pair >, pair > > But it does not seem like this is the case...
#include <iostream> #include
#include #include #include struct AA {}; struct BB {}; struct CC {};
template<int OFFSET> struct A { typedef AA T; enum O { offset = OFFSET }; enum S { size = 2 }; };
template<int OFFSET> struct B { typedef AA T; enum O { offset = OFFSET }; enum S { size = 4 }; };
template<int OFFSET> struct C { typedef AA T; enum O { offset = OFFSET }; enum S { size = 4 }; };
template < template <int> class Head, template <int> class... Tail> struct X : public Head< X
::size * X ::offset >, public X { typedef Head< X ::size * X ::offset > _Head; enum O { offset = X
::size * X ::offset }; enum S { size = _Head::size * X ::size }; typedef typename boost::mpl::insert < typename X
::type_map, boost::mpl::pair ::type type_map;
template <typename T> int get_offset() { return boost::mpl::at
::type:: offset; } }; // base case template < template <int> class Head> struct X<Head> : public Head<1> { enum O { offset = Head<1>::offset }; enum S { size = Head<1>::size };
typedef boost::mpl::map< boost::mpl::pair< typename Head<1>::T, Head<1> > > type_map; };
int main() { X< A, B, C > x1;
std::cout << x1.get_offset<CC>() << std::endl;
// generates compile errors //std::cout << x1.get_offset<BB>() << std::endl; //std::cout << x1.get_offset<CC>() << std::endl;
return 0; }
participants (1)
-
Allan Nielsen