In the following scenario
template <class T>
? f(T&& a, T&& b)
{
return a > b ? a : b;
}
what would the optimum return type be ? My thoughts so far are :
Return by r value refs, perfectly forwarding the function arguments :
template <class T> decltype(auto) f(T&& a, T&& b) { return a > b ? forward<T>(a) : forward<T>(b); }Move construct the return value :
template <class T> auto f(T&& a, T&& b) { return a > b ? forward<T>(a) : forward<T>(b); }Try fo find a way to enable (N)RVOs (even though I think since I want to use the function arguments that's impossible)
Is there a problem with these solutions ? Is there a better one ? What's the best practice ?