-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA12-0-1.cpp
More file actions
146 lines (106 loc) · 2.6 KB
/
A12-0-1.cpp
File metadata and controls
146 lines (106 loc) · 2.6 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// Rule: A12-0-1
// Source line: 16448
// Original file: A12-0-1.cpp
// $Id: A12-0-1.cpp 309769 2018-03-01 17:40:29Z jan.babst $
#include <string>
namespace v1
{
// Class is copyable and moveable via the compiler generated funtions.
// Compliant - rule of zero.
class A
{
private:
// Member data ...
};
} // namespace v1
namespace v2
{
// New requirement: Destructor needs to be added.
// Now the class is no longer moveable, but still copyable. The program
// still compiles, but may perform worse.
// Non-compliant - Unclear if this was the developers intent.
class A
{
public:
~A()
{
// ...
}
private:
// Member data ...
};
} // namespace v2
namespace v3
{
// Move operations are brought back by defaulting them.
// Copy operations are defaulted since they are no longer generated
// (complies to A12-0-1 but will also be a compiler error if they are needed).
// Default constructor is defaulted since it is no longer generated
// (not required by A12-0-1 but will be a compiler error if it is needed).
// Compliant - rule of five. Programmer’s intent is clear, class behaves the
// same as v1::A.
class A
{
public:
A() = default;
A(A const&) = default;
A(A&&) = default;
~A()
{
// ...
}
A& operator=(A const&) = default;
A& operator=(A&&) = default;
private:
// Member data ...
};
} // namespace v3
// A class with regular (value) semantics.
// Compliant - rule of zero.
class Simple
{
public:
// User defined constructor, also acts as default constructor.
explicit Simple(double d = 0.0, std::string s = "Hello")
: d_(d), s_(std::move(s))
{}
// Compiler generated copy c’tor, move c’tor, d’tor, copy assignment, move
// assignment.
private:
double d_;
std::string s_;
};
// A base class.
// Compliant - rule of five.
class Base
{
public:
Base(Base const&) = delete;
Base(Base&&) = delete;
virtual ~Base() = default;
Base& operator=(Base const&) = delete;
Base& operator=(Base&&) = delete;
// see also A12-8-6
// see also A12-8-6
// see also A12-4-1
// see also A12-8-6
// see also A12-8-6
// Declarations of pure virtual functions ...
protected:
Base() = default;
// in order to allow construction of derived objects
};
// A move-only class.
// Compliant - rule of five.
class MoveOnly
{
public:
MoveOnly();
MoveOnly(MoveOnly const&) = delete;
MoveOnly(MoveOnly&&) noexcept;
~MoveOnly();
MoveOnly& operator=(MoveOnly const&) = delete;
MoveOnly& operator=(MoveOnly&&) noexcept;
private:
// ...
};