Questions tagged [rvalue]

An rvalue is a temporary object (or subobject) or is a value not directly associated with an object.

Traditionally known as r-values since they generally appear on the right hand side of an expression; rvalues are temporary object whose lifetime does not extend past the current expression (unless bound to a an appropriate reference see ).

An rvalue is not directly associated with an object. Often a simple test is applied to determine if is an rvalue; "Is it named?"; if so, it is not an rvalue.

C++11 extended the original definition of an rvalue to include prvalues (pure rvalues) and xvalues (expiring values).

For a more general post on value categories, see this post on SO.

718 questions
0
votes
2 answers

Using wrapper objects as RValues with variadic template and reference parameters

I have a variadic template function template inline void ReadStream::decode(ARGS&...args) { internalDecode(args...); } template inline void ReadStream::internalDecode(T &head, ARGS&...args) { …
Andrew Goedhart
  • 937
  • 9
  • 17
0
votes
1 answer

Good practice with equalities for non-class enums (rvalues on left?)

I work in an environment that is slowly updating old c to c++. Frequently non-class enums are used within equality statements. Now I'm sure anyone who has taken a programming course or read a book which covers good practice knows that equalities…
mreff555
  • 1,049
  • 1
  • 11
  • 21
0
votes
1 answer

Are R & L-values relative to its context?

so assume we write the following in C++: a=b=5; which basically means a=(b=5); If we have a=5; I know that 5 is a literal and thus it is an R-Value. a is an L-Value. Same goes for b=5; I'm wondering now, what happens, if we write a=b=5; respectively…
xotix
  • 494
  • 1
  • 13
  • 41
0
votes
3 answers

rvalue references break when deep-returning

I've encountered a problem when passing returned rvalue references from a depth of more than 1. struct Data { std :: vector data; Data () { data .push_back (1); }; Data (Data && d) : data (std :: move (d .data)) {} }; Data && foo ()…
spraff
  • 32,570
  • 22
  • 121
  • 229
0
votes
3 answers

C++ function and rvalue confusion

with reference to the following code: // Example program #include #include using namespace std; struct S { S() { cout << "ctor\n"; } S(S&& rhs) { cout << "called move\n"; } }; S goo() { …
PYA
  • 8,096
  • 3
  • 21
  • 38
0
votes
0 answers

C++ rvalue references asssignment to lvalue reference

Let's assume having: template T&& f(T&& t) { return std::forward(t); } Presenter p; auto x = f(std::move(p)); // x is new Presenter object - move ctor invoked auto x = f(p); // x is new Presenter object - copy…
stanleysts
  • 41
  • 3
0
votes
0 answers

R-value passed to function by reference C++

I have a question about code below, exactly passing r-value arguments to function in C++. Why we can't pass r-value object Rect to function Print(Rect&), but r-value int we can. I know we can use Print(const int&) or Print(int&&). But the main…
0
votes
1 answer

forwarding reference with containers

It's possible that give std::vector e.g to function by forwarding reference? I know that template void f(const std::vector&&){} // is rvalue template void f(const std::vector&){} // is lvalue but how I can make…
21koizyd
  • 1,843
  • 12
  • 25
0
votes
1 answer

c++11 move constructor, initializing by unknown method using rvalue

I've made this TestClass to better illustrate the problem. As you can see the move constructor is called when the object is pushed into the vector and when the constructor is initialized using std::move function. But when we call TestClass…
0
votes
0 answers

Returning named rvalue reference

In the following code A f(A a) { return a; } the object a is returned via move constructor. And in this one A f(A&& a) { return a; } by copy constructor. Does the standard state that the move constructor cannot be used instead? More…
gl9100
  • 21
  • 3
0
votes
1 answer

Why does this use of assignment operator in a function argument fail?

Can someone point out why, in the following code, using variable p_char with the "return the rvalue" style when passing to write() SIGSEGVs? #include #include #include #include #include…
StoneThrow
  • 5,314
  • 4
  • 44
  • 86
0
votes
1 answer

Is it possible to call a function which takes a const rvalue as a parameter?

Recently i accidently programmed the following: void someFunction(const SomeClass&& value){ //Some Code } I didn't mean to add the 'const' keyword to the value parameter. However, this made me think: is it even possible to somehow call this…
Brotcrunsher
  • 1,964
  • 10
  • 32
0
votes
1 answer

Resolution of function arguments/parameters in C++

I am currently working my way through 'Effective Modern C++' to update my knowledge of the language, and have just finished item 27, which deals with overloading functions which take forwarding (or universal as the book calls them) references. Using…
PhilPotter1987
  • 1,306
  • 2
  • 12
  • 20
0
votes
1 answer

Why are constructed objects, in tuple initialization, copied?

I have a situation which I cannot wrap my head around. I define a non-copy-able struct and want to in-place construct it in a tuple. If I do so, it is copied. I thought the problem may be std::make_tuple, but it isn't. If instead I construct the…
scx
  • 3,221
  • 1
  • 19
  • 37
0
votes
1 answer

Passing a vector as a reference to a function

I'm trying to do the simply task of passing a vector to a function as a reference, and the modify the vector within the function. However, I get some pretty incomprehensible errors with the following example: // data.h class data { public: …
nov1943
  • 31
  • 4