blob: b52263a97b4e25176143b2d0f56f9537fefd79cb [file] [log] [blame]
Marshall Clow53c0e722014-03-03 19:20:40 +00001//===----------------------------------------------------------------------===//
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
Marshall Clowd124b5b2016-03-14 23:07:58 +000010#ifndef NASTY_CONTAINERS_H
11#define NASTY_CONTAINERS_H
Marshall Clow53c0e722014-03-03 19:20:40 +000012
Marshall Clowd124b5b2016-03-14 23:07:58 +000013#include <cassert>
Marshall Clow53c0e722014-03-03 19:20:40 +000014#include <vector>
15#include <list>
16
Eric Fiselier159b45f2016-10-12 09:31:26 +000017#include "test_macros.h"
18
Marshall Clow53c0e722014-03-03 19:20:40 +000019template <class T>
20class nasty_vector
21{
22public:
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) {}
Eric Fiselier869c5ad2017-04-19 01:02:49 +000042#if TEST_STD_VER >= 11
Marshall Clow53c0e722014-03-03 19:20:40 +000043 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); }
Eric Fiselier869c5ad2017-04-19 01:02:49 +000050#if TEST_STD_VER >= 11
Marshall Clow53c0e722014-03-03 19:20:40 +000051 void assign(std::initializer_list<value_type> il) { v_.assign(il); }
52#endif
53
Eric Fiselier159b45f2016-10-12 09:31:26 +000054 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(); }
Marshall Clow53c0e722014-03-03 19:20:40 +000058
Eric Fiselier159b45f2016-10-12 09:31:26 +000059 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(); }
Marshall Clow53c0e722014-03-03 19:20:40 +000063
Eric Fiselier159b45f2016-10-12 09:31:26 +000064 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(); }
Marshall Clow53c0e722014-03-03 19:20:40 +000068
Eric Fiselier159b45f2016-10-12 09:31:26 +000069 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(); }
Marshall Clow53c0e722014-03-03 19:20:40 +000073 void reserve(size_type n) { v_.reserve(n); };
Eric Fiselier159b45f2016-10-12 09:31:26 +000074 void shrink_to_fit() TEST_NOEXCEPT { v_.shrink_to_fit(); }
Marshall Clow53c0e722014-03-03 19:20:40 +000075
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
Eric Fiselier159b45f2016-10-12 09:31:26 +000086 value_type* data() TEST_NOEXCEPT { return v_.data(); }
87 const value_type* data() const TEST_NOEXCEPT { return v_.data(); }
Marshall Clow53c0e722014-03-03 19:20:40 +000088
89 void push_back(const value_type& x) { v_.push_back(x); }
Eric Fiselier869c5ad2017-04-19 01:02:49 +000090#if TEST_STD_VER >= 11
Marshall Clow53c0e722014-03-03 19:20:40 +000091 void push_back(value_type&& x) { v_.push_back(std::forward<value_type&&>(x)); }
Marshall Clow53c0e722014-03-03 19:20:40 +000092 template <class... Args>
93 void emplace_back(Args&&... args) { v_.emplace_back(std::forward<Args>(args)...); }
94#endif
Marshall Clow53c0e722014-03-03 19:20:40 +000095 void pop_back() { v_.pop_back(); }
96
Eric Fiselier869c5ad2017-04-19 01:02:49 +000097#if TEST_STD_VER >= 11
Marshall Clow53c0e722014-03-03 19:20:40 +000098 template <class... Args> iterator emplace(const_iterator pos, Args&&... args)
99 { return v_.emplace(pos, std::forward<Args>(args)...); }
100#endif
Eric Fiselier84acb1e2016-06-01 21:35:39 +0000101
Marshall Clow53c0e722014-03-03 19:20:40 +0000102 iterator insert(const_iterator pos, const value_type& x) { return v_.insert(pos, x); }
Eric Fiselier869c5ad2017-04-19 01:02:49 +0000103#if TEST_STD_VER >= 11
Marshall Clow53c0e722014-03-03 19:20:40 +0000104 iterator insert(const_iterator pos, value_type&& x) { return v_.insert(pos, std::forward<value_type>(x)); }
105#endif
106 iterator insert(const_iterator pos, size_type n, const value_type& x) { return v_.insert(pos, n, x); }
107 template <class InputIterator>
108 iterator insert(const_iterator pos, InputIterator first, InputIterator last)
109 { return v_.insert(pos, first, last); }
110
Eric Fiselier869c5ad2017-04-19 01:02:49 +0000111#if TEST_STD_VER >= 11
Marshall Clow53c0e722014-03-03 19:20:40 +0000112 iterator insert(const_iterator pos, std::initializer_list<value_type> il) { return v_.insert(pos, il); }
113#endif
114
115 iterator erase(const_iterator pos) { return v_.erase(pos); }
116 iterator erase(const_iterator first, const_iterator last) { return v_.erase(first, last); }
117
Eric Fiselier159b45f2016-10-12 09:31:26 +0000118 void clear() TEST_NOEXCEPT { v_.clear(); }
Marshall Clow53c0e722014-03-03 19:20:40 +0000119
120 void resize(size_type sz) { v_.resize(sz); }
121 void resize(size_type sz, const value_type& c) { v_.resize(sz, c); }
122
Eric Fiselier159b45f2016-10-12 09:31:26 +0000123 void swap(nasty_vector &nv)
124#if TEST_STD_VER > 14
125 noexcept(std::is_nothrow_swappable<nested_container>::value)
126#elif defined(_LIBCPP_VERSION)
127 TEST_NOEXCEPT_COND(std::__is_nothrow_swappable<nested_container>::value)
128#endif
Marshall Clow53c0e722014-03-03 19:20:40 +0000129 { v_.swap(nv.v_); }
Eric Fiselier84acb1e2016-06-01 21:35:39 +0000130
Marshall Clowd124b5b2016-03-14 23:07:58 +0000131 nasty_vector *operator &() { assert(false); return nullptr; } // nasty
132 const nasty_vector *operator &() const { assert(false); return nullptr; } // nasty
Eric Fiselier84acb1e2016-06-01 21:35:39 +0000133
Marshall Clow53c0e722014-03-03 19:20:40 +0000134 nested_container v_;
135};
136
137template <class T>
138bool operator==(const nasty_vector<T>& x, const nasty_vector<T>& y) { return x.v_ == y.v_; }
139
140template <class T>
141class nasty_list
142{
143public:
144
145 typedef typename std::list<T> nested_container;
146 typedef typename nested_container::value_type value_type;
147 typedef typename nested_container::reference reference;
148 typedef typename nested_container::const_reference const_reference;
149 typedef typename nested_container::iterator iterator;
150 typedef typename nested_container::const_iterator const_iterator;
151
152 typedef typename nested_container::size_type size_type;
153 typedef typename nested_container::difference_type difference_type;
154 typedef typename nested_container::pointer pointer;
155 typedef typename nested_container::const_pointer const_pointer;
156
157 typedef typename nested_container::reverse_iterator reverse_iterator;
158 typedef typename nested_container::const_reverse_iterator const_reverse_iterator;
159
160 nasty_list() : l_() {}
161 explicit nasty_list(size_type n) : l_(n) {}
162 nasty_list(size_type n, const value_type& value) : l_(n,value) {}
163 template <class Iter>
164 nasty_list(Iter first, Iter last) : l_(first, last) {}
Eric Fiselier869c5ad2017-04-19 01:02:49 +0000165#if TEST_STD_VER >= 11
Marshall Clow53c0e722014-03-03 19:20:40 +0000166 nasty_list(std::initializer_list<value_type> il) : l_(il) {}
167#endif
168
169 ~nasty_list() {}
170
Eric Fiselier869c5ad2017-04-19 01:02:49 +0000171#if TEST_STD_VER >= 11
Marshall Clow53c0e722014-03-03 19:20:40 +0000172 nasty_list& operator=(std::initializer_list<value_type> il) { l_ = il; return *this; }
173#endif
174 template <class Iter>
175 void assign(Iter first, Iter last) { l_.assign(first, last); }
176 void assign(size_type n, const value_type& t) { l_.assign(n, t); }
Eric Fiselier869c5ad2017-04-19 01:02:49 +0000177#if TEST_STD_VER >= 11
Marshall Clow53c0e722014-03-03 19:20:40 +0000178 void assign(std::initializer_list<value_type> il) { l_.assign(il); }
179#endif
180
181
Eric Fiselier159b45f2016-10-12 09:31:26 +0000182 iterator begin() TEST_NOEXCEPT { return l_.begin(); }
183 const_iterator begin() const TEST_NOEXCEPT { return l_.begin(); }
184 iterator end() TEST_NOEXCEPT { return l_.end(); }
185 const_iterator end() const TEST_NOEXCEPT { return l_.end(); }
Marshall Clow53c0e722014-03-03 19:20:40 +0000186
Eric Fiselier159b45f2016-10-12 09:31:26 +0000187 reverse_iterator rbegin() TEST_NOEXCEPT { return l_.rbegin(); }
188 const_reverse_iterator rbegin() const TEST_NOEXCEPT { return l_.rbegin(); }
189 reverse_iterator rend() TEST_NOEXCEPT { return l_.rend(); }
190 const_reverse_iterator rend() const TEST_NOEXCEPT { return l_.rend(); }
Marshall Clow53c0e722014-03-03 19:20:40 +0000191
Eric Fiselier159b45f2016-10-12 09:31:26 +0000192 const_iterator cbegin() const TEST_NOEXCEPT { return l_.cbegin(); }
193 const_iterator cend() const TEST_NOEXCEPT { return l_.cend(); }
194 const_reverse_iterator crbegin() const TEST_NOEXCEPT { return l_.crbegin(); }
195 const_reverse_iterator crend() const TEST_NOEXCEPT { return l_.crend(); }
Marshall Clow53c0e722014-03-03 19:20:40 +0000196
197 reference front() { return l_.front(); }
198 const_reference front() const { return l_.front(); }
199 reference back() { return l_.back(); }
200 const_reference back() const { return l_.back(); }
201
Eric Fiselier159b45f2016-10-12 09:31:26 +0000202 size_type size() const TEST_NOEXCEPT { return l_.size(); }
203 size_type max_size() const TEST_NOEXCEPT { return l_.max_size(); }
204 bool empty() const TEST_NOEXCEPT { return l_.empty(); }
Marshall Clow53c0e722014-03-03 19:20:40 +0000205
206 void push_front(const value_type& x) { l_.push_front(x); }
207 void push_back(const value_type& x) { l_.push_back(x); }
Eric Fiselier869c5ad2017-04-19 01:02:49 +0000208#if TEST_STD_VER >= 11
Marshall Clow53c0e722014-03-03 19:20:40 +0000209 void push_back(value_type&& x) { l_.push_back(std::forward<value_type&&>(x)); }
210 void push_front(value_type&& x) { l_.push_back(std::forward<value_type&&>(x)); }
Marshall Clow53c0e722014-03-03 19:20:40 +0000211 template <class... Args>
212 void emplace_back(Args&&... args) { l_.emplace_back(std::forward<Args>(args)...); }
213 template <class... Args>
214 void emplace_front(Args&&... args) { l_.emplace_front(std::forward<Args>(args)...); }
215#endif
Marshall Clow53c0e722014-03-03 19:20:40 +0000216 void pop_front() { l_.pop_front(); }
217 void pop_back() { l_.pop_back(); }
218
Eric Fiselier869c5ad2017-04-19 01:02:49 +0000219#if TEST_STD_VER >= 11
Marshall Clow53c0e722014-03-03 19:20:40 +0000220 template <class... Args> iterator emplace(const_iterator pos, Args&&... args)
221 { return l_.emplace(pos, std::forward<Args>(args)...); }
222#endif
Eric Fiselier84acb1e2016-06-01 21:35:39 +0000223
Marshall Clow53c0e722014-03-03 19:20:40 +0000224 iterator insert(const_iterator pos, const value_type& x) { return l_.insert(pos, x); }
Eric Fiselier869c5ad2017-04-19 01:02:49 +0000225#if TEST_STD_VER >= 11
Marshall Clow53c0e722014-03-03 19:20:40 +0000226 iterator insert(const_iterator pos, value_type&& x) { return l_.insert(pos, std::forward<value_type>(x)); }
227#endif
228 iterator insert(const_iterator pos, size_type n, const value_type& x) { return l_.insert(pos, n, x); }
229 template <class InputIterator>
230 iterator insert(const_iterator pos, InputIterator first, InputIterator last)
231 { return l_.insert(pos, first, last); }
232
Eric Fiselier869c5ad2017-04-19 01:02:49 +0000233#if TEST_STD_VER >= 11
Marshall Clow53c0e722014-03-03 19:20:40 +0000234 iterator insert(const_iterator pos, std::initializer_list<value_type> il) { return l_.insert(pos, il); }
235#endif
236
237 iterator erase(const_iterator pos) { return l_.erase(pos); }
238 iterator erase(const_iterator pos, const_iterator last) { return l_.erase(pos, last); }
239
Eric Fiselier0e5ebbc2016-12-23 23:37:52 +0000240 void resize(size_type) { l_.resize(); }
241 void resize(size_type, const value_type& c) { l_.resize(c); }
Marshall Clow53c0e722014-03-03 19:20:40 +0000242
Eric Fiselier159b45f2016-10-12 09:31:26 +0000243 void swap(nasty_list &nl)
244#if TEST_STD_VER > 14
245 noexcept(std::is_nothrow_swappable<nested_container>::value)
246#elif defined(_LIBCPP_VERSION)
247 TEST_NOEXCEPT_COND(std::__is_nothrow_swappable<nested_container>::value)
248#endif
Marshall Clow53c0e722014-03-03 19:20:40 +0000249 { l_.swap(nl.l_); }
Eric Fiselier84acb1e2016-06-01 21:35:39 +0000250
Eric Fiselier159b45f2016-10-12 09:31:26 +0000251 void clear() TEST_NOEXCEPT { l_.clear(); }
Marshall Clow53c0e722014-03-03 19:20:40 +0000252
253// void splice(const_iterator position, list& x);
254// void splice(const_iterator position, list&& x);
255// void splice(const_iterator position, list& x, const_iterator i);
256// void splice(const_iterator position, list&& x, const_iterator i);
257// void splice(const_iterator position, list& x, const_iterator first,
258// const_iterator last);
259// void splice(const_iterator position, list&& x, const_iterator first,
260// const_iterator last);
Eric Fiselier84acb1e2016-06-01 21:35:39 +0000261//
Marshall Clow53c0e722014-03-03 19:20:40 +0000262// void remove(const value_type& value);
263// template <class Pred> void remove_if(Pred pred);
264// void unique();
265// template <class BinaryPredicate>
266// void unique(BinaryPredicate binary_pred);
267// void merge(list& x);
268// void merge(list&& x);
269// template <class Compare>
270// void merge(list& x, Compare comp);
271// template <class Compare>
272// void merge(list&& x, Compare comp);
273// void sort();
274// template <class Compare>
275// void sort(Compare comp);
276// void reverse() noexcept;
277
Marshall Clowd124b5b2016-03-14 23:07:58 +0000278 nasty_list *operator &() { assert(false); return nullptr; } // nasty
279 const nasty_list *operator &() const { assert(false); return nullptr; } // nasty
Marshall Clow53c0e722014-03-03 19:20:40 +0000280
281 nested_container l_;
282};
283
284template <class T>
285bool operator==(const nasty_list<T>& x, const nasty_list<T>& y) { return x.l_ == y.l_; }
286
Marshall Clowd124b5b2016-03-14 23:07:58 +0000287// Not really a mutex, but can play one in tests
288class nasty_mutex
289{
290public:
Eric Fiselier159b45f2016-10-12 09:31:26 +0000291 nasty_mutex() TEST_NOEXCEPT {}
Marshall Clowd124b5b2016-03-14 23:07:58 +0000292 ~nasty_mutex() {}
293
Stephan T. Lavaveja686caa2017-07-29 00:55:10 +0000294 nasty_mutex *operator& () { assert(false); return nullptr; }
295 template <typename T>
296 void operator, (const T &) { assert(false); }
Marshall Clowd124b5b2016-03-14 23:07:58 +0000297
298private:
299 nasty_mutex(const nasty_mutex&) { assert(false); }
300 nasty_mutex& operator=(const nasty_mutex&) { assert(false); return *this; }
301
302public:
303 void lock() {}
Eric Fiselier159b45f2016-10-12 09:31:26 +0000304 bool try_lock() TEST_NOEXCEPT { return true; }
305 void unlock() TEST_NOEXCEPT {}
Marshall Clowd124b5b2016-03-14 23:07:58 +0000306
307 // Shared ownership
308 void lock_shared() {}
309 bool try_lock_shared() { return true; }
310 void unlock_shared() {}
311};
312
Marshall Clow53c0e722014-03-03 19:20:40 +0000313#endif