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
I've tried various declarations such as decltype(std::declval(TestCBClass::testStaticMethod))
You don't have to use std::declval
and pass actual arguments, not even their types, just to know what is the return type of a static/non-static member function. Instead, you can write your own trait to know what is the return type of a given function:
template
struct return_type;
template
struct return_type { using type = R; };
template
struct return_type { using type = R; };
template
struct return_type { using type = R; };
template
struct return_type { using type = R; };
template
struct return_type { using type = R; };
template
using return_type_t = typename return_type::type;
...
TestCBClass t;
std::future> a =
std::async(&TestCBClass::testCBArgRet, t, 1);
std::future> b =
std::async(&TestCBClass::testCBEmpty, t);
std::future> c =
std::async(&TestCBClass::testCBEmptyStatic);
DEMO