-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrvalue_references.cpp
More file actions
33 lines (26 loc) · 950 Bytes
/
rvalue_references.cpp
File metadata and controls
33 lines (26 loc) · 950 Bytes
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
//*****************************************************************************
//
// Author: Michael Price
// License: Attribution-NonCommercial-NoDerivs 3.0 Unported
// http://creativecommons.org/licenses/by-nc-nd/3.0/legalcode
//
//*****************************************************************************
#include "move_semantics.h"
MoveableBuffer rval_helper ()
{
MoveableBuffer this_can_move; return this_can_move;
}
void rval_func ()
{
// Default Construction
MoveableBuffer some_object;
// Copy Construction (always)
MoveableBuffer another_object = some_object;
// Move Assignment (if available, else Copy Assignment)
another_object = rval_helper();
// Reference Capturing
MoveableBuffer & normal_ref_1 = some_object;
//MoveableBuffer && rval_ref_1 = some_object; // Error!
const MoveableBuffer & normal_ref_2 = rval_helper();
MoveableBuffer && rval_ref_2 = rval_helper();
}