1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef NASTY_CONTAINERS_H
10 #define NASTY_CONTAINERS_H
16 #include "test_macros.h"
22 typedef typename
std::vector
<T
> nested_container
;
23 typedef typename
nested_container::value_type value_type
;
24 typedef typename
nested_container::reference reference
;
25 typedef typename
nested_container::const_reference const_reference
;
26 typedef typename
nested_container::iterator iterator
;
27 typedef typename
nested_container::const_iterator const_iterator
;
29 typedef typename
nested_container::size_type size_type
;
30 typedef typename
nested_container::difference_type difference_type
;
31 typedef typename
nested_container::pointer pointer
;
32 typedef typename
nested_container::const_pointer const_pointer
;
34 typedef typename
nested_container::reverse_iterator reverse_iterator
;
35 typedef typename
nested_container::const_reverse_iterator const_reverse_iterator
;
37 nasty_vector() : v_() {}
38 explicit nasty_vector(size_type n
) : v_(n
) {}
39 nasty_vector(size_type n
, const value_type
& value
) : v_(n
, value
) {}
40 template <class InputIterator
> nasty_vector(InputIterator first
, InputIterator last
) : v_(first
, last
) {}
41 #if TEST_STD_VER >= 11
42 nasty_vector(std::initializer_list
<value_type
> il
) : v_(il
) {}
46 template <class InputIterator
>
47 void assign(InputIterator first
, InputIterator last
) { v_
.assign(first
, last
); }
48 void assign(size_type n
, const value_type
& u
) { v_
.assign(n
, u
); }
49 #if TEST_STD_VER >= 11
50 void assign(std::initializer_list
<value_type
> il
) { v_
.assign(il
); }
53 iterator
begin() TEST_NOEXCEPT
{ return v_
.begin(); }
54 const_iterator
begin() const TEST_NOEXCEPT
{ return v_
.begin(); }
55 iterator
end() TEST_NOEXCEPT
{ return v_
.end(); }
56 const_iterator
end() const TEST_NOEXCEPT
{ return v_
.end(); }
58 reverse_iterator
rbegin() TEST_NOEXCEPT
{ return v_
.rbegin(); }
59 const_reverse_iterator
rbegin() const TEST_NOEXCEPT
{ return v_
.rbegin(); }
60 reverse_iterator
rend() TEST_NOEXCEPT
{ return v_
.rend(); }
61 const_reverse_iterator
rend() const TEST_NOEXCEPT
{ return v_
.rend(); }
63 const_iterator
cbegin() const TEST_NOEXCEPT
{ return v_
.cbegin(); }
64 const_iterator
cend() const TEST_NOEXCEPT
{ return v_
.cend(); }
65 const_reverse_iterator
crbegin() const TEST_NOEXCEPT
{ return v_
.crbegin(); }
66 const_reverse_iterator
crend() const TEST_NOEXCEPT
{ return v_
.crend(); }
68 size_type
size() const TEST_NOEXCEPT
{ return v_
.size(); }
69 size_type
max_size() const TEST_NOEXCEPT
{ return v_
.max_size(); }
70 size_type
capacity() const TEST_NOEXCEPT
{ return v_
.capacity(); }
71 bool empty() const TEST_NOEXCEPT
{ return v_
.empty(); }
72 void reserve(size_type n
) { v_
.reserve(n
); };
73 void shrink_to_fit() TEST_NOEXCEPT
{ v_
.shrink_to_fit(); }
75 reference
operator[](size_type n
) { return v_
[n
]; }
76 const_reference
operator[](size_type n
) const { return v_
[n
]; }
77 reference
at(size_type n
) { return v_
.at(n
); }
78 const_reference
at(size_type n
) const { return v_
.at(n
); }
80 reference
front() { return v_
.front(); }
81 const_reference
front() const { return v_
.front(); }
82 reference
back() { return v_
.back(); }
83 const_reference
back() const { return v_
.back(); }
85 value_type
* data() TEST_NOEXCEPT
{ return v_
.data(); }
86 const value_type
* data() const TEST_NOEXCEPT
{ return v_
.data(); }
88 void push_back(const value_type
& x
) { v_
.push_back(x
); }
89 #if TEST_STD_VER >= 11
90 void push_back(value_type
&& x
) { v_
.push_back(std::forward
<value_type
&&>(x
)); }
91 template <class... Args
>
92 void emplace_back(Args
&&... args
) { v_
.emplace_back(std::forward
<Args
>(args
)...); }
94 void pop_back() { v_
.pop_back(); }
96 #if TEST_STD_VER >= 11
97 template <class... Args
> iterator
emplace(const_iterator pos
, Args
&&... args
)
98 { return v_
.emplace(pos
, std::forward
<Args
>(args
)...); }
101 iterator
insert(const_iterator pos
, const value_type
& x
) { return v_
.insert(pos
, x
); }
102 #if TEST_STD_VER >= 11
103 iterator
insert(const_iterator pos
, value_type
&& x
) { return v_
.insert(pos
, std::forward
<value_type
>(x
)); }
105 iterator
insert(const_iterator pos
, size_type n
, const value_type
& x
) { return v_
.insert(pos
, n
, x
); }
106 template <class InputIterator
>
107 iterator
insert(const_iterator pos
, InputIterator first
, InputIterator last
)
108 { return v_
.insert(pos
, first
, last
); }
110 #if TEST_STD_VER >= 11
111 iterator
insert(const_iterator pos
, std::initializer_list
<value_type
> il
) { return v_
.insert(pos
, il
); }
114 iterator
erase(const_iterator pos
) { return v_
.erase(pos
); }
115 iterator
erase(const_iterator first
, const_iterator last
) { return v_
.erase(first
, last
); }
117 void clear() TEST_NOEXCEPT
{ v_
.clear(); }
119 void resize(size_type sz
) { v_
.resize(sz
); }
120 void resize(size_type sz
, const value_type
& c
) { v_
.resize(sz
, c
); }
122 void swap(nasty_vector
&nv
)
123 #if TEST_STD_VER > 14
124 noexcept(std::is_nothrow_swappable
<nested_container
>::value
)
125 #elif defined(_LIBCPP_VERSION)
126 TEST_NOEXCEPT_COND(std::__is_nothrow_swappable
<nested_container
>::value
)
130 nasty_vector
*operator &() { assert(false); return nullptr; } // nasty
131 const nasty_vector
*operator &() const { assert(false); return nullptr; } // nasty
137 bool operator==(const nasty_vector
<T
>& x
, const nasty_vector
<T
>& y
) { return x
.v_
== y
.v_
; }
144 typedef typename
std::list
<T
> nested_container
;
145 typedef typename
nested_container::value_type value_type
;
146 typedef typename
nested_container::reference reference
;
147 typedef typename
nested_container::const_reference const_reference
;
148 typedef typename
nested_container::iterator iterator
;
149 typedef typename
nested_container::const_iterator const_iterator
;
151 typedef typename
nested_container::size_type size_type
;
152 typedef typename
nested_container::difference_type difference_type
;
153 typedef typename
nested_container::pointer pointer
;
154 typedef typename
nested_container::const_pointer const_pointer
;
156 typedef typename
nested_container::reverse_iterator reverse_iterator
;
157 typedef typename
nested_container::const_reverse_iterator const_reverse_iterator
;
159 nasty_list() : l_() {}
160 explicit nasty_list(size_type n
) : l_(n
) {}
161 nasty_list(size_type n
, const value_type
& value
) : l_(n
,value
) {}
162 template <class Iter
>
163 nasty_list(Iter first
, Iter last
) : l_(first
, last
) {}
164 #if TEST_STD_VER >= 11
165 nasty_list(std::initializer_list
<value_type
> il
) : l_(il
) {}
170 #if TEST_STD_VER >= 11
171 nasty_list
& operator=(std::initializer_list
<value_type
> il
) { l_
= il
; return *this; }
173 template <class Iter
>
174 void assign(Iter first
, Iter last
) { l_
.assign(first
, last
); }
175 void assign(size_type n
, const value_type
& t
) { l_
.assign(n
, t
); }
176 #if TEST_STD_VER >= 11
177 void assign(std::initializer_list
<value_type
> il
) { l_
.assign(il
); }
181 iterator
begin() TEST_NOEXCEPT
{ return l_
.begin(); }
182 const_iterator
begin() const TEST_NOEXCEPT
{ return l_
.begin(); }
183 iterator
end() TEST_NOEXCEPT
{ return l_
.end(); }
184 const_iterator
end() const TEST_NOEXCEPT
{ return l_
.end(); }
186 reverse_iterator
rbegin() TEST_NOEXCEPT
{ return l_
.rbegin(); }
187 const_reverse_iterator
rbegin() const TEST_NOEXCEPT
{ return l_
.rbegin(); }
188 reverse_iterator
rend() TEST_NOEXCEPT
{ return l_
.rend(); }
189 const_reverse_iterator
rend() const TEST_NOEXCEPT
{ return l_
.rend(); }
191 const_iterator
cbegin() const TEST_NOEXCEPT
{ return l_
.cbegin(); }
192 const_iterator
cend() const TEST_NOEXCEPT
{ return l_
.cend(); }
193 const_reverse_iterator
crbegin() const TEST_NOEXCEPT
{ return l_
.crbegin(); }
194 const_reverse_iterator
crend() const TEST_NOEXCEPT
{ return l_
.crend(); }
196 reference
front() { return l_
.front(); }
197 const_reference
front() const { return l_
.front(); }
198 reference
back() { return l_
.back(); }
199 const_reference
back() const { return l_
.back(); }
201 size_type
size() const TEST_NOEXCEPT
{ return l_
.size(); }
202 size_type
max_size() const TEST_NOEXCEPT
{ return l_
.max_size(); }
203 bool empty() const TEST_NOEXCEPT
{ return l_
.empty(); }
205 void push_front(const value_type
& x
) { l_
.push_front(x
); }
206 void push_back(const value_type
& x
) { l_
.push_back(x
); }
207 #if TEST_STD_VER >= 11
208 void push_back(value_type
&& x
) { l_
.push_back(std::forward
<value_type
&&>(x
)); }
209 void push_front(value_type
&& x
) { l_
.push_back(std::forward
<value_type
&&>(x
)); }
210 template <class... Args
>
211 void emplace_back(Args
&&... args
) { l_
.emplace_back(std::forward
<Args
>(args
)...); }
212 template <class... Args
>
213 void emplace_front(Args
&&... args
) { l_
.emplace_front(std::forward
<Args
>(args
)...); }
215 void pop_front() { l_
.pop_front(); }
216 void pop_back() { l_
.pop_back(); }
218 #if TEST_STD_VER >= 11
219 template <class... Args
> iterator
emplace(const_iterator pos
, Args
&&... args
)
220 { return l_
.emplace(pos
, std::forward
<Args
>(args
)...); }
223 iterator
insert(const_iterator pos
, const value_type
& x
) { return l_
.insert(pos
, x
); }
224 #if TEST_STD_VER >= 11
225 iterator
insert(const_iterator pos
, value_type
&& x
) { return l_
.insert(pos
, std::forward
<value_type
>(x
)); }
227 iterator
insert(const_iterator pos
, size_type n
, const value_type
& x
) { return l_
.insert(pos
, n
, x
); }
228 template <class InputIterator
>
229 iterator
insert(const_iterator pos
, InputIterator first
, InputIterator last
)
230 { return l_
.insert(pos
, first
, last
); }
232 #if TEST_STD_VER >= 11
233 iterator
insert(const_iterator pos
, std::initializer_list
<value_type
> il
) { return l_
.insert(pos
, il
); }
236 iterator
erase(const_iterator pos
) { return l_
.erase(pos
); }
237 iterator
erase(const_iterator pos
, const_iterator last
) { return l_
.erase(pos
, last
); }
239 void resize(size_type
) { l_
.resize(); }
240 void resize(size_type
, const value_type
& c
) { l_
.resize(c
); }
242 void swap(nasty_list
&nl
)
243 #if TEST_STD_VER > 14
244 noexcept(std::is_nothrow_swappable
<nested_container
>::value
)
245 #elif defined(_LIBCPP_VERSION)
246 TEST_NOEXCEPT_COND(std::__is_nothrow_swappable
<nested_container
>::value
)
250 void clear() TEST_NOEXCEPT
{ l_
.clear(); }
252 // void splice(const_iterator position, list& x);
253 // void splice(const_iterator position, list&& x);
254 // void splice(const_iterator position, list& x, const_iterator i);
255 // void splice(const_iterator position, list&& x, const_iterator i);
256 // void splice(const_iterator position, list& x, const_iterator first,
257 // const_iterator last);
258 // void splice(const_iterator position, list&& x, const_iterator first,
259 // const_iterator last);
261 // void remove(const value_type& value);
262 // template <class Pred> void remove_if(Pred pred);
264 // template <class BinaryPredicate>
265 // void unique(BinaryPredicate binary_pred);
266 // void merge(list& x);
267 // void merge(list&& x);
268 // template <class Compare>
269 // void merge(list& x, Compare comp);
270 // template <class Compare>
271 // void merge(list&& x, Compare comp);
273 // template <class Compare>
274 // void sort(Compare comp);
275 // void reverse() noexcept;
277 nasty_list
*operator &() { assert(false); return nullptr; } // nasty
278 const nasty_list
*operator &() const { assert(false); return nullptr; } // nasty
284 bool operator==(const nasty_list
<T
>& x
, const nasty_list
<T
>& y
) { return x
.l_
== y
.l_
; }
286 // Not really a mutex, but can play one in tests
290 nasty_mutex() TEST_NOEXCEPT
{}
293 nasty_mutex
*operator& () { assert(false); return nullptr; }
294 template <typename T
>
295 void operator, (const T
&) { assert(false); }
298 nasty_mutex(const nasty_mutex
&) { assert(false); }
299 nasty_mutex
& operator=(const nasty_mutex
&) { assert(false); return *this; }
303 bool try_lock() TEST_NOEXCEPT
{ return true; }
304 void unlock() TEST_NOEXCEPT
{}
307 void lock_shared() {}
308 bool try_lock_shared() { return true; }
309 void unlock_shared() {}