J
Juha Nieminen
There's a special rule in the new standard with regard to rvalue references
when used with a template argument. Namely, if you have T&& (where T is
a template argument), it will be collapsed to T& if an lvalue is given
to it.
This means that if you have something like this:
template<typename T> void foo(T&&, T&&);
then two different functions will be instantiated depending on whether
you call it with rvalues or lvalues. In other words foo(1, 2) will
generate one function and foo(a, b) (where a and b are existing variables)
a different one.
What I do not understand is why calling foo(a, 1) or foo(1, b) doesn't
compile. It gives an error (at least with clang).
when used with a template argument. Namely, if you have T&& (where T is
a template argument), it will be collapsed to T& if an lvalue is given
to it.
This means that if you have something like this:
template<typename T> void foo(T&&, T&&);
then two different functions will be instantiated depending on whether
you call it with rvalues or lvalues. In other words foo(1, 2) will
generate one function and foo(a, b) (where a and b are existing variables)
a different one.
What I do not understand is why calling foo(a, 1) or foo(1, b) doesn't
compile. It gives an error (at least with clang).