So __FUNCTION__ tells us the name of the current function. Is there a similar macro for return type of the function?
Since you already use a Visual-C++ specific __FUNCTION__ macro you could look into __FUNCSIG__ macro - it expands into the full signature which you could then parse and extract the return type. There's no macro that would do that on itself in Visual C++.
If you don't need it at preprocessing time:
In C++0x, you can do use decltype(myFunc(dummyparams)), which stands for the return type of myFunc (compile-time).
If you now want a string out of that, enable RTTI (run-time type information) and use typeid().name() (run-time):
#include <typeinfo>
double myFunc(){
// ...
return 13.37;
}
int main(){
typedef decltype(myFunc()) myFunc_ret;
char const* myFunc_ret_str = typeid(myFunc_ret).name();
}
Note, however, that the myFunc_ret_str isn't always a clean name of the return type - it depends on how your compiler implements typeid.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With