Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ template determine function return type

Tags:

c++

templates

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.

like image 899
Anycorn Avatar asked Jul 08 '10 17:07

Anycorn


2 Answers

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

like image 137
Josh Kelley Avatar answered Oct 07 '22 04:10

Josh Kelley


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

like image 39
Klaim Avatar answered Oct 07 '22 04:10

Klaim