Re: [Boost-users] large enum and native array indexing

I would say that the easiest way is to use the preprocessor. #define BOOST_PP_LOCAL_MACRO(n) template<> struct Position
{ static const size_t value = n - 1; }; #define BOOST_PP_LOCAL_LIMITS (1, MAX_OP) #include BOOST_PP_LOCAL_ITERATE() In Christ, Steven Watanabe
I think I wasn't clear enough: the 3rd party lib (which I can't change of course) provides, enum Op { OPone = 7, OPtwo = 9, OPthree = 45, OPfour = 7667 // there is no pattern in the names nor the numbers. }; // in fact, there are a hundred entries and I wished to generate from Op template<> struct Position<OPone> { static const int value = 0; } template<> struct Position< OPtwo > { static const int value = 1; } template<> struct Position< OPthree > { static const int value = 2; } template<> struct Position< OPfour > { static const int value = 2; } I suppose there is no way to automagically generate the template specs from the enum? regards,

AMDG Hicham Mouline wrote:
I think I wasn't clear enough:
the 3rd party lib (which I can't change of course) provides, enum Op { OPone = 7, OPtwo = 9, OPthree = 45, OPfour = 7667 // there is no pattern in the names nor the numbers. }; // in fact, there are a hundred entries
and I wished to generate from Op
template<> struct Position<OPone> { static const int value = 0; } template<> struct Position< OPtwo > { static const int value = 1; } template<> struct Position< OPthree > { static const int value = 2; } template<> struct Position< OPfour > { static const int value = 2; }
I suppose there is no way to automagically generate the template specs from the enum?
No there isn't. There is no way to introspect the members of an enum.
The best you can do would be
typedef boost::mpl::vector_c
participants (2)
-
Hicham Mouline
-
Steven Watanabe