main.cpp

 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
// for std::move
#include <utility>  
#include <iostream>  
using namespace std;
                    
int main()
{
    int x = 5;  // x: lvalue
    int* p = &x;
    int& y = x; // y: lvalue? 
    const int& z = x; // z: lvalue? 
    int&& y1 = std::move(x); // y1: xvalue
    int&& y2 = std::move(y1); // y2: xvalue

    int x1 = std::move(x);    // different address from x
    //int& x2 = std::move(x); // invalid because non-const
    const int& x2 = std::move(x);  // same address as x
    
    cout << "y1= " << y1 << endl;
    cout << "y2= " << y2 << endl;
    cout << "&y1= " << &y1 << endl;
    cout << "&y2= " << &y2 << endl;

    cout << endl << "x1= " << x1 << endl;
    cout << "&x1= " << &x1 << endl;

    cout << endl << "x2= " << x2 << endl;
    cout << "&x2= " << &x2 << endl;
    return 0;
}
Back to glvalue