tags:

views:

95

answers:

2

hi

How can I go about determining return type of a member generic function?

    template<class E>
    struct result<E> {
        // E has member function data(), I need to know its return type
        typedef typename &E::data type;
    };

is it possible to do it in generic way? I know there is boost:: result_of but for my purposes it lacks specializations (if I understood correctly, return type must be specialized). boost implementation would be great.

+3  A: 

GCC's nonstandard typeof operator can do this, as can Boost.TypeOf.

Josh Kelley
that seems to work, provided there are no overloaded functions.Do you know how to deal with case where there is 2 functions (one has const qualifier)
aaa
You would need to typecast the function to the const or non const type before using it. You get the same problem with boost::bind.
bradgonesurfing
@brad thank you. Dont I need to know return type before type cast?can you give an example?
aaa
The problem is described with boost::bind here and how to handle it.http://www.boost.org/doc/libs/1_43_0/libs/bind/bind.html#err_overloade
bradgonesurfing
+3  A: 

If you're using VS2010 or GCC 4.3 at least you can use C++0x new keyword decltype .

Klaim