boost parameter - overloading on keyword "signature"

hello, i have something like this: *hpp : namespace tag{ template<typename Id> struct sequence{ static ::boost::parameter::keyword< a_<Id> >& a; static ::boost::parameter::keyword< b_<Id> >& b; static ::boost::parameter::keyword< arg_method_<Id> >& arg_method; }; } namespace sequence_arg{ struct method{}; struct a:public method{}; struct b:public method{}; } class sequence{ public: template<typename Id,typename ArgPack> sequence(const Id& id,const ArgPack&args){ fill_elements(id,args,args[tag::sequence<Id>::arg_method]); } private: template<typename Id,typename ArgPack> void fill_elements( const Id& id, const ArgPack& args, sequence_arg::a method ); template<typename Id,typename ArgPack> void fill_elements( const Id& id, const ArgPack& args, sequence_arg::b method ); }; *.cpp : sequence seq( id(), ( tag::sequence::a = a_value, tag::sequence::arg_method = sequence_arg::a() ) ); So far so good except there is redundancy of information about which method to use, so I'm looking for a way to be able to call say sequence seq( id(), ( tag::sequence::a = a_value ) ) Any suggestion?

on Mon Sep 08 2008, e r <erwann.rogard-AT-gmail.com> wrote:
hello,
i have something like this:
*hpp :
namespace tag{ template<typename Id> struct sequence{ static ::boost::parameter::keyword< a_<Id> >& a; static ::boost::parameter::keyword< b_<Id> >& b;
static ::boost::parameter::keyword< arg_method_<Id> >& arg_method; }; }
namespace sequence_arg{ struct method{}; struct a:public method{}; struct b:public method{}; }
class sequence{ public: template<typename Id,typename ArgPack> sequence(const Id& id,const ArgPack&args){ fill_elements(id,args,args[tag::sequence<Id>::arg_method]); }
private: template<typename Id,typename ArgPack> void fill_elements( const Id& id, const ArgPack& args, sequence_arg::a method ); template<typename Id,typename ArgPack> void fill_elements( const Id& id, const ArgPack& args, sequence_arg::b method ); };
*.cpp :
sequence seq( id(), ( tag::sequence::a = a_value, tag::sequence::arg_method = sequence_arg::a() ) );
So far so good except there is redundancy of information about which method to use, so I'm looking for a way to be able to call say
sequence seq( id(), ( tag::sequence::a = a_value ) )
Any suggestion?
Use the macros -- they automatically generate the SFINAE you need so that the right overload will be chosen -- and add type requirements. See http://www.boost.org/doc/libs/1_36_0/libs/parameter/doc/html/index.html#sign... and http://www.boost.org/doc/libs/1_36_0/libs/parameter/doc/html/index.html#addi.... BOOST_PARAMETER_FUNCTION( (void), fill_elements, (tag), (required (id,*) (method, a)) (optional ... )) { ... } BOOST_PARAMETER_FUNCTION( (void), fill_elements, (tag), (required (id,*) (method, b)) (optional ... )) { ... } HTH, -- Dave Abrahams BoostPro Computing http://www.boostpro.com

David Abrahams wrote:
on Mon Sep 08 2008, e r <erwann.rogard-AT-gmail.com> wrote:
hello,
i have something like this:
*hpp :
namespace tag{ template<typename Id> struct sequence{ static ::boost::parameter::keyword< a_<Id> >& a; static ::boost::parameter::keyword< b_<Id> >& b;
static ::boost::parameter::keyword< arg_method_<Id> >& arg_method; }; }
namespace sequence_arg{ struct method{}; struct a:public method{}; struct b:public method{}; }
class sequence{ public: template<typename Id,typename ArgPack> sequence(const Id& id,const ArgPack&args){ fill_elements(id,args,args[tag::sequence<Id>::arg_method]); }
private: template<typename Id,typename ArgPack> void fill_elements( const Id& id, const ArgPack& args, sequence_arg::a method ); template<typename Id,typename ArgPack> void fill_elements( const Id& id, const ArgPack& args, sequence_arg::b method ); };
*.cpp :
sequence seq( id(), ( tag::sequence::a = a_value, tag::sequence::arg_method = sequence_arg::a() ) );
oops, I made a mistake, it should be sequence seq( id(),//id instance of Id ( tag::sequence<Id>::a = a_value, tag::sequence<Id>::arg_method = sequence_arg::a() ) ); The reason I use Id is for example to discriminate between different objects of the same type within a host object.
So far so good except there is redundancy of information about which method to use, so I'm looking for a way to be able to call say
sequence seq( id(), ( tag::sequence::a = a_value ) )
Any suggestion?
Use the macros -- they automatically generate the SFINAE you need so that the right overload will be chosen -- and add type requirements. See http://www.boost.org/doc/libs/1_36_0/libs/parameter/doc/html/index.html#sign... and http://www.boost.org/doc/libs/1_36_0/libs/parameter/doc/html/index.html#addi....
BOOST_PARAMETER_FUNCTION( (void), fill_elements, (tag), (required (id,*) (method, a)) (optional ... )) { ... }
BOOST_PARAMETER_FUNCTION( (void), fill_elements, (tag), (required (id,*) (method, b)) (optional ... )) { ... }
HTH,
Much appreciated, Thanks! I think I follow you, but to keep faithful to my example you probably meant: BOOST_PARAMETER_CONST_MEMBER_FUNCTION( (void), fill_elements, (tag), (required (id,*) (a, *)) (optional ... )) { // say x = sqrt(a) } BOOST_PARAMETER_CONST_MEMBER_FUNCTION( (void), fill_elements, (tag), (required (id,*) (b, *)) (optional ... )) { //say x = b^2 } Am I correct? I still have a problem, because as I corrected above, my tag is indexed by Id. I guess I should then have something like this? class sequence{ public: template<typename Id,typename ArgPack> sequence(const Id& id,const ArgPack&args){ fill_elements(id,args,find_method<Id,ArgPack>::type()); } ... }; where find_method<Id,ArgPack> looks for which of sequence<Id>::a and sequence<Id>::b is present in ArgPack, and returns type sequence_arg::a or sequence_arg::b accordingly. I've looked into arglist.hpp, which seems to be what ArgPacks are made of, but I'd need a little guidance in getting started to write an appropriate MPL algorithm. Thanks again!
participants (2)
-
David Abrahams
-
e r