How to use the "type" member template pattern for using result_of?

Take the following function: struct test_function { template<typename Vector, typename IntType> typename Vector::value_type operator()(const Vector& x, IntType bound_value) const{ return x[0] * x[0] + bound_value; } }; I wasn't sure exactly how the "type" member template pattern works so that result_of will work. I tried the following, but can't figure out how to extract the type of the arguments or convert to an MPL sequence? Is there some trick I am missing? struct test_function { template<typename Args> struct result { //HOW TO CONVERT TO MPL SEQUENCE OR ANOTHER APPROACH? typedef typename boost::mpl::at_c<Args, 0 >::type::value_type type; }; template<typename Vector, typename IntType> typename Vector::value_type //The type in the vector... can be a double or AD type operator()(const Vector& x, IntType bound_value) const{ return x[0] * x[0] + bound_value; } }; Thanks, Jesse

Jesse Perla wrote:
Take the following function: struct test_function { template<typename Vector, typename IntType> typename Vector::value_type operator()(const Vector& x, IntType bound_value) const{ return x[0] * x[0] + bound_value; } };
I wasn't sure exactly how the "type" member template pattern works so that result_of will work. I tried the following, but can't figure out how to extract the type of the arguments or convert to an MPL sequence? Is there some trick I am missing?
struct test_function {
template<typename Sig> struct result; template<typename This, typename Vector, typename IntType> struct result<This(Vector, IntType)> { typedef typename boost::remove_reference< Vector >::type::value_type type; };
template<typename Vector, typename IntType> typename Vector::value_type //The type in the vector... can be a double or AD type operator()(const Vector& x, IntType bound_value) const{ return x[0] * x[0] + bound_value; } };
HTH, -- Eric Niebler BoostPro Computing http://www.boostpro.com

AMDG Jesse Perla wrote:
Take the following function: struct test_function { template<typename Vector, typename IntType> typename Vector::value_type operator()(const Vector& x, IntType bound_value) const{ return x[0] * x[0] + bound_value; } };
I wasn't sure exactly how the "type" member template pattern works so that result_of will work. I tried the following, but can't figure out how to extract the type of the arguments or convert to an MPL sequence? Is there some trick I am missing?
struct test_function { template<typename Args> struct result { //HOW TO CONVERT TO MPL SEQUENCE OR ANOTHER APPROACH? typedef typename boost::mpl::at_c<Args, 0 >::type::value_type type; };
template<typename Vector, typename IntType> typename Vector::value_type //The type in the vector... can be a double or AD type operator()(const Vector& x, IntType bound_value) const{ return x[0] * x[0] + bound_value; } };
struct test_function { template<typename Sig> struct result; template<typename This, typename Arg1, typename Arg2> struct result<This(Arg1, Arg2)> { typedef typename boost::remove_reference<Arg1>::type::value_type type; }; }; In Christ, Steven Watanabe
participants (3)
-
Eric Niebler
-
Jesse Perla
-
Steven Watanabe