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

What is faster to compute in C? (x==0) or (0==x)?

I wonder what is better to compute in C language: if (x==0) { // Some code ... } of if (0==x) { // Some code ... } I know the last is better in case the programmer forgets the second "=" and write "0 = x" instead "0 == x" because the…
-2
votes
2 answers

Converting between rvalue and lvalue

I am trying to understand and read that rvalues cannot be converted to lvalues. The following is fine int x = 1; // x is an lvalue int y = 2; // y is an lvalue int z = x + y; // the "+" needs rvalues, so x and y are converted to rvalues …
ontherocks
  • 1,747
  • 5
  • 26
  • 43
-2
votes
1 answer

Why does basic_string::assign not have a r-value overload?

According to this assign doesn't have a r-value overload. The kind of function signature I was expecting is: basic_string::assign(basic_string::basic_string &¶m); I checked the implementation for MSVC-2014 and CGI's implementation which do not…
bashrc
  • 4,725
  • 1
  • 22
  • 49
-2
votes
1 answer

Reference to Integer and String

Can somebody explain me why in VC++ 12 string &s = string("this"); works but not int &d = int(10); what operators are called while initializing a non const reference. Thanks.
-2
votes
2 answers

C++: Cannot initialize a variable of type 'guiBaseObject *' with an rvalue of type 'void'

I'm using openframeworks. This is based on C++. I have the following code: guiBaseObject *item = panel.addSlider("motor_speed", 0, 0, 100); And I am unable to understand why I receive the following…
user4791664
-3
votes
1 answer

Why is move assignment of unordered_map slow?

I am trying to understand how the move/rvalue assignment operator works. I know that it is largely implementation-specific, but assuming that move assignment in unordered_map works by only swapping the underlying data pointer or size attributes, I…
-3
votes
3 answers

Are glvalues really just prvalue with a memory address and can they be differentiated once bound to a reference?

There are countless explanations as to what the differences between glvalues and prvalues are, but they all pretty much boil down to "everything that has a memory address is a glvalue and everything else is a prvalue". I have read explanations like…
tempdev nova
  • 211
  • 1
  • 8
-3
votes
1 answer

If I apply decltype to an expresstion that yields an rvalue, do I always get a pointer? C++

I know that if I apply decltype to p, where p is an int*, decltype(*p) is int&. And decltype(&p) is int**. A reference being an rvalue, do I always get a pointer when applying decltype to an rvalue?
Jake Wright
  • 373
  • 1
  • 8
-3
votes
2 answers

Why do the C++ standard library operators accept rvalues?

When I run the following code: std::string myString = "I'm a string."; const std::string::iterator &myIterator = ++myString.begin(); char c = *myIterator; std::cout << c << std::endl; I get a segmentation fault (compiling with O3 optimization). I…
Jeremy B.
  • 81
  • 1
  • 7
-3
votes
3 answers

Why is this illegal initialization syntax?

template void func(T* arr, size_t length) { size_t size_half = length / 2; T* left = arr, right = arr + size_half; // Cannot initialize a variable of type 'int' with an rvalue of type 'int *' } It seems to me like the…
Francisco Aguilera
  • 3,099
  • 6
  • 31
  • 57
-4
votes
1 answer

If ++a return lvalue then why &(++a) show compile error?

I have heard that ++a returns l-value in c wheres a++ returns r-value in c. Since ++a return l-value then why &(++a) throws complilation error? Here's a link: Why is ++x a lvalue and x++ a rvalue? #include int main() { int a=1,*p; …
-4
votes
1 answer

Ambiguous/rvalue arguments cause compiler to choose incorrect overload

I have a home grown template class called Vec which is a pale shadow of: std::vector To avoid re-inventing the wheel the header overloads for assign are copied from: std::vector::assign ..so As part of testing Str class, ..test code is also…
tuk
  • 367
  • 1
  • 4
  • 10
-4
votes
1 answer

l value required as increment operand

Can somebody explain the compilation error in the program #include int main() { int i = 10; printf("%d", ++(-i)); return 0; }
1 2 3
47
48