I am trying to determine the return type of a various C++ member functions. I understand that decltype and std::declval can be used to do this, but I am having problems with the
You may also use std::result_of
and decltype
, if you prefer to list arguments types rather than the corresponding dummy values, like this:
#include
#include
#include
struct foo {
int memfun1(int a) const { return a; }
double memfun2(double b) const { return b; }
};
int main() {
std::result_of::type i = 10;
std::cout << i << std::endl;
std::result_of::type d = 12.9;
std::cout << d << std::endl;
}
DEMO here.