forked from cirosantilli/cpp-cheat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
no_base_no_member.hpp
74 lines (58 loc) · 2.28 KB
/
no_base_no_member.hpp
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
Simple class for tests on constructor destructor order.
This class has no members which are objects and no base classes.
TODO break this class up.
*/
class NoBaseNoMember {
public:
int i;
/// Default constructor
NoBaseNoMember() : i(0) {
callStack.push_back("NoBaseNoMember::NoBaseNoMember()");
}
/// Copy constructor
NoBaseNoMember(const NoBaseNoMember& other) : i(other.i) {
callStack.push_back("NoBaseNoMember::NoBaseNoMember(NoBaseNoMember)");
}
NoBaseNoMember(int i) : i(i) {callStack.push_back("NoBaseNoMember::NoBaseNoMember(int)");}
/// Assign
NoBaseNoMember& operator= (const NoBaseNoMember& rhs) {
this->i = rhs.i;
callStack.push_back("NoBaseNoMember::operator=");
return *this;
}
/// Destructor
~NoBaseNoMember() { callStack.push_back("NoBaseNoMember::~NoBaseNoMember()"); }
void method() { callStack.push_back("NoBaseNoMember::method()"); }
static NoBaseNoMember create() {
return NoBaseNoMember();
}
static NoBaseNoMember createNrvo() {
NoBaseNoMember c;
return c;
}
/// It would be hard or impossible to do RVO for this function.
static NoBaseNoMember createNrvoHard(bool b = false) {
//2 int constructors
NoBaseNoMember cf = NoBaseNoMember(0);
NoBaseNoMember ct = NoBaseNoMember(1);
return b ? ct : cf;
//2 int destructors
}
static void temporaryReference(NoBaseNoMember& temp) {
temp.i = 0;
}
static void temporaryReferenceConst(const NoBaseNoMember& temp) {}
};
class NoBaseNoMember0 {
public:
NoBaseNoMember0(){callStack.push_back("NoBaseNoMember0::NoBaseNoMember0()");}
~NoBaseNoMember0(){callStack.push_back("NoBaseNoMember0::~NoBaseNoMember0()");}
void method(){callStack.push_back("NoBaseNoMember0::method()");}
};
class NoBaseNoMember1 {
public:
NoBaseNoMember1(){callStack.push_back("NoBaseNoMember1::NoBaseNoMember1()");}
~NoBaseNoMember1(){callStack.push_back("NoBaseNoMember1::~NoBaseNoMember1()");}
void method(){callStack.push_back("NoBaseNoMember1::method()");}
};