In the following scenario
template <class T, class U>
? f(T&& a, U&& 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, class U> decltype(auto) f(T&& a, U&& b) { return a > b ? forward<T>(a) : forward<U>(b); } -
Move construct the return value :
template <class T, class U> auto f(T&& a, U&& b) { return a > b ? forward<T>(a) : forward<U>(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 ?
Aucun commentaire:
Enregistrer un commentaire