How to deduce (possibly void) return type of member function?

If I have a class...
struct X {
int f(double x);
void f(int y);
};
... and a template Y that wants to deduce the return-type of some member
functions of T...
template<class T>
struct Y {
typedef typename what_goes_here<T>::type f_double_return_type;
typedef typename what_goes here<T>::type f_int_return_type;
};
I"ve tried using...
typedef BOOST_TYPEOF_TPL(static_cast

Hi Terry, Terry Golubiewski schrieb:
If I have a class...
struct X { int f(double x); void f(int y); };
.... and a template Y that wants to deduce the return-type of some member functions of T...
template<class T> struct Y { typedef typename what_goes_here<T>::type f_double_return_type; typedef typename what_goes here<T>::type f_int_return_type; };
you should use boost::result_of to do such of things.
See
http://www.boost.org/doc/libs/1_43_0/libs/utility/utility.htm#result_of .
Here a description.
The class template |result_of| helps determine the type of a call
expression. Given an lvalue |f| of type |F| and lvalues |t1|, |t2|, ...,
|t/N/| of types |T1|, |T2|, ..., |T/N/|, respectively, the type
|result_of
I"ve tried using...
typedef BOOST_TYPEOF_TPL(static_cast
(0)->f(double(0))) f_double_type; // this works .... but ...
typedef BOOST_TYPEOF_TPL(static_cast
(0)->f(int(0)) f_int_type; // does not work for "void" Of course, I wouldn't know which one returns "void" or not ahead of time.
terry
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

How? I read the docs you referenced (previously), but I did not see a
concrete example.
typedef typename boost::result_of< ...what goes here???... (double)>::type
f_double_return_type;
terry
----- Original Message -----
From: "Kim Kuen Tang"
Hi Terry,
Terry Golubiewski schrieb:
If I have a class...
struct X { int f(double x); void f(int y); };
.... and a template Y that wants to deduce the return-type of some member functions of T...
template<class T> struct Y { typedef typename what_goes_here<T>::type f_double_return_type; typedef typename what_goes here<T>::type f_int_return_type; };
you should use boost::result_of to do such of things.

Terry Golubiewski schrieb:
How? I read the docs you referenced (previously), but I did not see a concrete example.
i thought it was straightforward, but looking into details it was not the right reference. =-O However, below is a solution which relies on BOOST_TYPEOF. BOOST_TYPEOF will have a problem if the return_type is void. So i replace it with mpl::void_.
typedef typename boost::result_of< ...what goes here???... (double)>::type f_double_return_type;
terry
HTH
Kim
# include
::type deduce_type(return_type (X::*)(Param));
typedef BOOST_TYPEOF(deduce_type<char>(&X::f)) void_;
typedef BOOST_TYPEOF(deduce_type<int>(&X::f)) int_;
typedef BOOST_TYPEOF(deduce_type<double>(&X::f)) double_;
int main() {
BOOST_MPL_ASSERT((boost::is_same

Mr. Kim Kuen Tang,
You are awesome! You approach worked! Thank you! However....
I want to detect the function return type of a user-supplied message
handler.
This non-generic version compiles and runs as expected.
#include

Hi Terry, Terry Golubiewski schrieb:
But this generic version doesn't compile...
what you want is a "lazy" version of BOOST_TYPEOF.
By wrapping your expression into BOOST_TYPEOF_NESTED_TYPEDEF you will
delay the calculation until you really need it.
The code below compile and work as expected.
HTH
Kim
# include
participants (2)
-
Kim Kuen Tang
-
Terry Golubiewski