3

I had a browse through the question on std::result_of on SO, but couldn't find an answer to this question.

How do I deduce the return type of a non-static method using std::return_type without using decltype?

#include <utility>                                                                 
#include <memory>                                                                                                                                   
struct A                                                                           
{                                                                                  
    int a;                                                                         

    int fun() { return 0;}                                                         
};                                                                                 

int main()                                                                         
{                                                                                  
    std::result_of<A::fun(A)>::type x; // error, argument 1 is invalid           
    std::result_of<A::fun()>::type x; // error, cannot call member function A::fun() without object             
    return 0;                                                                      
}

I know I can use a combination of declval and decltype to get the same effect but I was wondering if I could achieve this using result_of directly?

quant
  • 21,507
  • 32
  • 115
  • 211

0 Answers0