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

lvalue reference on rvalue reference

I have an interesting example to understand lvalue reference, rvalue reference, and std::forward. Maybe it will be a useful example for a deep understating concept. void foo(int&& a){ cout<<"foo&&"<
-1
votes
1 answer

cpp l-value vs r-value code| error: expected ',' or '...' before '&&' token, error: 'name' was not declared in this scope

I am a newbie with this topic in cpp and trying to usnderstand through this code, so please tell me how l-values and r-values make difference in this code and how they are implemented. Also why am i getting error here (do execution of this code…
Harsh Raj
  • 3
  • 2
-1
votes
1 answer

How to have both rvalue input (with operator =) and normal arguments in a method?

I kinda trying to make a class method here that is able to assign a rvalue with "operator =" to an array, which requires also the input of the indexes. For now the code looks like this: #include using namespace std; class Matrix { …
Átila
  • 1
-1
votes
1 answer

Pass R-Value array in C

If we consider the function int sum(int* nums, size_t len) { int sum = 0; for(int i = 0; i < len; i++) sum += nums[i]; return sum; } We could call it using an lvalue as such int[] nums = {1,2,3}; sum(nums, 3); But when trying to use an…
mdre
  • 81
  • 7
-1
votes
2 answers

Ensure returned pointer is const, without throwing warnings

My goal is to define a clean API for my library. One of my function returns a pointer that shall not be modified with pointers arithmetic. To do so at compile-time, I was planning on using the const keyword in the function prototype. Here's a naive…
gberth
  • 467
  • 5
  • 13
-1
votes
2 answers

What does & return a lvalue or a rvalue?

As per textbook . The address-of operator (§ 2.3.2, p. 52) requires an lvalue operand and returns a pointer to its operand as an rvalue. int a = 6,c=9; int *x = &a; //Here x is a lvalue. x = &c; As per my knowledge if we can assign , it is…
Nikhil Badyal
  • 1,589
  • 1
  • 9
  • 20
-1
votes
1 answer

Why are true, false and nullptr prvalues?

As far as I'm aware nullptr is an instance of some class, something like this: const class { public: template // convertible to any type operator T*() const // of null non-member { return 0; } // pointer... template
Alexey
  • 710
  • 3
  • 7
  • 19
-1
votes
2 answers

Overloading for rvalue?

Below is a code demonstrating the question: class X {}; X x; X&& rvalue_ref = std::move(x); static_assert(std::is_same::value, "Different types"); //To be sure that type is X&& void func(X&) { cout << "lvalue…
-1
votes
2 answers

error: invalid initialization of non-const reference of type 'std::function&' from an rvalue of type 'main()::'|

EDIT: Sorry, I asked this question without a thro understanding of references... I seem to be getting this error when I run this code... error: invalid initialization of non-const reference of type 'std::function&' from an rvalue of type…
Samuel
  • 315
  • 3
  • 14
-1
votes
2 answers

Why doesnt istream support rvalue extraction

I have a class that wraps around std::string to provide formatting: struct Wrap { std::string& s; // need const ref for output, non const for input friend std::ostream& operator<< (std::ostream& os, const Wrap& w) { os << "[" << w.s <<…
BitWhistler
  • 1,439
  • 8
  • 12
-1
votes
1 answer

how can I bind a class member function with param as rvalue to boost::function?

I try to bind a class member function with param as rval to boost::function. But it doesn't work. my sample false code : class Class1 { int Foo1(int&& b) { return b; } void foo2() { boost::function
庄嘉琪
  • 21
  • 2
-1
votes
2 answers

Return the kind of an expression in C, i.e., whether it's an rvalue or lvalue

Can I print how an expression is being evaluated? For example if I wanted to find out whether a value was being evaluated as an rvalue or lvalue I'd call the hypothetical code: int main() { if(isrvalue(*(int *)4)) return 0; else return…
J. Doe
  • 85
  • 7
-1
votes
1 answer

rvalue reference to temporary declaration

E && e0 = E () ; E e1 ; is there any differences between these two cases of object declaration.? ;
Volodymyr Boiko
  • 1,533
  • 15
  • 29
-1
votes
1 answer

R-value overloaded Operator string assignment error

I am having some trouble figuring out why i get Unhandled exception at 0x003DBD00 in Project10.exe: 0xC0000005: Access violation reading location 0xCDCDCDE5. It seems to pop up at a string assignment operator similar to this: std::string x =…
ILP911
  • 13
  • 3
-1
votes
1 answer

RValue Pointers?

How can I tell if a pointer is an RValue or I don't know what I'm talking about.. This really ridiculous idea popped into my head while drinking a beer.. What if you have stupid programmer/user.. Assume you have the following…
Brandon
  • 22,723
  • 11
  • 93
  • 186
1 2 3
47
48