|
Boost Users : |
Subject: Re: [Boost-users] large enum and native array indexing
From: Hicham Mouline (hicham_at_[hidden])
Date: 2009-01-15 05:34:38
>I would say that the easiest way is to use the preprocessor.
>#define BOOST_PP_LOCAL_MACRO(n) template<> struct
>Position<BOOST_PP_CAT(OP, n)> { 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,
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