Return forwarding reference parameters - Best practice

Viewed 1157

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 :

  1. 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); 
    }
    
  2. Move construct the return value :

    template <class T>
    auto f(T&& a, T&& b)
    {
        return a > b ? forward<T>(a) : forward<T>(b); 
    }
    
  3. 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 ?

2 Answers
Related