-3
template<typename T>
void foo(T&& a) 
{
    cout << is_rvalue_reference<T>::value << endl;
}

struct O
{
};

O o;
foo(o); //T is deduced to o&,a is O&
foo(std::move(o)); //T is deduced to O,a is O&&

Hi,all. Is there any way to make foo output 1(T is deduced to O&&)?

Leonhart Squall
  • 810
  • 1
  • 7
  • 15

1 Answers1

3

No. No type will ever be deduced as an rvalue reference type. A deduced type is either an lvalue reference type or a non-reference type.

The reference type out in the "universal reference" construction is T && (not T).

Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084