Sequoia
Loading...
Searching...
No Matches
OrderableMoveOnlyTestDiagnosticsUtilities.hpp
Go to the documentation of this file.
1
2// Copyright Oliver J. Rosten 2020. //
3// Distributed under the GNU GENERAL PUBLIC LICENSE, Version 3.0. //
4// (See accompanying file LICENSE.md or copy at //
5// https://www.gnu.org/licenses/gpl-3.0.en.html) //
7
8#pragma once
9
13
14#include <vector>
15
16namespace sequoia::testing
17{
19 {
20 public:
21 orderable_resource_binder() = default;
22
23 explicit orderable_resource_binder(int i)
24 : m_Index{i}
25 {}
26
28 : m_Index{std::exchange(other.m_Index, 0)}
29 {}
30
31 orderable_resource_binder& operator=(orderable_resource_binder&& other) noexcept
32 {
33 m_Index = std::exchange(other.m_Index, 0);
34 return *this;
35 }
36
37 [[nodiscard]]
38 int index() const noexcept
39 {
40 return m_Index;
41 }
42
43 [[nodiscard]]
44 friend auto operator<=>(const orderable_resource_binder&, const orderable_resource_binder&) = default;
45
46 template<class Stream>
47 friend Stream& operator<<(Stream& s, const orderable_resource_binder& b)
48 {
49 s << b.index();
50 return s;
51 }
52
53 template<class Stream>
54 friend Stream& operator>>(Stream& s, orderable_resource_binder& b)
55 {
56 s >> b.m_Index;
57 return s;
58 }
59 private:
60 int m_Index{-1};
61 };
62
63 template<class T=int, class Allocator=std::allocator<int>>
65 {
66 using value_type = T;
67 using allocator_type = Allocator;
68
69 orderable_move_only_beast(std::initializer_list<T> list) : x{list} {}
70
71 orderable_move_only_beast(std::initializer_list<T> list, const allocator_type& a) : x{list, a} {}
72
73 orderable_move_only_beast(const allocator_type& a) : x(a) {}
74
76
78
79 orderable_move_only_beast(orderable_move_only_beast&& other, const allocator_type& a) : x(std::move(other.x), a) {}
80
81 orderable_move_only_beast& operator=(const orderable_move_only_beast&) = delete;
82
84
85 void swap(orderable_move_only_beast& other) noexcept(noexcept(std::ranges::swap(this->x, other.x)))
86 {
87 std::ranges::swap(x, other.x);
88 }
89
90 friend void swap(orderable_move_only_beast& lhs, orderable_move_only_beast& rhs)
91 noexcept(noexcept(lhs.swap(rhs)))
92 {
93 lhs.swap(rhs);
94 }
95
96 std::vector<T, Allocator> x{};
97
98 [[nodiscard]]
99 friend auto operator<=>(const orderable_move_only_beast&, const orderable_move_only_beast&) noexcept = default;
100
101 template<class Stream>
102 friend Stream& operator<<(Stream& s, const orderable_move_only_beast& b)
103 {
104 for(auto i : b.x) s << i << ' ';
105 return s;
106 }
107 };
108
109 template<class T, class Allocator>
110 struct value_tester<orderable_move_only_beast<T, Allocator>> : beast_equivalence_tester<orderable_move_only_beast<T, Allocator>> {};
111
112 template<class T = int, class Allocator = std::allocator<int>>
114 {
115 using value_type = T;
116 using allocator_type = Allocator;
117
118 move_only_orderable_specified_moved_from_beast(std::initializer_list<T> list) : x{list} {}
119
120 move_only_orderable_specified_moved_from_beast(std::initializer_list<T> list, const allocator_type& a) : x(list, a) {}
121
122 move_only_orderable_specified_moved_from_beast(const allocator_type& a) : x(a) {}
123
125
127 : x{std::move(other.x)}
128 {
129 other.x.clear();
130 }
131
132 move_only_orderable_specified_moved_from_beast(move_only_orderable_specified_moved_from_beast&& other, const allocator_type& a) : x(std::move(other.x), a) {}
133
135
137 {
138 x = std::move(other.x);
139 other.x.clear();
140
141 return *this;
142 }
143
144 void swap(move_only_orderable_specified_moved_from_beast& other) noexcept(noexcept(std::ranges::swap(this->x, other.x)))
145 {
146 std::ranges::swap(x, other.x);
147 }
148
150 noexcept(noexcept(lhs.swap(rhs)))
151 {
152 lhs.swap(rhs);
153 }
154
155 std::vector<T, Allocator> x{};
156
157 [[nodiscard]]
158 friend auto operator<=>(const move_only_orderable_specified_moved_from_beast&, const move_only_orderable_specified_moved_from_beast&) noexcept = default;
159
160 template<class Stream>
161 friend Stream& operator<<(Stream& s, const move_only_orderable_specified_moved_from_beast& b)
162 {
163 for(const auto& i : b.x) s << i << '\n';
164 return s;
165 }
166 };
167
168 template<class T, class Allocator>
169 struct value_tester<move_only_orderable_specified_moved_from_beast<T, Allocator>> : beast_equivalence_tester<move_only_orderable_specified_moved_from_beast<T, Allocator>> {};
170
171 template<class T=int, class Allocator=std::allocator<int>>
173 {
174 using value_type = int;
175 using allocator_type = Allocator;
176
177 move_only_broken_less(std::initializer_list<T> list) : x{list} {}
178
179 move_only_broken_less(std::initializer_list<T> list, const allocator_type& a) : x{list, a} {}
180
181 move_only_broken_less(const allocator_type& a) : x(a) {}
182
184
185 move_only_broken_less(move_only_broken_less&&) noexcept = default;
186
187 move_only_broken_less(move_only_broken_less&& other, const allocator_type& a) : x(std::move(other.x), a) {}
188
189 move_only_broken_less& operator=(const move_only_broken_less&) = delete;
190
191 move_only_broken_less& operator=(move_only_broken_less&&) = default;
192
193 void swap(move_only_broken_less& other) noexcept(noexcept(std::ranges::swap(this->x, other.x)))
194 {
195 std::ranges::swap(x, other.x);
196 }
197
198 friend void swap(move_only_broken_less& lhs, move_only_broken_less& rhs)
199 noexcept(noexcept(lhs.swap(rhs)))
200 {
201 lhs.swap(rhs);
202 }
203
204 std::vector<T, Allocator> x{};
205
206 [[nodiscard]]
207 friend auto operator<=>(const move_only_broken_less&, const move_only_broken_less&) noexcept = default;
208
209 [[nodiscard]]
210 friend bool operator<(const move_only_broken_less& lhs, const move_only_broken_less& rhs) noexcept
211 {
212 return lhs.x > rhs.x;
213 }
214
215 template<class Stream>
216 friend Stream& operator<<(Stream& s, const move_only_broken_less& b)
217 {
218 for(auto i : b.x) s << i << ' ';
219 return s;
220 }
221 };
222
223 template<class T, class Allocator>
224 struct value_tester<move_only_broken_less<T, Allocator>> : beast_equivalence_tester<move_only_broken_less<T, Allocator>> {};
225
226 template<class T=int, class Allocator=std::allocator<int>>
228 {
229 using value_type = T;
230 using allocator_type = Allocator;
231
232 move_only_broken_lesseq(std::initializer_list<T> list) : x{list} {}
233
234 move_only_broken_lesseq(std::initializer_list<T> list, const allocator_type& a) : x{list, a} {}
235
236 move_only_broken_lesseq(const allocator_type& a) : x(a) {}
237
239
241
242 move_only_broken_lesseq(move_only_broken_lesseq&& other, const allocator_type& a) : x(std::move(other.x), a) {}
243
244 move_only_broken_lesseq& operator=(const move_only_broken_lesseq&) = delete;
245
246 move_only_broken_lesseq& operator=(move_only_broken_lesseq&&) = default;
247
248 void swap(move_only_broken_lesseq& other) noexcept(noexcept(std::ranges::swap(this->x, other.x)))
249 {
250 std::ranges::swap(x, other.x);
251 }
252
253 friend void swap(move_only_broken_lesseq& lhs, move_only_broken_lesseq& rhs)
254 noexcept(noexcept(lhs.swap(rhs)))
255 {
256 lhs.swap(rhs);
257 }
258
259 std::vector<T, Allocator> x{};
260
261 [[nodiscard]]
262 friend bool operator<=(const move_only_broken_lesseq& lhs, const move_only_broken_lesseq& rhs) noexcept
263 {
264 return lhs.x >= rhs.x;
265 }
266
267 [[nodiscard]]
268 friend auto operator<=>(const move_only_broken_lesseq&, const move_only_broken_lesseq&) noexcept = default;
269
270 template<class Stream>
271 friend Stream& operator<<(Stream& s, const move_only_broken_lesseq& b)
272 {
273 for(auto i : b.x) s << i << ' ';
274 return s;
275 }
276 };
277
278 template<class T, class Allocator>
279 struct value_tester<move_only_broken_lesseq<T, Allocator>> : beast_equivalence_tester<move_only_broken_lesseq<T, Allocator>> {};
280
281 template<class T=int, class Allocator=std::allocator<int>>
283 {
284 using value_type = T;
285 using allocator_type = Allocator;
286
287 move_only_broken_greater(std::initializer_list<T> list) : x{list} {}
288
289 move_only_broken_greater(std::initializer_list<T> list, const allocator_type& a) : x{list, a} {}
290
291 move_only_broken_greater(const allocator_type& a) : x(a) {}
292
294
296
297 move_only_broken_greater(move_only_broken_greater&& other, const allocator_type& a) : x(std::move(other.x), a) {}
298
299 move_only_broken_greater& operator=(const move_only_broken_greater&) = delete;
300
302
303 void swap(move_only_broken_greater& other) noexcept(noexcept(std::ranges::swap(this->x, other.x)))
304 {
305 std::ranges::swap(x, other.x);
306 }
307
308 friend void swap(move_only_broken_greater& lhs, move_only_broken_greater& rhs)
309 noexcept(noexcept(lhs.swap(rhs)))
310 {
311 lhs.swap(rhs);
312 }
313
314 std::vector<T, Allocator> x{};
315
316 [[nodiscard]]
317 friend bool operator>(const move_only_broken_greater& lhs, const move_only_broken_greater& rhs) noexcept
318 {
319 return lhs.x < rhs.x;
320 }
321
322 [[nodiscard]]
323 friend auto operator<=>(const move_only_broken_greater&, const move_only_broken_greater&) noexcept = default;
324
325 template<class Stream>
326 friend Stream& operator<<(Stream& s, const move_only_broken_greater& b)
327 {
328 for(auto i : b.x) s << i << ' ';
329 return s;
330 }
331 };
332
333 template<class T, class Allocator>
334 struct value_tester<move_only_broken_greater<T, Allocator>> : beast_equivalence_tester<move_only_broken_greater<T, Allocator>> {};
335
336 template<class T=int, class Allocator=std::allocator<int>>
338 {
339 using value_type = T;
340 using allocator_type = Allocator;
341
342 move_only_broken_greatereq(std::initializer_list<T> list) : x{list} {}
343
344 move_only_broken_greatereq(std::initializer_list<T> list, const allocator_type& a) : x{list, a} {}
345
346 move_only_broken_greatereq(const allocator_type& a) : x(a) {}
347
349
351
352 move_only_broken_greatereq(move_only_broken_greatereq&& other, const allocator_type& a) : x(std::move(other.x), a) {}
353
354 move_only_broken_greatereq& operator=(const move_only_broken_greatereq&) = delete;
355
357
358 void swap(move_only_broken_greatereq& other) noexcept(noexcept(std::ranges::swap(this->x, other.x)))
359 {
360 std::ranges::swap(x, other.x);
361 }
362
363 friend void swap(move_only_broken_greatereq& lhs, move_only_broken_greatereq& rhs)
364 noexcept(noexcept(lhs.swap(rhs)))
365 {
366 lhs.swap(rhs);
367 }
368
369 std::vector<T, Allocator> x{};
370
371 [[nodiscard]]
372 friend bool operator>=(const move_only_broken_greatereq& lhs, const move_only_broken_greatereq& rhs) noexcept
373 {
374 return lhs.x <= rhs.x;
375 }
376
377 [[nodiscard]]
378 friend auto operator<=>(const move_only_broken_greatereq&, const move_only_broken_greatereq&) noexcept = default;
379
380 template<class Stream>
381 friend Stream& operator<<(Stream& s, const move_only_broken_greatereq& b)
382 {
383 for(auto i : b.x) s << i << ' ';
384 return s;
385 }
386 };
387
388 template<class T, class Allocator>
389 struct value_tester<move_only_broken_greatereq<T, Allocator>> : beast_equivalence_tester<move_only_broken_greatereq<T, Allocator>> {};
390
391 template<class T=int, class Allocator=std::allocator<int>>
393 {
394 using value_type = T;
395 using allocator_type = Allocator;
396
397 move_only_inverted_comparisons(std::initializer_list<T> list) : x{list} {}
398
399 move_only_inverted_comparisons(std::initializer_list<T> list, const allocator_type& a) : x{list, a} {}
400
401 move_only_inverted_comparisons(const allocator_type& a) : x(a) {}
402
404
406
407 move_only_inverted_comparisons(move_only_inverted_comparisons&& other, const allocator_type& a) : x(std::move(other.x), a) {}
408
410
412
413 void swap(move_only_inverted_comparisons& other) noexcept(noexcept(std::ranges::swap(this->x, other.x)))
414 {
415 std::ranges::swap(x, other.x);
416 }
417
419 noexcept(noexcept(lhs.swap(rhs)))
420 {
421 lhs.swap(rhs);
422 }
423
424 std::vector<T, Allocator> x{};
425
426 [[nodiscard]]
427 friend bool operator==(const move_only_inverted_comparisons&, const move_only_inverted_comparisons&) noexcept = default;
428
429 [[nodiscard]]
430 friend bool operator!=(const move_only_inverted_comparisons&, const move_only_inverted_comparisons&) noexcept = default;
431
432 [[nodiscard]]
433 friend bool operator<(const move_only_inverted_comparisons& lhs, const move_only_inverted_comparisons& rhs) noexcept
434 {
435 return lhs.x > rhs.x;
436 }
437
438 [[nodiscard]]
439 friend bool operator<=(const move_only_inverted_comparisons& lhs, const move_only_inverted_comparisons& rhs) noexcept
440 {
441 return lhs.x >= rhs.x;
442 }
443
444 [[nodiscard]]
445 friend bool operator>(const move_only_inverted_comparisons& lhs, const move_only_inverted_comparisons& rhs) noexcept
446 {
447 return lhs.x < rhs.x;
448 }
449
450 [[nodiscard]]
451 friend bool operator>=(const move_only_inverted_comparisons& lhs, const move_only_inverted_comparisons& rhs) noexcept
452 {
453 return lhs.x <= rhs.x;
454 }
455
456 [[nodiscard]]
457 friend auto operator<=>(const move_only_inverted_comparisons&, const move_only_inverted_comparisons&) noexcept = default;
458
459 template<class Stream>
460 friend Stream& operator<<(Stream& s, const move_only_inverted_comparisons& b)
461 {
462 for(auto i : b.x) s << i << ' ';
463 return s;
464 }
465 };
466
467 template<class T, class Allocator>
468 struct value_tester<move_only_inverted_comparisons<T, Allocator>> : beast_equivalence_tester<move_only_inverted_comparisons<T, Allocator>> {};
469
470 template<class T=int, class Allocator=std::allocator<int>>
472 {
473 using value_type = T;
474 using allocator_type = Allocator;
475
476 move_only_broken_spaceship(std::initializer_list<T> list) : x{list} {}
477
478 move_only_broken_spaceship(std::initializer_list<T> list, const allocator_type& a) : x{list, a} {}
479
480 move_only_broken_spaceship(const allocator_type& a) : x(a) {}
481
483
485
486 move_only_broken_spaceship(move_only_broken_spaceship&& other, const allocator_type& a) : x(std::move(other.x), a) {}
487
488 move_only_broken_spaceship& operator=(const move_only_broken_spaceship&) = delete;
489
491
492 void swap(move_only_broken_spaceship& other) noexcept(noexcept(std::ranges::swap(this->x, other.x)))
493 {
494 std::ranges::swap(x, other.x);
495 }
496
497 friend void swap(move_only_broken_spaceship& lhs, move_only_broken_spaceship& rhs)
498 noexcept(noexcept(lhs.swap(rhs)))
499 {
500 lhs.swap(rhs);
501 }
502
503 std::vector<T, Allocator> x{};
504
505 [[nodiscard]]
506 friend bool operator==(const move_only_broken_spaceship&, const move_only_broken_spaceship&) noexcept = default;
507
508 [[nodiscard]]
509 friend bool operator!=(const move_only_broken_spaceship&, const move_only_broken_spaceship&) noexcept = default;
510
511 [[nodiscard]]
512 friend bool operator<(const move_only_broken_spaceship& lhs, const move_only_broken_spaceship& rhs) noexcept
513 {
514 return lhs.x < rhs.x;
515 }
516
517 [[nodiscard]]
518 friend bool operator<=(const move_only_broken_spaceship& lhs, const move_only_broken_spaceship& rhs) noexcept
519 {
520 return lhs.x <= rhs.x;
521 }
522
523 [[nodiscard]]
524 friend bool operator>(const move_only_broken_spaceship& lhs, const move_only_broken_spaceship& rhs) noexcept
525 {
526 return lhs.x > rhs.x;
527 }
528
529 [[nodiscard]]
530 friend bool operator>=(const move_only_broken_spaceship& lhs, const move_only_broken_spaceship& rhs) noexcept
531 {
532 return lhs.x >= rhs.x;
533 }
534
535 friend std::weak_ordering operator<=>(const move_only_broken_spaceship& lhs, const move_only_broken_spaceship& rhs) noexcept
536 {
537 if(lhs < rhs) return std::weak_ordering::greater;
538
539 if(rhs > lhs) return std::weak_ordering::less;
540
541 return std::weak_ordering::equivalent;
542 }
543
544 template<class Stream>
545 friend Stream& operator<<(Stream& s, const move_only_broken_spaceship& b)
546 {
547 for(auto i : b.x) s << i << ' ';
548 return s;
549 }
550 };
551
552 template<class T, class Allocator>
553 struct value_tester<move_only_broken_spaceship<T, Allocator>> : beast_equivalence_tester<move_only_broken_spaceship<T, Allocator>> {};
554}
Definition: OrderableMoveOnlyTestDiagnosticsUtilities.hpp:19
Definition: SemanticsTestDiagnosticsUtilities.hpp:20
Definition: OrderableMoveOnlyTestDiagnosticsUtilities.hpp:283
Definition: OrderableMoveOnlyTestDiagnosticsUtilities.hpp:338
Definition: OrderableMoveOnlyTestDiagnosticsUtilities.hpp:173
Definition: OrderableMoveOnlyTestDiagnosticsUtilities.hpp:228
Definition: OrderableMoveOnlyTestDiagnosticsUtilities.hpp:472
Definition: OrderableMoveOnlyTestDiagnosticsUtilities.hpp:393
Definition: OrderableMoveOnlyTestDiagnosticsUtilities.hpp:114
Definition: OrderableMoveOnlyTestDiagnosticsUtilities.hpp:65
class template, specializations of which implement various comparisons for the specified type.
Definition: FreeCheckers.hpp:78