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.

1087 questions
-2
votes
2 answers

Should an rvalue reference be used here?

I've been reading about rvalue references and std::move, and I have a performance question. For the following code: template void DoSomething() { T x = foo(); bar(std::move(x)); } Would it be better, from a performance perspective,…
George Hilliard
  • 15,402
  • 9
  • 58
  • 96
-3
votes
2 answers

problems with Move constructor and Move overloaded assignment operator?

Mostly all things explained by fredoverflow(user 237K Rep.) in his Two answers https://stackoverflow.com/a/3109981/11862989 https://stackoverflow.com/a/11540204/11862989 But while implementing Move constructor and overloaded Move Assignment…
Abhishek Mane
  • 619
  • 7
  • 20
-3
votes
1 answer

Why isn't the move constructor being called?

I am new to C++ and am trying to understand rvalue references and move semantics. I have written a simple class, Class, which includes a method, fun, which creates an instance of the class in its body and returns it. The class has a copy…
tossimmar
  • 129
  • 5
-3
votes
1 answer

Does the following code has undefined behavior due to r-value usage

According to the post r-value causes a warning without the use of std::move, I'm wondering if the following code has undefined behavior: struct Animal { virtual void foo() const { std::cout << "error" << std::endl; } }; struct Dog :…
abraham_hilbert
  • 2,221
  • 1
  • 13
  • 30
-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
  • 810
  • 1
  • 7
  • 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
  • 5,668
  • 10
  • 30
  • 46
-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
  • 391
  • 3
  • 8
1 2 3
72
73