Quick question

In this code

template <typename T>
foo(T&& t);

If I pass a lvalue, because its pass by reference the compiler creates a lvalue reference to my lvalue object and then T resolves to T&.

Then this line

foo(T&& t);

becomes T&& & which anyways becomes a lvalue reference. Is this correct?
Please answer anyone!
full code
T&& where T is a template parameter is what Meyers calls "universal reference" because of the special rules for template argument deduction.
foo(lvalue) will call foo<T&>(T&)
foo(rvalue) will call foo<T>(T&&)
(this is one half what makes perfect forwarding work, the other half is std::forward)
Last edited on
Ok thanks :D
Topic archived. No new replies allowed.