Referring to std::forward
For all the overloads, the return type has been specified as T&& (ignoring constexpr).
But in the description attached to the following example:
template<class T>
void wrapper(T&& arg)
{
// arg is always lvalue
foo(std::forward<T>(arg)); // Forward as lvalue or as rvalue, depending on T
}
If a call to wrapper() passes an rvalue std::string, then T is deduced to std::string (not std::string&, const std::string&, or std::string&&), and std::forward ensures that an rvalue reference is passed to foo.
If a call to wrapper() passes a const lvalue std::string, then T is deduced to const std::string&, and std::forward ensures that a const lvalue reference is passed to foo.
If a call to wrapper() passes a non-const lvalue std::string, then T is deduced to std::string&, and std::forward ensures that a non-const lvalue reference is passed to foo.
In the two instances above after the first, an lvalue reference and not an rvalue reference (as implied by T&&, is this understanding correct?) has been documented as being passed to foo.
If the above understanding is correct, how come the return value has been specified as T&&?
T&&does not always mean a rvalue reference. I suggest to read Scott Meyers article "Universal References in C++11". - zett42