-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcppVersions
57 lines (39 loc) · 1.21 KB
/
cppVersions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
C++ 11:
https://en.wikipedia.org/wiki/C++11
1. Rvalue references:
Lvalue and Rvalue refer to the left and right side of the assignment operator
lvalue: something that points to a specific memory location (variables)
rvalue: something that doesn't point anywhere
int x = 666; x is lvalue, and 666 is rvalue.
A reference is something that points to an existing memory location
int global = 100;
int& setGlobal()
{
return global;
}
// ... somewhere in main() ...
setGlobal() = 400; // OK
Watch out for & here: it's not the address-of operator, it defines the type of what's returned (a reference).
Lvalue references:
int y = 10;
int& yref = y;
yref++; // y is now 11
Lvalue to rvalue conversion
int x = 1;
int y = 3;
int z = x + y; // ok
forbidden conversion from rvalue to lvalue
If X is any type, then X&& is called an rvalue reference to X.
the ordinary reference X& is now also called an lvalue reference.
X& X::operator=(X const & rhs); // classical implementation
X& X::operator=(X&& rhs)
{
// Move semantics: exchange content between this and rhs
return *this;
}
Move semantics:
Range-based for loops
initializer lists
lambdas
smart pointers
Standardized semantics for multithreaded programs: