Given a very simple, but lengthy function, such as:
int foo(int a, int b, int c, int d) {
return 1;
}
// using ReturnTypeOfFoo = ???
W
I don't know if is the simplest way (if you can use C++17 surely isn't: see NathanOliver's answer) but... what about declaring a function as follows:
template
R getRetType (R(*)(Args...));
and using decltype()
?
using ReturnTypeOfFoo = decltype( getRetType(&foo) );
Observe that getRetType()
is only declared and not defined because is called only a decltype()
, so only the returned type is relevant.