lvalue, rvalue
-
lvalue(locator value): Anything that can hold a address. Appear
on the left-hand side of an assignment.
rvalue(read value): temporary value that does not occupy a persistent memory location. Appears on the right-hand side of an assignment
int a = 10; // a is l value
// 10 is rvalue
int x = a+b; // x is l value
// a+b is rvalue
lvalue reference or Reference Variable (&)
-
Reference to bind to lvalue. This is same as reference variable
Usage: Pass large objects without copying.
int a = 10;
int &b = a; // lvalue reference
b = 11;
cout << a; // 11
-
Example:
Copy Constructor
is lvalue reference
rvalue reference (&&)
-
Reference that binds to an rvalue(temporary value).
Usage:
Move semantics (ie moving a temporary withut copying it).
Perfect forwarding in template functions.
int a = 10;
int &&b = 10; // rvalue reference
-
Example:
Move constructor
XValue / Expiring Value
- (b+c) is called xvalue/temporary value which is ready to expire
a = b+c;
PRValue / Pure R Value
- Literal value is called pure R value
a = 42;