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
1 answer

Templates Non Type Parameters+ Lvalue/Rvalue

C++03 $14.1/6 - "A non-type non-reference template-parameter is not an lvalue." C++0x $14.2/6- "A non-type non-reference template-parameter is an rvalue." Is there any specific rationale behind rewording it?
Chubsdad
  • 24,777
  • 4
  • 73
  • 129
0
votes
2 answers

Is this true that variables whose address can be taken are lvalues?

Recently while reading blog on universal reference by scott meyers i came along statement that "if you can take the address of an expression, the expression is an lvalue." but is this really true Suppose i have following code class Test { }; int…
PapaDiHatti
  • 1,841
  • 19
  • 26
0
votes
3 answers

Does const reference prolong the life of a temporary object returned by a temporary object?

I know that const reference prolongs the life of a temporary locally. Now I am asking myself if this propriety can be extended on a chain of temporary objects, that is, if I can safely define: std::string const& foo =…
Alex Gidan
  • 2,619
  • 17
  • 29
0
votes
0 answers

Difference of const and non-const Reference C++

const int& dummy = 5; The code snippet above compiles without any errors / warnings using the g++ Compiler. Conversely using the code snippet int& dummy = 5; produces the following error code: invalid initialization of non-const reference of…
clickMe
  • 993
  • 11
  • 33
0
votes
0 answers

Can I use rvalue to store the intermediate results

I found it slow when calculate expression of array. So I wonder about can I use rvalue to store the intermediate results for reducing alloc action? #include "SArray.hpp" template SArray&& operator* (SArray&& s, const T& scale) { …
Luster
  • 171
  • 1
  • 1
  • 5
0
votes
0 answers

Can anyone give examples of when rvalue references in C++ prove very beneficial?

This feature seems to be interesting and useful, but I would like to know its use case in practical applications. Like the difference it created, before adding this feature and once it got introduced.
Mrunal SP
  • 7
  • 3
0
votes
3 answers

How is the move constructor of member variable invoked without using std::forward?

An example here for std::forward, // forward example #include // std::forward #include // std::cout // function with lvalue and rvalue reference overloads: void overloaded (const int& x) {std::cout << "[lvalue]";} void…
user557583
  • 33
  • 5
0
votes
1 answer

Trying to pass adress to a reffernce to a pointer

Why calling funk(&a) gives a compile error func(int * & data) {data++;} int main(){ int a = 5; int *p = &a; func(&a); //this gives a compile error funk(p); //this works fine } error: invalid initialization of non-const reference of type ‘int*&’…
klido
  • 3
  • 3
0
votes
3 answers

Why int *const p1; results in error while int *p1;works just fine?

I'm new to C++ and is trying to learn the concept of pointer. I'm confused as to why the third and fourth statements results in errors while the first and second works just fine. int *p1; //Ok const int *p1;//Ok int *const p1; //error: default…
Thor
  • 9,638
  • 15
  • 62
  • 137
0
votes
1 answer

return a pointer to a member of an object that is created on the heap

So if I have a class class Item { public: Item(int key, int value):key(key), value(value) {} int GetValue() { return value; } private: int key; int value; } If I create an Item object on the heap: Item *item = new Item(1, 2); Is it…
ZigZagZebra
  • 1,349
  • 3
  • 14
  • 25
0
votes
5 answers

Why need to set rvalue reference to null in move constructor?

I've read the post: Why do we need to set rvalue reference to null in move constructor? It said that during a move, you just copied the pointer from one object to another, so two pointers points to the temporary object. And when the temporary object…
sydridgm
  • 1,012
  • 4
  • 16
  • 30
0
votes
1 answer

Access the rvalue address using an operator?

How can I use an expression or an operator to get the address of a rvalue ? char buffer[100]; time_t rawtime=time(nullptr); //rawtime used only once ,after that it's abandoned. strftime(buffer, 80, "%y%m%d %H%M%S", localtime(&rawtime));// rewrite…
iouvxz
  • 89
  • 9
  • 27
0
votes
2 answers

Why is returned object an rvalue?

class A {} A foo() { A a; // some work return a; } Here it returns an instance of A, and I saw many readings saying that this returns a rvalue. My confusion is, since it's perfectly legit to do A b; a = b;, the variable a seems to be an…
OneZero
  • 11,556
  • 15
  • 55
  • 92
0
votes
1 answer

How do I use the `Function Call Operator` to load `rvalue` types to my object?

I have a class like this: template class MyClass { public: // ... T && operator()(uint64_t i, uint64_t j); // I want to add a member function like this. T & operator()(uint64_t i, uint64_t j); …
hkBattousai
  • 10,583
  • 18
  • 76
  • 124
0
votes
1 answer

Taking reference of rvalue

according to the open standard (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2027.html) This code should give an error: A& a_ref3 = A(); // Error! A&& a_ref4 = A(); // Ok However, I am able to do the first line just fine. And the…