Boost logo

Boost :

Subject: Re: [boost] Mixing protocol
From: David Abrahams (dave_at_[hidden])
Date: 2009-01-16 21:40:50

on Thu Jan 15 2009, Joel Falcou <> wrote:

> Steven Watanabe a écrit :
>> What do you mean by mixed?
>> result_of looks for a nested result or result_type only. It is
>> unaffected by apply/type.
>> MPL uses both apply and type and also has a metafunction called apply:
> What I anted is having polymorph object function that also acts as a apply-based MPL
> metafunction
> to avoid code duplication for the meta-programmed parts.

You could use

    template <class F>
    struct result_of_adapter
         template <class A0 = mpl::void_, class A1 = mpl::void_, class A2 = mpl::void_>
         struct apply
           : boost::result_of<F(A0,A1,A2)> {};

         template <class A0, class A1>
         struct apply<A0,A1,mpl::void_>
           : boost::result_of<F(A0,A1)> {};

         template <class A0>
         struct apply<A0,mpl::void_,mpl::void_>
           : boost::result_of<F(A0)> {};

         template <>
         struct apply<mpl::void_,mpl::void_,mpl::void_>
           : boost::result_of<F()> {};

When you want to use a polymorphic function type F with mpl::apply, you can
wrap it in result_of_adapter:

     mpl::apply<result_of_adapter<F>, argt0, argt1>::type

You might also want to look at Boost.Fusion and
both of which have to manage the same issue.

Dave Abrahams
BoostPro Computing

Boost list run by bdawes at, gregod at, cpdaniel at, john at