-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-classes.h
More file actions
252 lines (213 loc) · 6.62 KB
/
test-classes.h
File metadata and controls
252 lines (213 loc) · 6.62 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
#pragma once
#include <cassert>
#include <cstddef>
#include <exception>
#include <string>
#include <vector>
template <class... Ts>
struct overload : Ts... {
using Ts::operator()...;
};
template <class... Ts>
overload(Ts...) -> overload<Ts...>;
struct trivial_t {};
struct no_default_t {
no_default_t() = delete;
};
struct throwing_default_t {
throwing_default_t() {
throw std::exception();
}
};
struct throwing_move_operator_t {
static size_t swap_called; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
throwing_move_operator_t() = default;
throwing_move_operator_t(throwing_move_operator_t&&) noexcept(false) { // NOLINT(bugprone-exception-escape)
throw std::exception();
}
throwing_move_operator_t& operator=(throwing_move_operator_t&&) = default;
};
void swap(throwing_move_operator_t&, throwing_move_operator_t&);
struct no_copy_t {
no_copy_t(const no_copy_t&) = delete;
};
struct no_move_t {
no_move_t(no_move_t&&) = delete;
};
struct non_trivial_copy_t {
explicit non_trivial_copy_t(int x) noexcept : x{x} {}
non_trivial_copy_t(const non_trivial_copy_t& other) noexcept : x{other.x + 1} {}
int x;
};
struct non_trivial_copy_assignment_t {
static constexpr int DELTA = 5;
explicit non_trivial_copy_assignment_t(int x) noexcept : x{x} {}
non_trivial_copy_assignment_t& operator=(const non_trivial_copy_assignment_t& other) {
if (this != &other) {
x = other.x + DELTA;
}
return *this;
};
int x;
};
struct non_trivial_int_wrapper_t {
non_trivial_int_wrapper_t(int x) : x{x} {} // NOLINT(google-explicit-constructor)
non_trivial_int_wrapper_t& operator=(int i) {
x = i + 1;
return *this;
}
friend constexpr bool operator==(non_trivial_int_wrapper_t const& lhs,
non_trivial_int_wrapper_t const& rhs) noexcept {
return lhs.x == rhs.x;
}
friend constexpr bool operator!=(non_trivial_int_wrapper_t const& lhs,
non_trivial_int_wrapper_t const& rhs) noexcept {
return lhs.x != rhs.x;
}
friend constexpr bool operator<(non_trivial_int_wrapper_t const& lhs, non_trivial_int_wrapper_t const& rhs) noexcept {
return lhs.x < rhs.x;
}
friend constexpr bool operator<=(non_trivial_int_wrapper_t const& lhs,
non_trivial_int_wrapper_t const& rhs) noexcept {
return lhs.x <= rhs.x;
}
friend constexpr bool operator>(non_trivial_int_wrapper_t const& lhs, non_trivial_int_wrapper_t const& rhs) noexcept {
return lhs.x > rhs.x;
}
friend constexpr bool operator>=(non_trivial_int_wrapper_t const& lhs,
non_trivial_int_wrapper_t const& rhs) noexcept {
return lhs.x >= rhs.x;
}
int x;
};
struct no_move_assignment_t {
no_move_assignment_t& operator=(no_move_assignment_t&&) = delete;
};
struct no_copy_assignment_t {
no_copy_assignment_t& operator=(const no_copy_assignment_t&) = delete;
};
struct throwing_move_assignment_t {
throwing_move_assignment_t(throwing_move_assignment_t&&) = default;
throwing_move_assignment_t&
operator=(throwing_move_assignment_t&&) noexcept(false) { // NOLINT(bugprone-exception-escape)
throw std::exception();
}
};
struct only_movable {
static size_t move_assignment_called; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
constexpr only_movable() = default;
constexpr only_movable(only_movable&& other) noexcept {
assert(other.coin && "Move of moved value?");
coin = true;
other.coin = false;
}
constexpr only_movable& operator=(only_movable&& other) noexcept {
if (this != &other) {
assert(other.coin && "Move of moved value?");
move_assignment_called += 1;
coin = true;
other.coin = false;
}
return *this;
}
[[nodiscard]] constexpr bool has_coin() const noexcept {
return coin;
}
only_movable(only_movable const&) = delete;
only_movable& operator=(only_movable const&) = delete;
private:
bool coin{true};
};
struct yac_coin {
constexpr operator int() noexcept { // NOLINT(google-explicit-constructor)
return 42; // NOLINT(cppcoreguidelines-avoid-magic-numbers)
}
};
struct coin_wrapper {
constexpr coin_wrapper() noexcept = default;
constexpr coin_wrapper(coin_wrapper&& other) noexcept {
assert(other.coin && "Move of moved value?");
coin = other.coin;
other.coin = 0;
}
constexpr coin_wrapper& operator=(coin_wrapper&& other) noexcept {
if (this != &other) {
assert((other.coin != 0) && "Move of moved value?");
coin = other.coin;
other.coin = 0;
}
return *this;
}
[[nodiscard]] constexpr auto has_coins() const noexcept {
return coin;
}
constexpr explicit coin_wrapper(yac_coin) noexcept : coin{17} {} // NOLINT(cppcoreguidelines-avoid-magic-numbers)
constexpr coin_wrapper(coin_wrapper const& other) noexcept : coin(other.coin + 1) {}
constexpr coin_wrapper& operator=(coin_wrapper const& other) noexcept {
if (this != &other) {
coin = other.coin + 1;
}
return *this;
}
private:
int coin{1};
};
struct sqr_sum_visitor {
template <typename... Args>
constexpr long operator()(Args... args) const noexcept {
return ((args * args) + ...);
}
};
struct strange_visitor {
strange_visitor() = default;
strange_visitor(strange_visitor const&) = delete;
strange_visitor(strange_visitor&&) = default;
constexpr int operator()(int value) & {
return value;
}
constexpr int operator()(int value) && {
return value + 1;
}
constexpr int operator()(int value) const& {
return value + 2;
}
constexpr int operator()(int value) const&& {
return value + 3;
}
};
struct broken_address {
broken_address* operator&() { // NOLINT(google-runtime-operator)
return nullptr;
}
broken_address const* operator&() const { // NOLINT(google-runtime-operator)
return nullptr;
}
std::vector<int> x;
};
struct empty_comparable {
empty_comparable() = default;
empty_comparable(empty_comparable&&) { // NOLINT(bugprone-exception-escape)
throw std::exception();
}
empty_comparable& operator=(empty_comparable&&) { // NOLINT(bugprone-exception-escape)
throw std::exception();
}
bool operator==(const empty_comparable&) const {
throw std::exception();
}
bool operator!=(const empty_comparable&) const {
throw std::exception();
}
bool operator<(const empty_comparable&) const {
throw std::exception();
}
bool operator<=(const empty_comparable&) const {
throw std::exception();
}
bool operator>(const empty_comparable&) const {
throw std::exception();
}
bool operator>=(const empty_comparable&) const {
throw std::exception();
}
};