Boost logo

Boost Users :

Subject: Re: [Boost-users] Iterate over template arguments
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2011-11-24 06:16:31


On 11/23/2011 04:33 PM, Allan Nielsen wrote:
>> It might be me which does not understand it, but as I read the
>> documentation funciton_types is for manipulating functions pointers,
>> not to manage template arguments...
>>
>> Please correct me if I'm wrong
> Okay, I got it...<int(int)> is one template argument...
> :
> typename boost::function_types::result_type<T0>::type is the return
> type, and I can use parameter_types and MPL to iterate over the
> parameters. Clever..
>
> But how do I implement the call interface:
>
> template<typename T>
> struct IfCall {
> typedef typename boost::function_types::result_type<T0>::type R;
>
> R call( /* T0, T1, T2...*/ ) { // can I get the MPL sequence into
> the method signature??
> }
> };

You need to use the preprocessor for this; in that case, you can also
get rid of Boost.FunctionTypes.

#include <boost/preprocessor/repetition/repeat.hpp>
#include <boost/preprocessor/repetition/enum_params.hpp>
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
#include <boost/preprocessor/punctuation/comma_if.hpp>

#define IFCALL_MAX_ARITY 5

template<class Sig>
struct IfCall;

#define M0(z, n, t) \
template<class R BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, class A)>\
struct IfCall<R(BOOST_PP_ENUM_PARAMS(n, A))> \
{ \
     R call(BOOST_PP_ENUM_BINARY_PARAMS(n, A, const& a)) \
     { \
         return R(); \
     } \
}; \
/**/

BOOST_PP_REPEAT(BOOST_PP_INC(IFCALL_MAX_ARITY), M0, ~)
#undef M0


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