]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/support/nasty_containers.hpp
Vendor import of libc++ trunk r290819:
[FreeBSD/FreeBSD.git] / test / support / nasty_containers.hpp
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef NASTY_CONTAINERS_H
11 #define NASTY_CONTAINERS_H
12
13 #include <cassert>
14 #include <vector>
15 #include <list>
16
17 #include "test_macros.h"
18
19 template <class T>
20 class nasty_vector
21 {
22 public:
23     typedef typename std::vector<T>                           nested_container;
24     typedef typename nested_container::value_type             value_type;
25     typedef typename nested_container::reference              reference;
26     typedef typename nested_container::const_reference        const_reference;
27     typedef typename nested_container::iterator               iterator;
28     typedef typename nested_container::const_iterator         const_iterator;
29
30     typedef typename nested_container::size_type              size_type;
31     typedef typename nested_container::difference_type        difference_type;
32     typedef typename nested_container::pointer                pointer;
33     typedef typename nested_container::const_pointer          const_pointer;
34
35     typedef typename nested_container::reverse_iterator       reverse_iterator;
36     typedef typename nested_container::const_reverse_iterator const_reverse_iterator;
37
38     nasty_vector() : v_() {}
39     explicit nasty_vector(size_type n) : v_(n) {}
40     nasty_vector(size_type n, const value_type& value) : v_(n, value) {}
41     template <class InputIterator> nasty_vector(InputIterator first, InputIterator last) : v_(first, last) {}
42 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
43     nasty_vector(std::initializer_list<value_type> il) : v_(il) {}
44 #endif
45     ~nasty_vector() {}
46
47     template <class InputIterator>
48         void assign(InputIterator first, InputIterator last) { v_.assign(first, last); }
49     void assign(size_type n, const value_type& u) { v_.assign(n, u); }
50 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
51     void assign(std::initializer_list<value_type> il)  { v_.assign(il); }
52 #endif
53
54     iterator               begin() TEST_NOEXCEPT         { return v_.begin(); }
55     const_iterator         begin()   const TEST_NOEXCEPT { return v_.begin(); }
56     iterator               end() TEST_NOEXCEPT           { return v_.end(); }
57     const_iterator         end()     const TEST_NOEXCEPT { return v_.end(); }
58
59     reverse_iterator       rbegin() TEST_NOEXCEPT        { return v_.rbegin(); }
60     const_reverse_iterator rbegin()  const TEST_NOEXCEPT { return v_.rbegin(); }
61     reverse_iterator       rend() TEST_NOEXCEPT          { return v_.rend(); }
62     const_reverse_iterator rend()    const TEST_NOEXCEPT { return v_.rend(); }
63
64     const_iterator         cbegin()  const TEST_NOEXCEPT { return v_.cbegin(); }
65     const_iterator         cend()    const TEST_NOEXCEPT { return v_.cend(); }
66     const_reverse_iterator crbegin() const TEST_NOEXCEPT { return v_.crbegin(); }
67     const_reverse_iterator crend()   const TEST_NOEXCEPT { return v_.crend(); }
68
69     size_type size() const TEST_NOEXCEPT      { return v_.size(); }
70     size_type max_size() const TEST_NOEXCEPT  { return v_.max_size(); }
71     size_type capacity() const TEST_NOEXCEPT  { return v_.capacity(); }
72     bool empty() const TEST_NOEXCEPT          { return v_.empty(); }
73     void reserve(size_type n)             { v_.reserve(n); };
74     void shrink_to_fit() TEST_NOEXCEPT        { v_.shrink_to_fit(); }
75
76     reference       operator[](size_type n)       { return v_[n]; }
77     const_reference operator[](size_type n) const { return v_[n]; }
78     reference       at(size_type n)               { return v_.at(n); }
79     const_reference at(size_type n) const         { return v_.at(n); }
80
81     reference       front()       { return v_.front(); }
82     const_reference front() const { return v_.front(); }
83     reference       back()        { return v_.back(); }
84     const_reference back() const  { return v_.back(); }
85
86     value_type*       data() TEST_NOEXCEPT       { return v_.data(); }
87     const value_type* data() const TEST_NOEXCEPT { return v_.data(); }
88
89     void push_back(const value_type& x)     { v_.push_back(x); }
90 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
91     void push_back(value_type&& x)          { v_.push_back(std::forward<value_type&&>(x)); }
92 #ifndef _LIBCPP_HAS_NO_VARIADICS
93     template <class... Args>
94         void emplace_back(Args&&... args)   { v_.emplace_back(std::forward<Args>(args)...); }
95 #endif
96 #endif
97     void pop_back()                         { v_.pop_back(); }
98
99 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
100 #ifndef _LIBCPP_HAS_NO_VARIADICS
101     template <class... Args> iterator emplace(const_iterator pos, Args&&... args)
102     { return v_.emplace(pos, std::forward<Args>(args)...); }
103 #endif
104 #endif
105
106     iterator insert(const_iterator pos, const value_type& x) { return v_.insert(pos, x); }
107 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
108     iterator insert(const_iterator pos, value_type&& x)      { return v_.insert(pos, std::forward<value_type>(x)); }
109 #endif
110     iterator insert(const_iterator pos, size_type n, const value_type& x) { return v_.insert(pos, n, x); }
111     template <class InputIterator>
112         iterator insert(const_iterator pos, InputIterator first, InputIterator last)
113     { return v_.insert(pos, first, last); }
114
115 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
116     iterator insert(const_iterator pos, std::initializer_list<value_type> il) { return v_.insert(pos, il); }
117 #endif
118
119     iterator erase(const_iterator pos)                        { return v_.erase(pos); }
120     iterator erase(const_iterator first, const_iterator last) { return v_.erase(first, last); }
121
122     void clear() TEST_NOEXCEPT { v_.clear(); }
123
124     void resize(size_type sz)                      { v_.resize(sz); }
125     void resize(size_type sz, const value_type& c) { v_.resize(sz, c); }
126
127     void swap(nasty_vector &nv)
128 #if TEST_STD_VER > 14
129     noexcept(std::is_nothrow_swappable<nested_container>::value)
130 #elif defined(_LIBCPP_VERSION)
131     TEST_NOEXCEPT_COND(std::__is_nothrow_swappable<nested_container>::value)
132 #endif
133     { v_.swap(nv.v_); }
134
135     nasty_vector *operator &()             { assert(false); return nullptr; }  // nasty
136     const nasty_vector *operator &() const { assert(false); return nullptr; }  // nasty
137
138     nested_container v_;
139 };
140
141 template <class T>
142 bool operator==(const nasty_vector<T>& x, const nasty_vector<T>& y) { return x.v_ == y.v_; }
143
144 template <class T>
145 class nasty_list
146 {
147 public:
148
149     typedef typename std::list<T>                             nested_container;
150     typedef typename nested_container::value_type             value_type;
151     typedef typename nested_container::reference              reference;
152     typedef typename nested_container::const_reference        const_reference;
153     typedef typename nested_container::iterator               iterator;
154     typedef typename nested_container::const_iterator         const_iterator;
155
156     typedef typename nested_container::size_type              size_type;
157     typedef typename nested_container::difference_type        difference_type;
158     typedef typename nested_container::pointer                pointer;
159     typedef typename nested_container::const_pointer          const_pointer;
160
161     typedef typename nested_container::reverse_iterator       reverse_iterator;
162     typedef typename nested_container::const_reverse_iterator const_reverse_iterator;
163
164     nasty_list() : l_() {}
165     explicit nasty_list(size_type n)  : l_(n) {}
166     nasty_list(size_type n, const value_type& value)  : l_(n,value) {}
167     template <class Iter>
168         nasty_list(Iter first, Iter last)  : l_(first, last) {}
169 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
170     nasty_list(std::initializer_list<value_type> il) : l_(il) {}
171 #endif
172
173     ~nasty_list() {}
174
175 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
176     nasty_list& operator=(std::initializer_list<value_type> il) { l_ = il; return *this; }
177 #endif
178     template <class Iter>
179         void assign(Iter first, Iter last) { l_.assign(first, last); }
180     void assign(size_type n, const value_type& t) { l_.assign(n, t); }
181 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
182     void assign(std::initializer_list<value_type> il) { l_.assign(il); }
183 #endif
184
185
186     iterator               begin() TEST_NOEXCEPT         { return l_.begin(); }
187     const_iterator         begin()   const TEST_NOEXCEPT { return l_.begin(); }
188     iterator               end() TEST_NOEXCEPT           { return l_.end(); }
189     const_iterator         end()     const TEST_NOEXCEPT { return l_.end(); }
190
191     reverse_iterator       rbegin() TEST_NOEXCEPT        { return l_.rbegin(); }
192     const_reverse_iterator rbegin()  const TEST_NOEXCEPT { return l_.rbegin(); }
193     reverse_iterator       rend() TEST_NOEXCEPT          { return l_.rend(); }
194     const_reverse_iterator rend()    const TEST_NOEXCEPT { return l_.rend(); }
195
196     const_iterator         cbegin()  const TEST_NOEXCEPT { return l_.cbegin(); }
197     const_iterator         cend()    const TEST_NOEXCEPT { return l_.cend(); }
198     const_reverse_iterator crbegin() const TEST_NOEXCEPT { return l_.crbegin(); }
199     const_reverse_iterator crend()   const TEST_NOEXCEPT { return l_.crend(); }
200
201     reference       front()       { return l_.front(); }
202     const_reference front() const { return l_.front(); }
203     reference       back()        { return l_.back(); }
204     const_reference back() const  { return l_.back(); }
205
206     size_type size() const TEST_NOEXCEPT      { return l_.size(); }
207     size_type max_size() const TEST_NOEXCEPT  { return l_.max_size(); }
208     bool empty() const TEST_NOEXCEPT          { return l_.empty(); }
209
210     void push_front(const value_type& x)    { l_.push_front(x); }
211     void push_back(const value_type& x)     { l_.push_back(x); }
212 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
213     void push_back(value_type&& x)          { l_.push_back(std::forward<value_type&&>(x)); }
214     void push_front(value_type&& x)         { l_.push_back(std::forward<value_type&&>(x)); }
215 #ifndef _LIBCPP_HAS_NO_VARIADICS
216     template <class... Args>
217         void emplace_back(Args&&... args)   { l_.emplace_back(std::forward<Args>(args)...); }
218     template <class... Args>
219         void emplace_front(Args&&... args)  { l_.emplace_front(std::forward<Args>(args)...); }
220 #endif
221 #endif
222     void pop_front()                        { l_.pop_front(); }
223     void pop_back()                         { l_.pop_back(); }
224
225 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
226 #ifndef _LIBCPP_HAS_NO_VARIADICS
227     template <class... Args> iterator emplace(const_iterator pos, Args&&... args)
228     { return l_.emplace(pos, std::forward<Args>(args)...); }
229 #endif
230 #endif
231
232     iterator insert(const_iterator pos, const value_type& x) { return l_.insert(pos, x); }
233 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
234     iterator insert(const_iterator pos, value_type&& x)      { return l_.insert(pos, std::forward<value_type>(x)); }
235 #endif
236     iterator insert(const_iterator pos, size_type n, const value_type& x) { return l_.insert(pos, n, x); }
237     template <class InputIterator>
238         iterator insert(const_iterator pos, InputIterator first, InputIterator last)
239     { return l_.insert(pos, first, last); }
240
241 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
242     iterator insert(const_iterator pos, std::initializer_list<value_type> il) { return l_.insert(pos, il); }
243 #endif
244
245     iterator erase(const_iterator pos)                      { return l_.erase(pos); }
246     iterator erase(const_iterator pos, const_iterator last) { return l_.erase(pos, last); }
247
248     void resize(size_type)                      { l_.resize(); }
249     void resize(size_type, const value_type& c) { l_.resize(c); }
250
251     void swap(nasty_list &nl)
252 #if TEST_STD_VER > 14
253     noexcept(std::is_nothrow_swappable<nested_container>::value)
254 #elif defined(_LIBCPP_VERSION)
255     TEST_NOEXCEPT_COND(std::__is_nothrow_swappable<nested_container>::value)
256 #endif
257     { l_.swap(nl.l_); }
258
259     void clear() TEST_NOEXCEPT { l_.clear(); }
260
261 //     void splice(const_iterator position, list& x);
262 //     void splice(const_iterator position, list&& x);
263 //     void splice(const_iterator position, list& x, const_iterator i);
264 //     void splice(const_iterator position, list&& x, const_iterator i);
265 //     void splice(const_iterator position, list& x, const_iterator first,
266 //                                                   const_iterator last);
267 //     void splice(const_iterator position, list&& x, const_iterator first,
268 //                                                   const_iterator last);
269 //
270 //     void remove(const value_type& value);
271 //     template <class Pred> void remove_if(Pred pred);
272 //     void unique();
273 //     template <class BinaryPredicate>
274 //         void unique(BinaryPredicate binary_pred);
275 //     void merge(list& x);
276 //     void merge(list&& x);
277 //     template <class Compare>
278 //         void merge(list& x, Compare comp);
279 //     template <class Compare>
280 //         void merge(list&& x, Compare comp);
281 //     void sort();
282 //     template <class Compare>
283 //         void sort(Compare comp);
284 //     void reverse() noexcept;
285
286     nasty_list *operator &()             { assert(false); return nullptr; }  // nasty
287     const nasty_list *operator &() const { assert(false); return nullptr; }  // nasty
288
289     nested_container l_;
290 };
291
292 template <class T>
293 bool operator==(const nasty_list<T>& x, const nasty_list<T>& y) { return x.l_ == y.l_; }
294
295 // Not really a mutex, but can play one in tests
296 class nasty_mutex
297 {
298 public:
299      nasty_mutex() TEST_NOEXCEPT {}
300      ~nasty_mutex() {}
301
302         nasty_mutex *operator& ()   { assert(false); return nullptr; }
303         template <typename T>
304         void operator, (const T &) { assert(false); }
305
306 private:
307     nasty_mutex(const nasty_mutex&)            { assert(false); }
308     nasty_mutex& operator=(const nasty_mutex&) { assert(false); return *this; }
309
310 public:
311     void lock()               {}
312     bool try_lock() TEST_NOEXCEPT { return true; }
313     void unlock() TEST_NOEXCEPT   {}
314
315     // Shared ownership
316     void lock_shared()     {}
317     bool try_lock_shared() { return true; }
318     void unlock_shared()   {}
319 };
320
321 #endif