Boost logo

Boost Users :

Subject: Re: [Boost-users] Iterate over template arguments
From: Jeffrey Lee Hellrung, Jr. (jeffrey.hellrung_at_[hidden])
Date: 2011-11-23 15:08:22


On Wed, Nov 23, 2011 at 7:33 AM, Allan Nielsen <a_at_[hidden]> 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??
> }
> };

Ugh. Well, what I can think of at the moment:
- Use the Boost.Preprocessor library to specialize each arity of lfCall,
e.g., generate
template< class R, class T0 >
struct lfCall< R ( T0 ) > { /*...*/ R call(T0) { /*...*/ } };
and similarly for all other supported arities with the preprocessor; or
- If you're flexible in the call interface, you might be able to utilize
Boost.Fusion's fuse/unfuse adaptors [1].

- Jeff

http://www.boost.org/doc/libs/1_48_0/libs/fusion/doc/html/fusion/functional/adapters.html



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