C++ forwarding reference and r-value reference

It’s a great question which foxes almost everyone in the beginning.

template <class T>
class A
{
    template <class U>
    void foo(T&& t, U&& u);
};

In this example, T is not deduced (you explicitly define it when you instanciate the template).

U is deduced because it’s deduced from the argument u.

Therefore, in almost all cases it would be:

std::move(t);
std::forward<U>(u);

Leave a Comment