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
0 answers

Passing rvalue as const& reference

Assume there is QRegExp regex (wildcard) and QDirIterator dit. If they are identical, .i.e. they should match. Why does this QString s = dirIterator.fileName(); if(ignore.exactMatch(s)) continue; match and the following…
ManuelSchneid3r
  • 15,850
  • 12
  • 65
  • 103
0
votes
2 answers

C++ lvalues, rvalues, references, parameters, and performance

So I have a function that needs to take an std::vector as a parameter. I'd like to know the best way to declare the parameter so that the underlying array is not deep-copied, as it could be rather large. // which should I choose? void…
dwoodwardgb
  • 180
  • 4
  • 10
0
votes
0 answers

confusion about a function returning int&&

I wrote some test code. int getInt() { int a = 3; return a; } int& getIntR() { int a = 3; return a; } int getRL() { return int(1); } int&& getRRL() { return getRL(); } int main() { // works, even though there may cause some…
Azure
  • 1
  • 2
0
votes
1 answer

How do you inspect an rvalue (temporary object) in lldb?

When you set a breakpoint, e.g. b main in lldb, it's pretty easy to see the variables in that current frame: (lldb) frame variables But how do you inspect temporary objects? Say I have these functions std::string func2() {...} void func(const…
jar
  • 381
  • 3
  • 15
0
votes
0 answers

Check if expression is xvalue or prvalue

I just want to verify some rules described at cppreference. It is easy to check, whether expression is lvalue or rvalue. #include #include template bool IsLValue(const char* i_expression, T&, bool i_expected =…
Vladislav
  • 394
  • 1
  • 14
0
votes
3 answers

c++ translate from dynamic allocation to references

I have following code: class A{ public: virtual do_something() = 0; } class B : public A{ public: virtual do_something() override; } void use_a(A *a){ if (a){ a->do_something(); delete a; } } use_a( new B() ); How this…
Nick
  • 9,962
  • 4
  • 42
  • 80
0
votes
6 answers

What is the difference between `*a =` and `= *a`?

In following function, void swap(int * a, int * b) { int t; t = *a; // = *a *a = *b; // a* = *b = t; } What is the difference between = *a and *a =? I've heard that the * operator in = *a is a de-referencing(or in-directing)…
Jin Kwon
  • 20,295
  • 14
  • 115
  • 184
0
votes
2 answers

function returns pointer to array

i wrote this c++ code to make a function returns a pointer to an array of double, in such way i use it as rvalue. i got a weird error message because i couldn't understand what's wrong with it. here is the code with the error message #include…
Issak Sdu
  • 29
  • 2
  • 7
0
votes
1 answer

Is there exception to rule that if address can be find out using & it's lvalue?

Is there any exception to rule that if I can find address using & it's l-value otherwise r-value? For example, int i; &i will give address of i, but I cannot take address of (i + 5), unless I is pointer or array. Regards
Pranit Kothari
  • 9,721
  • 10
  • 61
  • 137
0
votes
1 answer

rvalue reference to a function type

As known, the function call which return type is an rvlaue to a function is an lvalue. A function call is an lvalue if the result type is an lvalue reference type or an rvalue reference to function type, an xvalue if the result type is an…
St.Antario
  • 26,175
  • 41
  • 130
  • 318
0
votes
1 answer

Assignment to an array subsection: am I assigning to an Rvalue here, and if so how do I fix it?

In the hope of making my Fortran code easier to port over to C++ one day, I've been working on some expression template code to provide whole-array arithmetic operators and the ability to copy from and assign to specified sections of longer arrays.…
Eos Pengwern
  • 1,467
  • 3
  • 20
  • 37
0
votes
1 answer

Is There a Pointer Version of ref that Supports Rvalues?

This is really two questions about ref rolled into one: Can I use ref on an rvalue? Obviously as the programmer I would have the responsibility to ensure it outlived any calling code. Is there a pointer version of ref? The goal of these two…
Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288
0
votes
1 answer

What is the difference between Visual Studio and g++ with reference?

class A { ... } A foo() { A fooA; return fooA; } int main() { A &a = foo(); return 0; } Here is the simple code. I test this in VS2013. there are no error or warning. I think foo() function return temporary of "fooA". That is…
seung hwan Son
  • 183
  • 1
  • 7
0
votes
1 answer

C++ - how to return a prvalue by reference?

So I'm implementing a native arrays wrapper which will allow such to be passed as function arguments and to be returned. I'm having a trouble however with casting it to a native array as native arrays can't be returned. As an replacement I decided…
AnArrayOfFunctions
  • 3,452
  • 2
  • 29
  • 66
0
votes
1 answer

Non lvalue in assignment error

I got this error when I used names to print the strings, but no errors when tempNames is used. char* names[] = { "JIM", "RAM", "SAM", 0 }; int main(int argc, char *argv[]) { char**…
Raju
  • 1,149
  • 1
  • 6
  • 19