
So far BOOST proposes various prtocols for meta-function : - the result_of protocol - the apply<> protocol of MPL - the ::type protocol of traits Can those protocols be mixed somehow without any side-effects when used with the various aforementionned protocol ? -- ___________________________________________ Joel Falcou - Assistant Professor PARALL Team - LRI - Universite Paris Sud XI Tel : (+33)1 69 15 66 35

AMDG Joel Falcou wrote:
So far BOOST proposes various prtocols for meta-function :
- the result_of protocol - the apply<> protocol of MPL - the ::type protocol of traits
Can those protocols be mixed somehow without any side-effects when used with the various aforementionned protocol ?
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: struct identity { template<class T> struct apply { typedef T type; }; }; typedef mpl::apply<identity, int>::type int_; boost::mpl::apply is generally preferable, because it works with MPL Lambda expressions as well as metafunction classes. In Christ, Steven Watanabe

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 pretty much answered the question. Thanks. -- ___________________________________________ Joel Falcou - Assistant Professor PARALL Team - LRI - Universite Paris Sud XI Tel : (+33)1 69 15 66 35

on Thu Jan 15 2009, Joel Falcou <joel.falcou-AT-u-psud.fr> 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 http://spirit.sourceforge.net/dl_docs/phoenix-2/libs/spirit/phoenix/doc/html... both of which have to manage the same issue. -- Dave Abrahams BoostPro Computing http://www.boostpro.com

Additional question : Is result_of beign able to be called recursively like : boost::result_of<foo(int,bar(float))>::type If not, why and how can it be fixed ?

AMDG Joel Falcou wrote:
Is result_of beign able to be called recursively like :
boost::result_of<foo(int,bar(float))>::type
No. boost::result_of<foo(int, boost::result_of<bar(float)>::type)>::type will work though.
If not, why and how can it be fixed ?
In Christ, Steven Watanabe
participants (3)
-
David Abrahams
-
Joel Falcou
-
Steven Watanabe