I want to perfect-forward a call to a function, but I always want to return a const version of the returned type. I mean, when returning a reference, I want a const& instead. How can I achieve that?
- I don't care about non-reference types. After all, returning a const T (without a reference) is not much different than
T. - I care only about a
constat the top level. IfTis a pointer type, or some other more complex type, I do not want to add constness somewhere deeper.
If I just forward the call normally:
template<class Func, class... Args>
decltype(auto) Example(Func f, Args&&... args)
{
return fun(std::forward<Args>(args)...);
}
and f happens to return, say, int& then I just get just that: int&. But I would like to get a const int& instead.
decltype(auto) const, or decltype(auto const) seem to be illegal.