
Hello everyone. We talked a few days ago about the design of the check library (about the compile or run-time weight parameter.) Reminder : the weights are the contribution to the running sum of a digit in a number. I used and followed your ideas and suggestions that bring me to the policies class. 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. While we speak about the design, what do you think about the policies class ? There are useful because the core of the algorithm is the same for every checks. Every critics or suggestions are welcomed, thank you, Pierre Talbot.

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

On 08/02/2011 12:03 AM, Jeffrey Lee Hellrung, Jr. wrote:
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.
template<int weight0, int weight1 = invalid_weight, int weight2 = invalid_weight, ...> struct weight_policy; template<int weight0> struct weight_policy<weight0> { /* definition */ }; template<int weight0, int weight1> struct weight_policy<weight0, weight1> { /* definition */ }; etc. is enough. The extra parameters already have defaults, so it's not needed to repeat them. Though I do not see what the point of that policy is.

2011/8/2 Mathias Gaunard <mathias.gaunard@ens-lyon.org>:
On 08/02/2011 12:03 AM, Jeffrey Lee Hellrung, Jr. wrote:
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.
template<int weight0, int weight1 = invalid_weight, int weight2 = invalid_weight, ...> struct weight_policy;
template<int weight0> struct weight_policy<weight0> { /* definition */ };
template<int weight0, int weight1> struct weight_policy<weight0, weight1> { /* definition */ };
etc. is enough.
The extra parameters already have defaults, so it's not needed to repeat them.
Thank you for the procedure.
Though I do not see what the point of that policy is.
Maybe an error to isolate the characterics of a check ? I did it because it was useful to create different behavior in a same function ; but maybe the weight don't create a different behavior and just add information on the number to check. So perhaps it would be a good idea to pass it in a different template argument that we won't call a "policy". What do you think about it ? Thank you, Pierre Talbot.
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
participants (3)
-
Jeffrey Lee Hellrung, Jr.
-
Mathias Gaunard
-
Pierre Talbot