1515#include < vector>
1616#include < flat_map>
1717
18+ #include " ../flat_helpers.h"
1819#include " test_allocator.h"
1920#include " test_macros.h"
2021
@@ -30,150 +31,6 @@ void check_invariant(const std::flat_map<Args...>& m) {
3031 assert (std::adjacent_find (keys.begin (), keys.end (), key_equal) == keys.end ());
3132}
3233
33- struct StartsWith {
34- explicit StartsWith (char ch) : lower_(1 , ch), upper_(1 , ch + 1 ) {}
35- StartsWith (const StartsWith&) = delete ;
36- void operator =(const StartsWith&) = delete ;
37- struct Less {
38- using is_transparent = void ;
39- bool operator ()(const std::string& a, const std::string& b) const { return a < b; }
40- bool operator ()(const StartsWith& a, const std::string& b) const { return a.upper_ <= b; }
41- bool operator ()(const std::string& a, const StartsWith& b) const { return a < b.lower_ ; }
42- bool operator ()(const StartsWith&, const StartsWith&) const {
43- assert (false ); // should not be called
44- return false ;
45- }
46- };
47-
48- private:
49- std::string lower_;
50- std::string upper_;
51- };
52-
53- template <class T >
54- struct CopyOnlyVector : std::vector<T> {
55- using std::vector<T>::vector;
56-
57- CopyOnlyVector (const CopyOnlyVector&) = default ;
58- CopyOnlyVector (CopyOnlyVector&& other) : CopyOnlyVector(other) {}
59- CopyOnlyVector (CopyOnlyVector&& other, std::vector<T>::allocator_type alloc) : CopyOnlyVector(other, alloc) {}
60-
61- CopyOnlyVector& operator =(const CopyOnlyVector&) = default ;
62- CopyOnlyVector& operator =(CopyOnlyVector& other) { return this ->operator =(other); }
63- };
64-
65- template <class T , bool ConvertibleToT = false >
66- struct Transparent {
67- T t;
68-
69- operator T () const
70- requires ConvertibleToT
71- {
72- return t;
73- }
74- };
75-
76- template <class T >
77- using ConvertibleTransparent = Transparent<T, true >;
78-
79- template <class T >
80- using NonConvertibleTransparent = Transparent<T, false >;
81-
82- struct TransparentComparator {
83- using is_transparent = void ;
84-
85- bool * transparent_used = nullptr ;
86- TransparentComparator () = default ;
87- TransparentComparator (bool & used) : transparent_used(&used) {}
88-
89- template <class T , bool Convertible>
90- bool operator ()(const T& t, const Transparent<T, Convertible>& transparent) const {
91- if (transparent_used != nullptr ) {
92- *transparent_used = true ;
93- }
94- return t < transparent.t ;
95- }
96-
97- template <class T , bool Convertible>
98- bool operator ()(const Transparent<T, Convertible>& transparent, const T& t) const {
99- if (transparent_used != nullptr ) {
100- *transparent_used = true ;
101- }
102- return transparent.t < t;
103- }
104-
105- template <class T >
106- bool operator ()(const T& t1, const T& t2) const {
107- return t1 < t2;
108- }
109- };
110-
111- struct NonTransparentComparator {
112- template <class T , bool Convertible>
113- bool operator ()(const T&, const Transparent<T, Convertible>&) const ;
114-
115- template <class T , bool Convertible>
116- bool operator ()(const Transparent<T, Convertible>&, const T&) const ;
117-
118- template <class T >
119- bool operator ()(const T&, const T&) const ;
120- };
121-
122- struct NoDefaultCtr {
123- NoDefaultCtr () = delete ;
124- };
125-
126- #ifndef TEST_HAS_NO_EXCEPTIONS
127- template <class T >
128- struct EmplaceUnsafeContainer : std::vector<T> {
129- using std::vector<T>::vector;
130-
131- template <class ... Args>
132- auto emplace (Args&&... args) -> decltype(std::declval<std::vector<T>>().emplace(std::forward<Args>(args)...)) {
133- if (this ->size () > 1 ) {
134- auto it1 = this ->begin ();
135- auto it2 = it1 + 1 ;
136- // messing up the container
137- std::iter_swap (it1, it2);
138- }
139-
140- throw 42 ;
141- }
142-
143- template <class ... Args>
144- auto insert (Args&&... args) -> decltype(std::declval<std::vector<T>>().insert(std::forward<Args>(args)...)) {
145- if (this ->size () > 1 ) {
146- auto it1 = this ->begin ();
147- auto it2 = it1 + 1 ;
148- // messing up the container
149- std::iter_swap (it1, it2);
150- }
151-
152- throw 42 ;
153- }
154- };
155-
156- template <class T >
157- struct ThrowOnEraseContainer : std::vector<T> {
158- using std::vector<T>::vector;
159-
160- template <class ... Args>
161- auto erase (Args&&... args) -> decltype(std::declval<std::vector<T>>().erase(std::forward<Args>(args)...)) {
162- throw 42 ;
163- }
164- };
165-
166- template <class T >
167- struct ThrowOnMoveContainer : std::vector<T> {
168- using std::vector<T>::vector;
169-
170- ThrowOnMoveContainer (ThrowOnMoveContainer&&) { throw 42 ; }
171-
172- ThrowOnMoveContainer& operator =(ThrowOnMoveContainer&&) { throw 42 ; }
173- };
174-
175- #endif
176-
17734template <class F >
17835void test_emplace_exception_guarantee ([[maybe_unused]] F&& emplace_function) {
17936#ifndef TEST_HAS_NO_EXCEPTIONS
@@ -363,32 +220,5 @@ void test_erase_exception_guarantee([[maybe_unused]] F&& erase_function) {
363220 }
364221#endif
365222}
366- class Moveable {
367- int int_;
368- double double_;
369-
370- public:
371- Moveable () : int_(0 ), double_(0 ) {}
372- Moveable (int i, double d) : int_(i), double_(d) {}
373- Moveable (Moveable&& x) : int_(x.int_), double_(x.double_) {
374- x.int_ = -1 ;
375- x.double_ = -1 ;
376- }
377- Moveable& operator =(Moveable&& x) {
378- int_ = x.int_ ;
379- x.int_ = -1 ;
380- double_ = x.double_ ;
381- x.double_ = -1 ;
382- return *this ;
383- }
384-
385- Moveable (const Moveable&) = delete ;
386- Moveable& operator =(const Moveable&) = delete ;
387- bool operator ==(const Moveable& x) const { return int_ == x.int_ && double_ == x.double_ ; }
388- bool operator <(const Moveable& x) const { return int_ < x.int_ || (int_ == x.int_ && double_ < x.double_ ); }
389-
390- int get () const { return int_; }
391- bool moved () const { return int_ == -1 ; }
392- };
393223
394224#endif // SUPPORT_FLAT_MAP_HELPERS_H
0 commit comments