1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef NASTY_CONTAINERS_H
11 #define NASTY_CONTAINERS_H
17 #include "test_macros.h"
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;
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;
35 typedef typename nested_container::reverse_iterator reverse_iterator;
36 typedef typename nested_container::const_reverse_iterator const_reverse_iterator;
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) {}
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); }
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(); }
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(); }
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(); }
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(); }
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); }
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(); }
86 value_type* data() TEST_NOEXCEPT { return v_.data(); }
87 const value_type* data() const TEST_NOEXCEPT { return v_.data(); }
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)...); }
97 void pop_back() { v_.pop_back(); }
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)...); }
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)); }
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); }
115 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
116 iterator insert(const_iterator pos, std::initializer_list<value_type> il) { return v_.insert(pos, il); }
119 iterator erase(const_iterator pos) { return v_.erase(pos); }
120 iterator erase(const_iterator first, const_iterator last) { return v_.erase(first, last); }
122 void clear() TEST_NOEXCEPT { v_.clear(); }
124 void resize(size_type sz) { v_.resize(sz); }
125 void resize(size_type sz, const value_type& c) { v_.resize(sz, c); }
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)
135 nasty_vector *operator &() { assert(false); return nullptr; } // nasty
136 const nasty_vector *operator &() const { assert(false); return nullptr; } // nasty
142 bool operator==(const nasty_vector<T>& x, const nasty_vector<T>& y) { return x.v_ == y.v_; }
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;
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;
161 typedef typename nested_container::reverse_iterator reverse_iterator;
162 typedef typename nested_container::const_reverse_iterator const_reverse_iterator;
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) {}
175 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
176 nasty_list& operator=(std::initializer_list<value_type> il) { l_ = il; return *this; }
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); }
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(); }
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(); }
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(); }
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(); }
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(); }
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)...); }
222 void pop_front() { l_.pop_front(); }
223 void pop_back() { l_.pop_back(); }
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)...); }
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)); }
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); }
241 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
242 iterator insert(const_iterator pos, std::initializer_list<value_type> il) { return l_.insert(pos, il); }
245 iterator erase(const_iterator pos) { return l_.erase(pos); }
246 iterator erase(const_iterator pos, const_iterator last) { return l_.erase(pos, last); }
248 void resize(size_type) { l_.resize(); }
249 void resize(size_type, const value_type& c) { l_.resize(c); }
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)
259 void clear() TEST_NOEXCEPT { l_.clear(); }
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);
270 // void remove(const value_type& value);
271 // template <class Pred> void remove_if(Pred pred);
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);
282 // template <class Compare>
283 // void sort(Compare comp);
284 // void reverse() noexcept;
286 nasty_list *operator &() { assert(false); return nullptr; } // nasty
287 const nasty_list *operator &() const { assert(false); return nullptr; } // nasty
293 bool operator==(const nasty_list<T>& x, const nasty_list<T>& y) { return x.l_ == y.l_; }
295 // Not really a mutex, but can play one in tests
299 nasty_mutex() TEST_NOEXCEPT {}
302 nasty_mutex *operator& () { assert(false); return nullptr; }
303 template <typename T>
304 void operator, (const T &) { assert(false); }
307 nasty_mutex(const nasty_mutex&) { assert(false); }
308 nasty_mutex& operator=(const nasty_mutex&) { assert(false); return *this; }
312 bool try_lock() TEST_NOEXCEPT { return true; }
313 void unlock() TEST_NOEXCEPT {}
316 void lock_shared() {}
317 bool try_lock_shared() { return true; }
318 void unlock_shared() {}