[mpl - function_types] Generate typedef from operator() of a functor

Hi all, Given an mpl sequence of types such as: typedef mpl::vector<T0, T1, T2, T3> arg_types; 1) the users of my library provide functors such as F (where T0 and T1 may have been any of the types of arg_types: class F { typedef mpl::pair<T0,T1> signature_type; double operator()(const T0& t0, T1& t1); }; is there a way to generate signature_type automatically ? 2) if the operator() is overloaded, the user class currently has to typedef an mpl::vector of mpl::pairs such as class G { typedef mpl::vector<mpl::pair<T2,T3>, mpl::pair<T1,T1>, mpl::pair<T3,T1> > signature_type; double operator()(const T2& t2, T3& t3); double operator()(const T1& t1, T1& t1); double operator()(const T3& t3, T1& t1); }; in this case, is it also possible to generate signature_type automatically ? Regrads, Olivier

Olivier Tournaire wrote:
Hi all,
Given an mpl sequence of types such as: typedef mpl::vector<T0, T1, T2, T3> arg_types;
1) the users of my library provide functors such as F (where T0 and T1 may have been any of the types of arg_types:
class F { typedef mpl::pair<T0,T1> signature_type; double operator()(const T0& t0, T1& t1); }; is there a way to generate signature_type automatically ?
Retrieve the operator() params usign aprameter_types, it'll end up as vector<F*,T0,T1> then use mpl::pop_front to remove the unwanted pointer to member
2) if the operator() is overloaded, the user class currently has to typedef an mpl::vector of mpl::pairs such as
class G { typedef mpl::vector<mpl::pair<T2,T3>, mpl::pair<T1,T1>, mpl::pair<T3,T1> > signature_type; double operator()(const T2& t2, T3& t3); double operator()(const T1& t1, T1& t1); double operator()(const T3& t3, T1& t1); };
Why don't you use something like the result_of protocol ? Maybe easier -- ___________________________________________ Joel Falcou - Assistant Professor PARALL Team - LRI - Universite Paris Sud XI Tel : (+33)1 69 15 66 35

Thanks again Joel. 2010/1/30 joel falcou <joel.falcou@lri.fr>
Olivier Tournaire wrote:
Hi all,
Given an mpl sequence of types such as: typedef mpl::vector<T0, T1, T2, T3> arg_types;
1) the users of my library provide functors such as F (where T0 and T1 may have been any of the types of arg_types:
class F { typedef mpl::pair<T0,T1> signature_type; double operator()(const T0& t0, T1& t1); }; is there a way to generate signature_type automatically ?
Retrieve the operator() params usign aprameter_types, it'll end up as
vector<F*,T0,T1>
then use mpl::pop_front to remove the unwanted pointer to member
2) if the operator() is overloaded, the user class currently has to
typedef an mpl::vector of mpl::pairs such as
class G { typedef mpl::vector<mpl::pair<T2,T3>, mpl::pair<T1,T1>, mpl::pair<T3,T1>
signature_type; double operator()(const T2& t2, T3& t3); double operator()(const T1& t1, T1& t1); double operator()(const T3& t3, T1& t1); };
Why don't you use something like the result_of protocol ?
Why not. Could you give us more details ? Regards
Maybe easier
-- ___________________________________________ Joel Falcou - Assistant Professor PARALL Team - LRI - Universite Paris Sud XI Tel : (+33)1 69 15 66 35
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Olivier Tournaire wrote:
2) if the operator() is overloaded, the user class currently has to typedef an mpl::vector of mpl::pairs such as
class G { typedef mpl::vector<mpl::pair<T2,T3>, mpl::pair<T1,T1>, mpl::pair<T3,T1> > signature_type; double operator()(const T2& t2, T3& t3); double operator()(const T1& t1, T1& t1); double operator()(const T3& t3, T1& t1); };
Why don't you use something like the result_of protocol ?
Why not. Could you give us more details ?
Details are at: http://www.boost.org/doc/libs/1_41_0/libs/fusion/doc/html/fusion/functional/... http://www.boost.org/doc/libs/1_41_0/libs/fusion/doc/html/fusion/functional/... http://www.boost.org/doc/libs/1_41_0/libs/utility/utility.htm#result_of basically, you're building a polymorphic function object, ie a functor with templated arguments/return type. What you can do is have one template operator() and use the result_of protocol to validate the call signature w/r to your T1,..,Tn. Then you can use tag-dispatchign to jump into the proper internal implementation class G { template<class Sig> struct result; template<class This> struct result<This(T2,T3)> { typedef double type; }; template<class This> struct result<This(T1,T1)> { typedef double type; }; template<class This> struct result<This(T3,T1)> { typedef double type; }; template<class A0,class A1> typename result<G(A0,A1)>::type operator()( A0 const& a0, A1 const& a1) { return eval(a0,a, mpl::pair<A0,A1>()); } template<class A0,class A1> typename result<G(A0,A1)>::type eval( A0 const& a0, A1 const& a1, mpl::pair<T2,T3> const&) { /* ... */ } template<class A0,class A1> typename result<G(A0,A1)>::type eval( A0 const& a0, A1 const& a1, mpl::pair<T1,T1> const&) { /* ... */ } template<class A0,class A1> typename result<G(A0,A1)>::type eval( A0 const& a0, A1 const& a1, mpl::pair<T3,T1> const&) { /* ... */ } }; or something like that. -- ___________________________________________ Joel Falcou - Assistant Professor PARALL Team - LRI - Universite Paris Sud XI Tel : (+33)1 69 15 66 35
participants (2)
-
joel falcou
-
Olivier Tournaire