[AMDGPU] Mark AGPR tuple implicit in the first instr of AGPR spills. (#115285)
[llvm-project.git] / libcxx / test / support / nasty_containers.h
blob34027f0127eaf6f646556964084b14d06bfed067
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #ifndef NASTY_CONTAINERS_H
10 #define NASTY_CONTAINERS_H
12 #include <cassert>
13 #include <cstddef>
14 #include <vector>
15 #include <list>
16 #include <type_traits>
18 #include "test_macros.h"
20 template <class T>
21 class nasty_vector
23 public:
24 typedef typename std::vector<T> nested_container;
25 typedef typename nested_container::value_type value_type;
26 typedef typename nested_container::reference reference;
27 typedef typename nested_container::const_reference const_reference;
28 typedef typename nested_container::iterator iterator;
29 typedef typename nested_container::const_iterator const_iterator;
31 typedef typename nested_container::size_type size_type;
32 typedef typename nested_container::difference_type difference_type;
33 typedef typename nested_container::pointer pointer;
34 typedef typename nested_container::const_pointer const_pointer;
36 typedef typename nested_container::reverse_iterator reverse_iterator;
37 typedef typename nested_container::const_reverse_iterator const_reverse_iterator;
39 nasty_vector() : v_() {}
40 explicit nasty_vector(size_type n) : v_(n) {}
41 nasty_vector(size_type n, const value_type& value) : v_(n, value) {}
42 template <class InputIterator> nasty_vector(InputIterator first, InputIterator last) : v_(first, last) {}
43 #if TEST_STD_VER >= 11
44 nasty_vector(std::initializer_list<value_type> il) : v_(il) {}
45 #endif
46 nasty_vector(const nasty_vector&) = default;
47 nasty_vector& operator=(const nasty_vector&) = default;
48 ~nasty_vector() {}
50 template <class InputIterator>
51 void assign(InputIterator first, InputIterator last) { v_.assign(first, last); }
52 void assign(size_type n, const value_type& u) { v_.assign(n, u); }
53 #if TEST_STD_VER >= 11
54 void assign(std::initializer_list<value_type> il) { v_.assign(il); }
55 #endif
57 iterator begin() TEST_NOEXCEPT { return v_.begin(); }
58 const_iterator begin() const TEST_NOEXCEPT { return v_.begin(); }
59 iterator end() TEST_NOEXCEPT { return v_.end(); }
60 const_iterator end() const TEST_NOEXCEPT { return v_.end(); }
62 reverse_iterator rbegin() TEST_NOEXCEPT { return v_.rbegin(); }
63 const_reverse_iterator rbegin() const TEST_NOEXCEPT { return v_.rbegin(); }
64 reverse_iterator rend() TEST_NOEXCEPT { return v_.rend(); }
65 const_reverse_iterator rend() const TEST_NOEXCEPT { return v_.rend(); }
67 const_iterator cbegin() const TEST_NOEXCEPT { return v_.cbegin(); }
68 const_iterator cend() const TEST_NOEXCEPT { return v_.cend(); }
69 const_reverse_iterator crbegin() const TEST_NOEXCEPT { return v_.crbegin(); }
70 const_reverse_iterator crend() const TEST_NOEXCEPT { return v_.crend(); }
72 size_type size() const TEST_NOEXCEPT { return v_.size(); }
73 size_type max_size() const TEST_NOEXCEPT { return v_.max_size(); }
74 size_type capacity() const TEST_NOEXCEPT { return v_.capacity(); }
75 bool empty() const TEST_NOEXCEPT { return v_.empty(); }
76 void reserve(size_type n) { v_.reserve(n); };
77 void shrink_to_fit() TEST_NOEXCEPT { v_.shrink_to_fit(); }
79 reference operator[](size_type n) { return v_[n]; }
80 const_reference operator[](size_type n) const { return v_[n]; }
81 reference at(size_type n) { return v_.at(n); }
82 const_reference at(size_type n) const { return v_.at(n); }
84 reference front() { return v_.front(); }
85 const_reference front() const { return v_.front(); }
86 reference back() { return v_.back(); }
87 const_reference back() const { return v_.back(); }
89 value_type* data() TEST_NOEXCEPT { return v_.data(); }
90 const value_type* data() const TEST_NOEXCEPT { return v_.data(); }
92 void push_back(const value_type& x) { v_.push_back(x); }
93 #if TEST_STD_VER >= 11
94 void push_back(value_type&& x) { v_.push_back(std::forward<value_type&&>(x)); }
95 template <class... Args>
96 void emplace_back(Args&&... args) { v_.emplace_back(std::forward<Args>(args)...); }
97 #endif
98 void pop_back() { v_.pop_back(); }
100 #if TEST_STD_VER >= 11
101 template <class... Args> iterator emplace(const_iterator pos, Args&&... args)
102 { return v_.emplace(pos, std::forward<Args>(args)...); }
103 #endif
105 iterator insert(const_iterator pos, const value_type& x) { return v_.insert(pos, x); }
106 #if TEST_STD_VER >= 11
107 iterator insert(const_iterator pos, value_type&& x) { return v_.insert(pos, std::forward<value_type>(x)); }
108 #endif
109 iterator insert(const_iterator pos, size_type n, const value_type& x) { return v_.insert(pos, n, x); }
110 template <class InputIterator>
111 iterator insert(const_iterator pos, InputIterator first, InputIterator last)
112 { return v_.insert(pos, first, last); }
114 #if TEST_STD_VER >= 11
115 iterator insert(const_iterator pos, std::initializer_list<value_type> il) { return v_.insert(pos, il); }
116 #endif
118 iterator erase(const_iterator pos) { return v_.erase(pos); }
119 iterator erase(const_iterator first, const_iterator last) { return v_.erase(first, last); }
121 void clear() TEST_NOEXCEPT { v_.clear(); }
123 void resize(size_type sz) { v_.resize(sz); }
124 void resize(size_type sz, const value_type& c) { v_.resize(sz, c); }
126 void swap(nasty_vector& nv)
127 #if TEST_STD_VER > 14
128 noexcept(std::is_nothrow_swappable<nested_container>::value)
129 #elif defined(_LIBCPP_VERSION)
130 TEST_NOEXCEPT_COND(std::__is_nothrow_swappable_v<nested_container>)
131 #endif
133 v_.swap(nv.v_);
136 nasty_vector *operator &() { assert(false); return nullptr; } // nasty
137 const nasty_vector *operator &() const { assert(false); return nullptr; } // nasty
139 nested_container v_;
142 template <class T>
143 bool operator==(const nasty_vector<T>& x, const nasty_vector<T>& y) { return x.v_ == y.v_; }
146 #if TEST_STD_VER >= 20
148 template <class T>
149 auto operator<=>(const nasty_vector<T>& x, const nasty_vector<T>& y) { return x.v_ <=> y.v_; }
151 #endif
153 template <class T>
154 class nasty_list
156 public:
158 typedef typename std::list<T> nested_container;
159 typedef typename nested_container::value_type value_type;
160 typedef typename nested_container::reference reference;
161 typedef typename nested_container::const_reference const_reference;
162 typedef typename nested_container::iterator iterator;
163 typedef typename nested_container::const_iterator const_iterator;
165 typedef typename nested_container::size_type size_type;
166 typedef typename nested_container::difference_type difference_type;
167 typedef typename nested_container::pointer pointer;
168 typedef typename nested_container::const_pointer const_pointer;
170 typedef typename nested_container::reverse_iterator reverse_iterator;
171 typedef typename nested_container::const_reverse_iterator const_reverse_iterator;
173 nasty_list() : l_() {}
174 explicit nasty_list(size_type n) : l_(n) {}
175 nasty_list(size_type n, const value_type& value) : l_(n,value) {}
176 template <class Iter>
177 nasty_list(Iter first, Iter last) : l_(first, last) {}
178 #if TEST_STD_VER >= 11
179 nasty_list(std::initializer_list<value_type> il) : l_(il) {}
180 #endif
181 nasty_list(const nasty_list&) = default;
182 nasty_list& operator=(const nasty_list&) = default;
183 ~nasty_list() {}
185 #if TEST_STD_VER >= 11
186 nasty_list& operator=(std::initializer_list<value_type> il) { l_ = il; return *this; }
187 #endif
188 template <class Iter>
189 void assign(Iter first, Iter last) { l_.assign(first, last); }
190 void assign(size_type n, const value_type& t) { l_.assign(n, t); }
191 #if TEST_STD_VER >= 11
192 void assign(std::initializer_list<value_type> il) { l_.assign(il); }
193 #endif
196 iterator begin() TEST_NOEXCEPT { return l_.begin(); }
197 const_iterator begin() const TEST_NOEXCEPT { return l_.begin(); }
198 iterator end() TEST_NOEXCEPT { return l_.end(); }
199 const_iterator end() const TEST_NOEXCEPT { return l_.end(); }
201 reverse_iterator rbegin() TEST_NOEXCEPT { return l_.rbegin(); }
202 const_reverse_iterator rbegin() const TEST_NOEXCEPT { return l_.rbegin(); }
203 reverse_iterator rend() TEST_NOEXCEPT { return l_.rend(); }
204 const_reverse_iterator rend() const TEST_NOEXCEPT { return l_.rend(); }
206 const_iterator cbegin() const TEST_NOEXCEPT { return l_.cbegin(); }
207 const_iterator cend() const TEST_NOEXCEPT { return l_.cend(); }
208 const_reverse_iterator crbegin() const TEST_NOEXCEPT { return l_.crbegin(); }
209 const_reverse_iterator crend() const TEST_NOEXCEPT { return l_.crend(); }
211 reference front() { return l_.front(); }
212 const_reference front() const { return l_.front(); }
213 reference back() { return l_.back(); }
214 const_reference back() const { return l_.back(); }
216 size_type size() const TEST_NOEXCEPT { return l_.size(); }
217 size_type max_size() const TEST_NOEXCEPT { return l_.max_size(); }
218 bool empty() const TEST_NOEXCEPT { return l_.empty(); }
220 void push_front(const value_type& x) { l_.push_front(x); }
221 void push_back(const value_type& x) { l_.push_back(x); }
222 #if TEST_STD_VER >= 11
223 void push_back(value_type&& x) { l_.push_back(std::forward<value_type&&>(x)); }
224 void push_front(value_type&& x) { l_.push_front(std::forward<value_type&&>(x)); }
225 template <class... Args>
226 void emplace_back(Args&&... args) { l_.emplace_back(std::forward<Args>(args)...); }
227 template <class... Args>
228 void emplace_front(Args&&... args) { l_.emplace_front(std::forward<Args>(args)...); }
229 #endif
230 void pop_front() { l_.pop_front(); }
231 void pop_back() { l_.pop_back(); }
233 #if TEST_STD_VER >= 11
234 template <class... Args> iterator emplace(const_iterator pos, Args&&... args)
235 { return l_.emplace(pos, std::forward<Args>(args)...); }
236 #endif
238 iterator insert(const_iterator pos, const value_type& x) { return l_.insert(pos, x); }
239 #if TEST_STD_VER >= 11
240 iterator insert(const_iterator pos, value_type&& x) { return l_.insert(pos, std::forward<value_type>(x)); }
241 #endif
242 iterator insert(const_iterator pos, size_type n, const value_type& x) { return l_.insert(pos, n, x); }
243 template <class InputIterator>
244 iterator insert(const_iterator pos, InputIterator first, InputIterator last)
245 { return l_.insert(pos, first, last); }
247 #if TEST_STD_VER >= 11
248 iterator insert(const_iterator pos, std::initializer_list<value_type> il) { return l_.insert(pos, il); }
249 #endif
251 iterator erase(const_iterator pos) { return l_.erase(pos); }
252 iterator erase(const_iterator first, const_iterator last) { return l_.erase(first, last); }
254 void resize(size_type n) { l_.resize(n); }
255 void resize(size_type n, const value_type& c) { l_.resize(n, c); }
257 void swap(nasty_list& nl)
258 #if TEST_STD_VER > 14
259 noexcept(std::is_nothrow_swappable<nested_container>::value)
260 #elif defined(_LIBCPP_VERSION)
261 TEST_NOEXCEPT_COND(std::__is_nothrow_swappable_v<nested_container>)
262 #endif
264 l_.swap(nl.l_);
267 void clear() TEST_NOEXCEPT { l_.clear(); }
269 // void splice(const_iterator position, list& x);
270 // void splice(const_iterator position, list&& x);
271 // void splice(const_iterator position, list& x, const_iterator i);
272 // void splice(const_iterator position, list&& x, const_iterator i);
273 // void splice(const_iterator position, list& x, const_iterator first,
274 // const_iterator last);
275 // void splice(const_iterator position, list&& x, const_iterator first,
276 // const_iterator last);
278 // void remove(const value_type& value);
279 // template <class Pred> void remove_if(Pred pred);
280 // void unique();
281 // template <class BinaryPredicate>
282 // void unique(BinaryPredicate binary_pred);
283 // void merge(list& x);
284 // void merge(list&& x);
285 // template <class Compare>
286 // void merge(list& x, Compare comp);
287 // template <class Compare>
288 // void merge(list&& x, Compare comp);
289 // void sort();
290 // template <class Compare>
291 // void sort(Compare comp);
292 // void reverse() noexcept;
294 nasty_list *operator &() { assert(false); return nullptr; } // nasty
295 const nasty_list *operator &() const { assert(false); return nullptr; } // nasty
297 nested_container l_;
300 template <class T>
301 bool operator==(const nasty_list<T>& x, const nasty_list<T>& y) { return x.l_ == y.l_; }
303 #if TEST_STD_VER >= 20
305 template <class T>
306 auto operator<=>(const nasty_list<T>& x, const nasty_list<T>& y) { return x.l_ <=> y.l_; }
308 #endif
310 // Not really a mutex, but can play one in tests
311 class nasty_mutex
313 public:
314 nasty_mutex() TEST_NOEXCEPT {}
315 ~nasty_mutex() {}
317 nasty_mutex *operator& () { assert(false); return nullptr; }
318 template <typename T>
319 void operator, (const T &) { assert(false); }
321 private:
322 nasty_mutex(const nasty_mutex&) { assert(false); }
323 nasty_mutex& operator=(const nasty_mutex&) { assert(false); return *this; }
325 public:
326 void lock() {}
327 bool try_lock() TEST_NOEXCEPT { return true; }
328 void unlock() TEST_NOEXCEPT {}
330 // Shared ownership
331 void lock_shared() {}
332 bool try_lock_shared() { return true; }
333 void unlock_shared() {}
336 #endif