Lorah Attkins Lorah Attkins - 12 days ago 7
C++ Question

Is this a forwarding reference?

The distinction between rvalue references and forwarding references was made clear enough in this example by Scott Meyers:

Widget&& var1 = someWidget; // here, “&&” means rvalue reference (1)

auto&& var2 = var1; // here, “&&” does not mean rvalue reference (2)

template<typename T>
void f(std::vector<T>&& param); // here, “&&” means rvalue reference (3)

template<typename T>
void f(T&& param); // here, “&&”does not mean rvalue reference (4)


Essentially the distinction happens when we have a deducible context, hence case (3) explicitly states that we have a
vector<...>&&
whereas the
T
in case (4) is to be deduced and (after applying reference collapsing rules) categorized in terms of "value category".

But what happens with a bit more complex pattern matching? Take the following case for example :

template <template <class...> class Tuple, class... Ts>
void f(Tuple<Ts...>&& arg)
{

}


What does
&&
mean here ?

Answer

In your last example, arg is an rvalue reference.

A forwarding reference is an rvalue reference to a cv-unqualified template parameter

and Tuple<Ts...> is not a template parameter.

(Citation from [temp.deduct.call].)