Questions tagged [rvalue-reference]

An rvalue reference is a new language feature in C++11 representing a reference to an rvalue. Together with reference collapsing, they are used to implement and enable move semantics and perfect forwarding.

An rvalue reference is a language feature added in C++11 (formerly known as C++0x). It is used to bind to an rvalue thus extending the temporary object's lifetime.

Together with reference collapsing, they are used to implement and enable move semantics and perfect forwarding.

979 questions
-3
votes
1 answer

about type deduction when perfect-forwarding

template void foo(T&& a) { cout << is_rvalue_reference::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…
Leonhart Squall
  • 770
  • 1
  • 5
  • 15
-4
votes
1 answer

R-value Reference push_back Function

I'm writing a Queue class. I have two versions of push_back for the new C++11 standard. One of these versions uses a rvalue reference as a parameter. My version works, but I think it must be lacking something: 97 template 98 void…
Victor Brunell
  • 3,780
  • 8
  • 26
  • 39
-5
votes
1 answer

c++11 about rvalue reference

#include using namespace std; int&& move(int&& t) { return static_cast(t); } int main() { move(5) = 10;//why error? return 0; } Error prog.cpp:9:13: error: using xvalue (rvalue reference) as lvalue Here's the…
user2178911
  • 381
  • 3
  • 7
-10
votes
1 answer

Initialization of a constant reference with a number

What is the meaning of the following line? Why is this allowed as 0 is an r-value and not a variable name? What is the significance of const in this statement? const int &x = 0;
user3112666
  • 105
  • 1
  • 6
1 2 3
65
66