
On Mon, Aug 1, 2011 at 12:15 PM, Pierre Talbot < pierre.talbot.6114@herslibramont.be> wrote: [...]
I tried to extract the characteristics of a "generic" check and the weight is one of these. So I tried to implement the weight policy class :
#define _WEIGHT_factory(z,n,unused) \ template<BOOST_PP_ENUM_PARAMS(n, int weight)> \ struct weight_policy \ { typedef typename boost::mpl::vector_c<int BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, weight)> weight ; } ; \
BOOST_PP_REPEAT_FROM_TO(1,BOOST_CHECK_LIMIT_WEIGHTS,_WEIGHT_factory,~)
#undef _WEIGHT_factory
But the compiler doesn't like the "struct template parameter overloading". Is a limit of the language ? Or am I doing it in the wrong way ? If it's impossible, I though that we could passed the weights to a function that aimed to "build" the vector_c type.
[...] You'll have to generate something like template< int = invalid_weight, int = invalid_weight, /* repeat some pp constant # of times, e.g., BOOST_CHECK_LIMIT_WEIGHTS times */, int = invalid_weight > struct weight_policy; template< int weight0 > struct weight_policy< weight0, invalid_weight, invalid_weight, /* ...and so on... */, invalid_weight > { /* definition */ }; template< int weight0, int weight 1 > struct weight_policy< weight0, weight1, invalid_weight, /* ...and so on... */, invalid_weight > { /* definition */ }; You'll need to make use of BOOST_PP_SUB to generate the sequence of "invalid_weight"s in the specializations. Also, you may want to have 2 weight policies, weight_policy which takes a sequence of Boost.MPL integral constants, and weight_policy_c which takes a sequence of (literal) integral constants (cf. vector and vector_c). - Jeff