I don't want to declare the return value two times, so maybe there is a more clever way in modern C++ to do this, but I couldn't find any way.
So, instead of this:
int calculate() {
int ret=0;
return ret;
}
I want to do something like this:
int calculate() {
decltype(return_type) ret=0;
return ret;
}
It would make it easier to change the return type if needed.
If it's not possible, then why is it not possible?
auto calculate()
?decltype(auto) calculate()
decltype(calculate()) ret = 0;
?decltype(auto)
should be fine there, no?decltype(auto)
is dangerous if you don't want the function to be forwarding references, e.g.return(ret);
does cause the issue I referred to.