blob: a0155f0b275882d4319164ed29b9d5b14429e2fb [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===---------------------------- set -------------------------------------===//
3//
Howard Hinnantc566dc32010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantc51e1022010-05-11 19:42:16 +00005//
Howard Hinnantee11c312010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantc51e1022010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_SET
12#define _LIBCPP_SET
13
14/*
15
16 set synopsis
17
18namespace std
19{
20
21template <class Key, class Compare = less<Key>,
22 class Allocator = allocator<Key>>
23class set
24{
25public:
26 // types:
27 typedef Key key_type;
28 typedef key_type value_type;
29 typedef Compare key_compare;
30 typedef key_compare value_compare;
31 typedef Allocator allocator_type;
32 typedef typename allocator_type::reference reference;
33 typedef typename allocator_type::const_reference const_reference;
34 typedef typename allocator_type::size_type size_type;
35 typedef typename allocator_type::difference_type difference_type;
36 typedef typename allocator_type::pointer pointer;
37 typedef typename allocator_type::const_pointer const_pointer;
38
39 typedef implementation-defined iterator;
40 typedef implementation-defined const_iterator;
41 typedef std::reverse_iterator<iterator> reverse_iterator;
42 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +000043 typedef unspecified node_type; // C++17
44 typedef INSERT_RETURN_TYPE<iterator, node_type> insert_return_type; // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +000045
46 // construct/copy/destroy:
Howard Hinnantf95f4f52011-06-04 15:22:34 +000047 set()
48 noexcept(
49 is_nothrow_default_constructible<allocator_type>::value &&
50 is_nothrow_default_constructible<key_compare>::value &&
51 is_nothrow_copy_constructible<key_compare>::value);
52 explicit set(const value_compare& comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +000053 set(const value_compare& comp, const allocator_type& a);
54 template <class InputIterator>
55 set(InputIterator first, InputIterator last,
56 const value_compare& comp = value_compare());
57 template <class InputIterator>
58 set(InputIterator first, InputIterator last, const value_compare& comp,
59 const allocator_type& a);
60 set(const set& s);
Howard Hinnantf95f4f52011-06-04 15:22:34 +000061 set(set&& s)
62 noexcept(
63 is_nothrow_move_constructible<allocator_type>::value &&
64 is_nothrow_move_constructible<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +000065 explicit set(const allocator_type& a);
66 set(const set& s, const allocator_type& a);
67 set(set&& s, const allocator_type& a);
68 set(initializer_list<value_type> il, const value_compare& comp = value_compare());
69 set(initializer_list<value_type> il, const value_compare& comp,
70 const allocator_type& a);
Marshall Clow631788a2013-09-11 00:06:45 +000071 template <class InputIterator>
72 set(InputIterator first, InputIterator last, const allocator_type& a)
73 : set(first, last, Compare(), a) {} // C++14
74 set(initializer_list<value_type> il, const allocator_type& a)
75 : set(il, Compare(), a) {} // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000076 ~set();
77
78 set& operator=(const set& s);
Howard Hinnantf95f4f52011-06-04 15:22:34 +000079 set& operator=(set&& s)
80 noexcept(
81 allocator_type::propagate_on_container_move_assignment::value &&
82 is_nothrow_move_assignable<allocator_type>::value &&
83 is_nothrow_move_assignable<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +000084 set& operator=(initializer_list<value_type> il);
85
86 // iterators:
Howard Hinnantf95f4f52011-06-04 15:22:34 +000087 iterator begin() noexcept;
88 const_iterator begin() const noexcept;
89 iterator end() noexcept;
90 const_iterator end() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000091
Howard Hinnantf95f4f52011-06-04 15:22:34 +000092 reverse_iterator rbegin() noexcept;
93 const_reverse_iterator rbegin() const noexcept;
94 reverse_iterator rend() noexcept;
95 const_reverse_iterator rend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000096
Howard Hinnantf95f4f52011-06-04 15:22:34 +000097 const_iterator cbegin() const noexcept;
98 const_iterator cend() const noexcept;
99 const_reverse_iterator crbegin() const noexcept;
100 const_reverse_iterator crend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000101
102 // capacity:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000103 bool empty() const noexcept;
104 size_type size() const noexcept;
105 size_type max_size() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000106
107 // modifiers:
108 template <class... Args>
109 pair<iterator, bool> emplace(Args&&... args);
110 template <class... Args>
111 iterator emplace_hint(const_iterator position, Args&&... args);
112 pair<iterator,bool> insert(const value_type& v);
113 pair<iterator,bool> insert(value_type&& v);
114 iterator insert(const_iterator position, const value_type& v);
115 iterator insert(const_iterator position, value_type&& v);
116 template <class InputIterator>
117 void insert(InputIterator first, InputIterator last);
118 void insert(initializer_list<value_type> il);
119
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000120 node_type extract(const_iterator position); // C++17
121 node_type extract(const key_type& x); // C++17
122 insert_return_type insert(node_type&& nh); // C++17
123 iterator insert(const_iterator hint, node_type&& nh); // C++17
124
Howard Hinnantc51e1022010-05-11 19:42:16 +0000125 iterator erase(const_iterator position);
Marshall Clow22ea5b82015-05-10 13:35:00 +0000126 iterator erase(iterator position); // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000127 size_type erase(const key_type& k);
128 iterator erase(const_iterator first, const_iterator last);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000129 void clear() noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000130
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000131 template<class C2>
132 void merge(set<Key, C2, Allocator>& source); // C++17
133 template<class C2>
134 void merge(set<Key, C2, Allocator>&& source); // C++17
135 template<class C2>
136 void merge(multiset<Key, C2, Allocator>& source); // C++17
137 template<class C2>
138 void merge(multiset<Key, C2, Allocator>&& source); // C++17
139
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000140 void swap(set& s)
141 noexcept(
142 __is_nothrow_swappable<key_compare>::value &&
143 (!allocator_type::propagate_on_container_swap::value ||
144 __is_nothrow_swappable<allocator_type>::value));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000145
146 // observers:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000147 allocator_type get_allocator() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000148 key_compare key_comp() const;
149 value_compare value_comp() const;
150
151 // set operations:
152 iterator find(const key_type& k);
153 const_iterator find(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000154 template<typename K>
155 iterator find(const K& x);
156 template<typename K>
157 const_iterator find(const K& x) const; // C++14
158 template<typename K>
159 size_type count(const K& x) const; // C++14
160
Howard Hinnantc51e1022010-05-11 19:42:16 +0000161 size_type count(const key_type& k) const;
162 iterator lower_bound(const key_type& k);
163 const_iterator lower_bound(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000164 template<typename K>
165 iterator lower_bound(const K& x); // C++14
166 template<typename K>
167 const_iterator lower_bound(const K& x) const; // C++14
168
Howard Hinnantc51e1022010-05-11 19:42:16 +0000169 iterator upper_bound(const key_type& k);
170 const_iterator upper_bound(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000171 template<typename K>
172 iterator upper_bound(const K& x); // C++14
173 template<typename K>
174 const_iterator upper_bound(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000175 pair<iterator,iterator> equal_range(const key_type& k);
176 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000177 template<typename K>
178 pair<iterator,iterator> equal_range(const K& x); // C++14
179 template<typename K>
180 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000181};
182
183template <class Key, class Compare, class Allocator>
184bool
185operator==(const set<Key, Compare, Allocator>& x,
186 const set<Key, Compare, Allocator>& y);
187
188template <class Key, class Compare, class Allocator>
189bool
190operator< (const set<Key, Compare, Allocator>& x,
191 const set<Key, Compare, Allocator>& y);
192
193template <class Key, class Compare, class Allocator>
194bool
195operator!=(const set<Key, Compare, Allocator>& x,
196 const set<Key, Compare, Allocator>& y);
197
198template <class Key, class Compare, class Allocator>
199bool
200operator> (const set<Key, Compare, Allocator>& x,
201 const set<Key, Compare, Allocator>& y);
202
203template <class Key, class Compare, class Allocator>
204bool
205operator>=(const set<Key, Compare, Allocator>& x,
206 const set<Key, Compare, Allocator>& y);
207
208template <class Key, class Compare, class Allocator>
209bool
210operator<=(const set<Key, Compare, Allocator>& x,
211 const set<Key, Compare, Allocator>& y);
212
213// specialized algorithms:
214template <class Key, class Compare, class Allocator>
215void
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000216swap(set<Key, Compare, Allocator>& x, set<Key, Compare, Allocator>& y)
217 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000218
Marshall Clow29b53f22018-12-14 18:49:35 +0000219template <class Key, class Compare, class Allocator, class Predicate>
220 void erase_if(set<Key, Compare, Allocator>& c, Predicate pred); // C++20
221
Howard Hinnantc51e1022010-05-11 19:42:16 +0000222template <class Key, class Compare = less<Key>,
223 class Allocator = allocator<Key>>
224class multiset
225{
226public:
227 // types:
228 typedef Key key_type;
229 typedef key_type value_type;
230 typedef Compare key_compare;
231 typedef key_compare value_compare;
232 typedef Allocator allocator_type;
233 typedef typename allocator_type::reference reference;
234 typedef typename allocator_type::const_reference const_reference;
235 typedef typename allocator_type::size_type size_type;
236 typedef typename allocator_type::difference_type difference_type;
237 typedef typename allocator_type::pointer pointer;
238 typedef typename allocator_type::const_pointer const_pointer;
239
240 typedef implementation-defined iterator;
241 typedef implementation-defined const_iterator;
242 typedef std::reverse_iterator<iterator> reverse_iterator;
243 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000244 typedef unspecified node_type; // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000245
246 // construct/copy/destroy:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000247 multiset()
248 noexcept(
249 is_nothrow_default_constructible<allocator_type>::value &&
250 is_nothrow_default_constructible<key_compare>::value &&
251 is_nothrow_copy_constructible<key_compare>::value);
252 explicit multiset(const value_compare& comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000253 multiset(const value_compare& comp, const allocator_type& a);
254 template <class InputIterator>
255 multiset(InputIterator first, InputIterator last,
256 const value_compare& comp = value_compare());
257 template <class InputIterator>
258 multiset(InputIterator first, InputIterator last,
259 const value_compare& comp, const allocator_type& a);
260 multiset(const multiset& s);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000261 multiset(multiset&& s)
262 noexcept(
263 is_nothrow_move_constructible<allocator_type>::value &&
264 is_nothrow_move_constructible<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000265 explicit multiset(const allocator_type& a);
266 multiset(const multiset& s, const allocator_type& a);
267 multiset(multiset&& s, const allocator_type& a);
268 multiset(initializer_list<value_type> il, const value_compare& comp = value_compare());
269 multiset(initializer_list<value_type> il, const value_compare& comp,
270 const allocator_type& a);
Marshall Clow631788a2013-09-11 00:06:45 +0000271 template <class InputIterator>
272 multiset(InputIterator first, InputIterator last, const allocator_type& a)
273 : set(first, last, Compare(), a) {} // C++14
274 multiset(initializer_list<value_type> il, const allocator_type& a)
275 : set(il, Compare(), a) {} // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000276 ~multiset();
277
278 multiset& operator=(const multiset& s);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000279 multiset& operator=(multiset&& s)
280 noexcept(
281 allocator_type::propagate_on_container_move_assignment::value &&
282 is_nothrow_move_assignable<allocator_type>::value &&
283 is_nothrow_move_assignable<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000284 multiset& operator=(initializer_list<value_type> il);
285
286 // iterators:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000287 iterator begin() noexcept;
288 const_iterator begin() const noexcept;
289 iterator end() noexcept;
290 const_iterator end() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000291
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000292 reverse_iterator rbegin() noexcept;
293 const_reverse_iterator rbegin() const noexcept;
294 reverse_iterator rend() noexcept;
295 const_reverse_iterator rend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000296
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000297 const_iterator cbegin() const noexcept;
298 const_iterator cend() const noexcept;
299 const_reverse_iterator crbegin() const noexcept;
300 const_reverse_iterator crend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000301
302 // capacity:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000303 bool empty() const noexcept;
304 size_type size() const noexcept;
305 size_type max_size() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000306
307 // modifiers:
308 template <class... Args>
309 iterator emplace(Args&&... args);
310 template <class... Args>
311 iterator emplace_hint(const_iterator position, Args&&... args);
312 iterator insert(const value_type& v);
313 iterator insert(value_type&& v);
314 iterator insert(const_iterator position, const value_type& v);
315 iterator insert(const_iterator position, value_type&& v);
316 template <class InputIterator>
317 void insert(InputIterator first, InputIterator last);
318 void insert(initializer_list<value_type> il);
319
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000320 node_type extract(const_iterator position); // C++17
321 node_type extract(const key_type& x); // C++17
322 iterator insert(node_type&& nh); // C++17
323 iterator insert(const_iterator hint, node_type&& nh); // C++17
324
Howard Hinnantc51e1022010-05-11 19:42:16 +0000325 iterator erase(const_iterator position);
Marshall Clow22ea5b82015-05-10 13:35:00 +0000326 iterator erase(iterator position); // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000327 size_type erase(const key_type& k);
328 iterator erase(const_iterator first, const_iterator last);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000329 void clear() noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000330
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000331 template<class C2>
332 void merge(multiset<Key, C2, Allocator>& source); // C++17
333 template<class C2>
334 void merge(multiset<Key, C2, Allocator>&& source); // C++17
335 template<class C2>
336 void merge(set<Key, C2, Allocator>& source); // C++17
337 template<class C2>
338 void merge(set<Key, C2, Allocator>&& source); // C++17
339
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000340 void swap(multiset& s)
341 noexcept(
342 __is_nothrow_swappable<key_compare>::value &&
343 (!allocator_type::propagate_on_container_swap::value ||
344 __is_nothrow_swappable<allocator_type>::value));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000345
346 // observers:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000347 allocator_type get_allocator() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000348 key_compare key_comp() const;
349 value_compare value_comp() const;
350
351 // set operations:
352 iterator find(const key_type& k);
353 const_iterator find(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000354 template<typename K>
355 iterator find(const K& x);
356 template<typename K>
357 const_iterator find(const K& x) const; // C++14
358
Howard Hinnantc51e1022010-05-11 19:42:16 +0000359 size_type count(const key_type& k) const;
360 iterator lower_bound(const key_type& k);
361 const_iterator lower_bound(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000362 template<typename K>
363 iterator lower_bound(const K& x); // C++14
364 template<typename K>
365 const_iterator lower_bound(const K& x) const; // C++14
366
Howard Hinnantc51e1022010-05-11 19:42:16 +0000367 iterator upper_bound(const key_type& k);
368 const_iterator upper_bound(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000369 template<typename K>
370 iterator upper_bound(const K& x); // C++14
371 template<typename K>
372 const_iterator upper_bound(const K& x) const; // C++14
373
Howard Hinnantc51e1022010-05-11 19:42:16 +0000374 pair<iterator,iterator> equal_range(const key_type& k);
375 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000376 template<typename K>
377 pair<iterator,iterator> equal_range(const K& x); // C++14
378 template<typename K>
379 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000380};
381
382template <class Key, class Compare, class Allocator>
383bool
384operator==(const multiset<Key, Compare, Allocator>& x,
385 const multiset<Key, Compare, Allocator>& y);
386
387template <class Key, class Compare, class Allocator>
388bool
389operator< (const multiset<Key, Compare, Allocator>& x,
390 const multiset<Key, Compare, Allocator>& y);
391
392template <class Key, class Compare, class Allocator>
393bool
394operator!=(const multiset<Key, Compare, Allocator>& x,
395 const multiset<Key, Compare, Allocator>& y);
396
397template <class Key, class Compare, class Allocator>
398bool
399operator> (const multiset<Key, Compare, Allocator>& x,
400 const multiset<Key, Compare, Allocator>& y);
401
402template <class Key, class Compare, class Allocator>
403bool
404operator>=(const multiset<Key, Compare, Allocator>& x,
405 const multiset<Key, Compare, Allocator>& y);
406
407template <class Key, class Compare, class Allocator>
408bool
409operator<=(const multiset<Key, Compare, Allocator>& x,
410 const multiset<Key, Compare, Allocator>& y);
411
412// specialized algorithms:
413template <class Key, class Compare, class Allocator>
414void
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000415swap(multiset<Key, Compare, Allocator>& x, multiset<Key, Compare, Allocator>& y)
416 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000417
Marshall Clow29b53f22018-12-14 18:49:35 +0000418template <class Key, class Compare, class Allocator, class Predicate>
419 void erase_if(multiset<Key, Compare, Allocator>& c, Predicate pred); // C++20
420
Howard Hinnantc51e1022010-05-11 19:42:16 +0000421} // std
422
423*/
424
425#include <__config>
426#include <__tree>
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000427#include <__node_handle>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000428#include <functional>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000429#include <version>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000430
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000431#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000432#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000433#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000434
435_LIBCPP_BEGIN_NAMESPACE_STD
436
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000437template <class _Key, class _Compare, class _Allocator>
438class multiset;
439
Howard Hinnantc51e1022010-05-11 19:42:16 +0000440template <class _Key, class _Compare = less<_Key>,
441 class _Allocator = allocator<_Key> >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000442class _LIBCPP_TEMPLATE_VIS set
Howard Hinnantc51e1022010-05-11 19:42:16 +0000443{
444public:
445 // types:
446 typedef _Key key_type;
447 typedef key_type value_type;
448 typedef _Compare key_compare;
449 typedef key_compare value_compare;
450 typedef _Allocator allocator_type;
451 typedef value_type& reference;
452 typedef const value_type& const_reference;
453
Louis Dionne878a3a82018-12-06 21:46:17 +0000454 static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), "");
Marshall Clow5128cf32015-11-26 01:24:04 +0000455 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
456 "Allocator::value_type must be same type as value_type");
457
Howard Hinnantc51e1022010-05-11 19:42:16 +0000458private:
459 typedef __tree<value_type, value_compare, allocator_type> __base;
460 typedef allocator_traits<allocator_type> __alloc_traits;
461 typedef typename __base::__node_holder __node_holder;
462
463 __base __tree_;
464
465public:
466 typedef typename __base::pointer pointer;
467 typedef typename __base::const_pointer const_pointer;
468 typedef typename __base::size_type size_type;
469 typedef typename __base::difference_type difference_type;
470 typedef typename __base::const_iterator iterator;
471 typedef typename __base::const_iterator const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000472 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
473 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000474
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000475#if _LIBCPP_STD_VER > 14
476 typedef __set_node_handle<typename __base::__node, allocator_type> node_type;
477 typedef __insert_return_type<iterator, node_type> insert_return_type;
478#endif
479
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000480 template <class _Key2, class _Compare2, class _Alloc2>
481 friend class _LIBCPP_TEMPLATE_VIS set;
482 template <class _Key2, class _Compare2, class _Alloc2>
483 friend class _LIBCPP_TEMPLATE_VIS multiset;
484
Howard Hinnant192cf032010-09-23 16:27:36 +0000485 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +0000486 set()
487 _NOEXCEPT_(
488 is_nothrow_default_constructible<allocator_type>::value &&
489 is_nothrow_default_constructible<key_compare>::value &&
490 is_nothrow_copy_constructible<key_compare>::value)
491 : __tree_(value_compare()) {}
492
493 _LIBCPP_INLINE_VISIBILITY
494 explicit set(const value_compare& __comp)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000495 _NOEXCEPT_(
496 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000497 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000498 : __tree_(__comp) {}
Marshall Clow7086a5a2014-03-10 04:50:10 +0000499
Howard Hinnant192cf032010-09-23 16:27:36 +0000500 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7ed23a72014-03-05 19:06:20 +0000501 explicit set(const value_compare& __comp, const allocator_type& __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000502 : __tree_(__comp, __a) {}
503 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000504 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000505 set(_InputIterator __f, _InputIterator __l,
506 const value_compare& __comp = value_compare())
507 : __tree_(__comp)
508 {
509 insert(__f, __l);
510 }
511
512 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000513 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000514 set(_InputIterator __f, _InputIterator __l, const value_compare& __comp,
515 const allocator_type& __a)
516 : __tree_(__comp, __a)
517 {
518 insert(__f, __l);
519 }
520
Marshall Clow631788a2013-09-11 00:06:45 +0000521#if _LIBCPP_STD_VER > 11
522 template <class _InputIterator>
Louis Dionned2322c82018-11-01 14:41:37 +0000523 _LIBCPP_INLINE_VISIBILITY
Marshall Clow631788a2013-09-11 00:06:45 +0000524 set(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
525 : set(__f, __l, key_compare(), __a) {}
526#endif
527
Howard Hinnant192cf032010-09-23 16:27:36 +0000528 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000529 set(const set& __s)
530 : __tree_(__s.__tree_)
531 {
532 insert(__s.begin(), __s.end());
533 }
534
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000535 _LIBCPP_INLINE_VISIBILITY
536 set& operator=(const set& __s)
537 {
538 __tree_ = __s.__tree_;
539 return *this;
540 }
541
Eric Fiselier615961b2017-04-18 20:58:03 +0000542#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant192cf032010-09-23 16:27:36 +0000543 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000544 set(set&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000545 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000546 : __tree_(_VSTD::move(__s.__tree_)) {}
Eric Fiselier615961b2017-04-18 20:58:03 +0000547#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000548
Howard Hinnant192cf032010-09-23 16:27:36 +0000549 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000550 explicit set(const allocator_type& __a)
551 : __tree_(__a) {}
552
Howard Hinnant192cf032010-09-23 16:27:36 +0000553 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000554 set(const set& __s, const allocator_type& __a)
555 : __tree_(__s.__tree_.value_comp(), __a)
556 {
557 insert(__s.begin(), __s.end());
558 }
559
Eric Fiselier615961b2017-04-18 20:58:03 +0000560#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000561 set(set&& __s, const allocator_type& __a);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000562
Howard Hinnant192cf032010-09-23 16:27:36 +0000563 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000564 set(initializer_list<value_type> __il, const value_compare& __comp = value_compare())
565 : __tree_(__comp)
566 {
567 insert(__il.begin(), __il.end());
568 }
569
Howard Hinnant192cf032010-09-23 16:27:36 +0000570 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000571 set(initializer_list<value_type> __il, const value_compare& __comp,
572 const allocator_type& __a)
573 : __tree_(__comp, __a)
574 {
575 insert(__il.begin(), __il.end());
576 }
577
Marshall Clow631788a2013-09-11 00:06:45 +0000578#if _LIBCPP_STD_VER > 11
Louis Dionned2322c82018-11-01 14:41:37 +0000579 _LIBCPP_INLINE_VISIBILITY
Marshall Clow631788a2013-09-11 00:06:45 +0000580 set(initializer_list<value_type> __il, const allocator_type& __a)
581 : set(__il, key_compare(), __a) {}
582#endif
583
Howard Hinnant192cf032010-09-23 16:27:36 +0000584 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000585 set& operator=(initializer_list<value_type> __il)
586 {
587 __tree_.__assign_unique(__il.begin(), __il.end());
588 return *this;
589 }
590
Howard Hinnant192cf032010-09-23 16:27:36 +0000591 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000592 set& operator=(set&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000593 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000594 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000595 __tree_ = _VSTD::move(__s.__tree_);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000596 return *this;
597 }
Eric Fiselier615961b2017-04-18 20:58:03 +0000598#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000599
Howard Hinnant192cf032010-09-23 16:27:36 +0000600 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000601 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000602 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000603 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000604 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000605 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000606 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000607 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000608
Howard Hinnant192cf032010-09-23 16:27:36 +0000609 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000610 reverse_iterator rbegin() _NOEXCEPT
611 {return reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +0000612 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000613 const_reverse_iterator rbegin() const _NOEXCEPT
614 {return const_reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +0000615 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000616 reverse_iterator rend() _NOEXCEPT
617 {return reverse_iterator(begin());}
Howard Hinnant192cf032010-09-23 16:27:36 +0000618 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000619 const_reverse_iterator rend() const _NOEXCEPT
620 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000621
Howard Hinnant192cf032010-09-23 16:27:36 +0000622 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000623 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000624 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000625 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000626 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000627 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000628 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000629 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000630
Marshall Clow425f5752017-11-15 05:51:26 +0000631 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000632 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant192cf032010-09-23 16:27:36 +0000633 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000634 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000635 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000636 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000637
638 // modifiers:
Eric Fiselier615961b2017-04-18 20:58:03 +0000639#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000640 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +0000641 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000642 pair<iterator, bool> emplace(_Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000643 {return __tree_.__emplace_unique(_VSTD::forward<_Args>(__args)...);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000644 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +0000645 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000646 iterator emplace_hint(const_iterator __p, _Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000647 {return __tree_.__emplace_hint_unique(__p, _VSTD::forward<_Args>(__args)...);}
Eric Fiselier615961b2017-04-18 20:58:03 +0000648#endif // _LIBCPP_CXX03_LANG
649
Howard Hinnant192cf032010-09-23 16:27:36 +0000650 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000651 pair<iterator,bool> insert(const value_type& __v)
652 {return __tree_.__insert_unique(__v);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000653 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000654 iterator insert(const_iterator __p, const value_type& __v)
655 {return __tree_.__insert_unique(__p, __v);}
Eric Fiselier615961b2017-04-18 20:58:03 +0000656
Howard Hinnantc51e1022010-05-11 19:42:16 +0000657 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000658 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000659 void insert(_InputIterator __f, _InputIterator __l)
660 {
661 for (const_iterator __e = cend(); __f != __l; ++__f)
662 __tree_.__insert_unique(__e, *__f);
663 }
664
Eric Fiselier615961b2017-04-18 20:58:03 +0000665#ifndef _LIBCPP_CXX03_LANG
666 _LIBCPP_INLINE_VISIBILITY
667 pair<iterator,bool> insert(value_type&& __v)
668 {return __tree_.__insert_unique(_VSTD::move(__v));}
669
670 _LIBCPP_INLINE_VISIBILITY
671 iterator insert(const_iterator __p, value_type&& __v)
672 {return __tree_.__insert_unique(__p, _VSTD::move(__v));}
673
Howard Hinnant192cf032010-09-23 16:27:36 +0000674 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000675 void insert(initializer_list<value_type> __il)
676 {insert(__il.begin(), __il.end());}
Eric Fiselier615961b2017-04-18 20:58:03 +0000677#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000678
Howard Hinnant192cf032010-09-23 16:27:36 +0000679 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000680 iterator erase(const_iterator __p) {return __tree_.erase(__p);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000681 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000682 size_type erase(const key_type& __k)
683 {return __tree_.__erase_unique(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000684 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000685 iterator erase(const_iterator __f, const_iterator __l)
686 {return __tree_.erase(__f, __l);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000687 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000688 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000689
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000690#if _LIBCPP_STD_VER > 14
691 _LIBCPP_INLINE_VISIBILITY
692 insert_return_type insert(node_type&& __nh)
693 {
694 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
695 "node_type with incompatible allocator passed to set::insert()");
696 return __tree_.template __node_handle_insert_unique<
697 node_type, insert_return_type>(_VSTD::move(__nh));
698 }
699 _LIBCPP_INLINE_VISIBILITY
700 iterator insert(const_iterator __hint, node_type&& __nh)
701 {
702 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
703 "node_type with incompatible allocator passed to set::insert()");
704 return __tree_.template __node_handle_insert_unique<node_type>(
705 __hint, _VSTD::move(__nh));
706 }
707 _LIBCPP_INLINE_VISIBILITY
708 node_type extract(key_type const& __key)
709 {
710 return __tree_.template __node_handle_extract<node_type>(__key);
711 }
712 _LIBCPP_INLINE_VISIBILITY
713 node_type extract(const_iterator __it)
714 {
715 return __tree_.template __node_handle_extract<node_type>(__it);
716 }
Louis Dionned2322c82018-11-01 14:41:37 +0000717 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000718 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +0000719 void merge(set<key_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000720 {
721 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
722 "merging container with incompatible allocator");
723 __tree_.__node_handle_merge_unique(__source.__tree_);
724 }
Louis Dionned2322c82018-11-01 14:41:37 +0000725 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000726 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +0000727 void merge(set<key_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000728 {
729 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
730 "merging container with incompatible allocator");
731 __tree_.__node_handle_merge_unique(__source.__tree_);
732 }
Louis Dionned2322c82018-11-01 14:41:37 +0000733 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000734 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +0000735 void merge(multiset<key_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000736 {
737 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
738 "merging container with incompatible allocator");
739 __tree_.__node_handle_merge_unique(__source.__tree_);
740 }
Louis Dionned2322c82018-11-01 14:41:37 +0000741 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000742 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +0000743 void merge(multiset<key_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000744 {
745 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
746 "merging container with incompatible allocator");
747 __tree_.__node_handle_merge_unique(__source.__tree_);
748 }
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000749#endif
750
Howard Hinnant192cf032010-09-23 16:27:36 +0000751 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000752 void swap(set& __s) _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
753 {__tree_.swap(__s.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000754
Howard Hinnant192cf032010-09-23 16:27:36 +0000755 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000756 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000757 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000758 key_compare key_comp() const {return __tree_.value_comp();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000759 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000760 value_compare value_comp() const {return __tree_.value_comp();}
761
762 // set operations:
Howard Hinnant192cf032010-09-23 16:27:36 +0000763 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000764 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000765 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000766 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000767#if _LIBCPP_STD_VER > 11
768 template <typename _K2>
769 _LIBCPP_INLINE_VISIBILITY
770 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
771 find(const _K2& __k) {return __tree_.find(__k);}
772 template <typename _K2>
773 _LIBCPP_INLINE_VISIBILITY
774 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
775 find(const _K2& __k) const {return __tree_.find(__k);}
776#endif
777
Howard Hinnant192cf032010-09-23 16:27:36 +0000778 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000779 size_type count(const key_type& __k) const
780 {return __tree_.__count_unique(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +0000781#if _LIBCPP_STD_VER > 11
782 template <typename _K2>
783 _LIBCPP_INLINE_VISIBILITY
784 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +0000785 count(const _K2& __k) const {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +0000786#endif
Howard Hinnant192cf032010-09-23 16:27:36 +0000787 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000788 iterator lower_bound(const key_type& __k)
789 {return __tree_.lower_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000790 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000791 const_iterator lower_bound(const key_type& __k) const
792 {return __tree_.lower_bound(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000793#if _LIBCPP_STD_VER > 11
794 template <typename _K2>
795 _LIBCPP_INLINE_VISIBILITY
796 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
797 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
798
799 template <typename _K2>
800 _LIBCPP_INLINE_VISIBILITY
801 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
802 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
803#endif
804
Howard Hinnant192cf032010-09-23 16:27:36 +0000805 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000806 iterator upper_bound(const key_type& __k)
807 {return __tree_.upper_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000808 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000809 const_iterator upper_bound(const key_type& __k) const
810 {return __tree_.upper_bound(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000811#if _LIBCPP_STD_VER > 11
812 template <typename _K2>
813 _LIBCPP_INLINE_VISIBILITY
814 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
815 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
816 template <typename _K2>
817 _LIBCPP_INLINE_VISIBILITY
818 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
819 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
820#endif
821
Howard Hinnant192cf032010-09-23 16:27:36 +0000822 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000823 pair<iterator,iterator> equal_range(const key_type& __k)
824 {return __tree_.__equal_range_unique(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000825 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000826 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
827 {return __tree_.__equal_range_unique(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000828#if _LIBCPP_STD_VER > 11
829 template <typename _K2>
830 _LIBCPP_INLINE_VISIBILITY
831 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +0000832 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000833 template <typename _K2>
834 _LIBCPP_INLINE_VISIBILITY
835 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +0000836 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000837#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000838};
839
Eric Fiselier615961b2017-04-18 20:58:03 +0000840#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000841
842template <class _Key, class _Compare, class _Allocator>
843set<_Key, _Compare, _Allocator>::set(set&& __s, const allocator_type& __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000844 : __tree_(_VSTD::move(__s.__tree_), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000845{
846 if (__a != __s.get_allocator())
847 {
848 const_iterator __e = cend();
849 while (!__s.empty())
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000850 insert(__e, _VSTD::move(__s.__tree_.remove(__s.begin())->__value_));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000851 }
852}
853
Eric Fiselier615961b2017-04-18 20:58:03 +0000854#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000855
856template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000857inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000858bool
859operator==(const set<_Key, _Compare, _Allocator>& __x,
860 const set<_Key, _Compare, _Allocator>& __y)
861{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000862 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000863}
864
865template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000866inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000867bool
868operator< (const set<_Key, _Compare, _Allocator>& __x,
869 const set<_Key, _Compare, _Allocator>& __y)
870{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000871 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000872}
873
874template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000875inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000876bool
877operator!=(const set<_Key, _Compare, _Allocator>& __x,
878 const set<_Key, _Compare, _Allocator>& __y)
879{
880 return !(__x == __y);
881}
882
883template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000884inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000885bool
886operator> (const set<_Key, _Compare, _Allocator>& __x,
887 const set<_Key, _Compare, _Allocator>& __y)
888{
889 return __y < __x;
890}
891
892template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000893inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000894bool
895operator>=(const set<_Key, _Compare, _Allocator>& __x,
896 const set<_Key, _Compare, _Allocator>& __y)
897{
898 return !(__x < __y);
899}
900
901template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000902inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000903bool
904operator<=(const set<_Key, _Compare, _Allocator>& __x,
905 const set<_Key, _Compare, _Allocator>& __y)
906{
907 return !(__y < __x);
908}
909
910// specialized algorithms:
911template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000912inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000913void
914swap(set<_Key, _Compare, _Allocator>& __x,
915 set<_Key, _Compare, _Allocator>& __y)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000916 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000917{
918 __x.swap(__y);
919}
920
Marshall Clow29b53f22018-12-14 18:49:35 +0000921#if _LIBCPP_STD_VER > 17
922template <class _Key, class _Compare, class _Allocator, class _Predicate>
923inline _LIBCPP_INLINE_VISIBILITY
924void erase_if(set<_Key, _Compare, _Allocator>& __c, _Predicate __pred)
925{ __libcpp_erase_if_container(__c, __pred); }
926#endif
927
Howard Hinnantc51e1022010-05-11 19:42:16 +0000928template <class _Key, class _Compare = less<_Key>,
929 class _Allocator = allocator<_Key> >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000930class _LIBCPP_TEMPLATE_VIS multiset
Howard Hinnantc51e1022010-05-11 19:42:16 +0000931{
932public:
933 // types:
934 typedef _Key key_type;
935 typedef key_type value_type;
936 typedef _Compare key_compare;
937 typedef key_compare value_compare;
938 typedef _Allocator allocator_type;
939 typedef value_type& reference;
940 typedef const value_type& const_reference;
941
Louis Dionne878a3a82018-12-06 21:46:17 +0000942 static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), "");
Marshall Clow5128cf32015-11-26 01:24:04 +0000943 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
944 "Allocator::value_type must be same type as value_type");
945
Howard Hinnantc51e1022010-05-11 19:42:16 +0000946private:
947 typedef __tree<value_type, value_compare, allocator_type> __base;
948 typedef allocator_traits<allocator_type> __alloc_traits;
949 typedef typename __base::__node_holder __node_holder;
950
951 __base __tree_;
952
953public:
954 typedef typename __base::pointer pointer;
955 typedef typename __base::const_pointer const_pointer;
956 typedef typename __base::size_type size_type;
957 typedef typename __base::difference_type difference_type;
958 typedef typename __base::const_iterator iterator;
959 typedef typename __base::const_iterator const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000960 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
961 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000962
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000963#if _LIBCPP_STD_VER > 14
964 typedef __set_node_handle<typename __base::__node, allocator_type> node_type;
965#endif
966
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000967 template <class _Key2, class _Compare2, class _Alloc2>
968 friend class _LIBCPP_TEMPLATE_VIS set;
969 template <class _Key2, class _Compare2, class _Alloc2>
970 friend class _LIBCPP_TEMPLATE_VIS multiset;
971
Howard Hinnantc51e1022010-05-11 19:42:16 +0000972 // construct/copy/destroy:
Howard Hinnant192cf032010-09-23 16:27:36 +0000973 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +0000974 multiset()
975 _NOEXCEPT_(
976 is_nothrow_default_constructible<allocator_type>::value &&
977 is_nothrow_default_constructible<key_compare>::value &&
978 is_nothrow_copy_constructible<key_compare>::value)
979 : __tree_(value_compare()) {}
980
981 _LIBCPP_INLINE_VISIBILITY
982 explicit multiset(const value_compare& __comp)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000983 _NOEXCEPT_(
984 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000985 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000986 : __tree_(__comp) {}
Marshall Clow7086a5a2014-03-10 04:50:10 +0000987
Howard Hinnant192cf032010-09-23 16:27:36 +0000988 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7ed23a72014-03-05 19:06:20 +0000989 explicit multiset(const value_compare& __comp, const allocator_type& __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000990 : __tree_(__comp, __a) {}
991 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000992 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000993 multiset(_InputIterator __f, _InputIterator __l,
994 const value_compare& __comp = value_compare())
995 : __tree_(__comp)
996 {
997 insert(__f, __l);
998 }
999
Marshall Clow631788a2013-09-11 00:06:45 +00001000#if _LIBCPP_STD_VER > 11
1001 template <class _InputIterator>
Louis Dionned2322c82018-11-01 14:41:37 +00001002 _LIBCPP_INLINE_VISIBILITY
Marshall Clow631788a2013-09-11 00:06:45 +00001003 multiset(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
1004 : multiset(__f, __l, key_compare(), __a) {}
1005#endif
1006
Howard Hinnantc51e1022010-05-11 19:42:16 +00001007 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001008 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001009 multiset(_InputIterator __f, _InputIterator __l,
1010 const value_compare& __comp, const allocator_type& __a)
1011 : __tree_(__comp, __a)
1012 {
1013 insert(__f, __l);
1014 }
1015
Howard Hinnant192cf032010-09-23 16:27:36 +00001016 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001017 multiset(const multiset& __s)
1018 : __tree_(__s.__tree_.value_comp(),
1019 __alloc_traits::select_on_container_copy_construction(__s.__tree_.__alloc()))
1020 {
1021 insert(__s.begin(), __s.end());
1022 }
1023
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001024 _LIBCPP_INLINE_VISIBILITY
1025 multiset& operator=(const multiset& __s)
1026 {
1027 __tree_ = __s.__tree_;
1028 return *this;
1029 }
1030
Eric Fiselier615961b2017-04-18 20:58:03 +00001031#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant192cf032010-09-23 16:27:36 +00001032 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001033 multiset(multiset&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001034 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001035 : __tree_(_VSTD::move(__s.__tree_)) {}
Eric Fiselier615961b2017-04-18 20:58:03 +00001036
1037 multiset(multiset&& __s, const allocator_type& __a);
1038#endif // _LIBCPP_CXX03_LANG
Howard Hinnant192cf032010-09-23 16:27:36 +00001039 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001040 explicit multiset(const allocator_type& __a)
1041 : __tree_(__a) {}
Howard Hinnant192cf032010-09-23 16:27:36 +00001042 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001043 multiset(const multiset& __s, const allocator_type& __a)
1044 : __tree_(__s.__tree_.value_comp(), __a)
1045 {
1046 insert(__s.begin(), __s.end());
1047 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001048
Eric Fiselier615961b2017-04-18 20:58:03 +00001049#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant192cf032010-09-23 16:27:36 +00001050 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001051 multiset(initializer_list<value_type> __il, const value_compare& __comp = value_compare())
1052 : __tree_(__comp)
1053 {
1054 insert(__il.begin(), __il.end());
1055 }
1056
Howard Hinnant192cf032010-09-23 16:27:36 +00001057 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001058 multiset(initializer_list<value_type> __il, const value_compare& __comp,
1059 const allocator_type& __a)
1060 : __tree_(__comp, __a)
1061 {
1062 insert(__il.begin(), __il.end());
1063 }
1064
Marshall Clow631788a2013-09-11 00:06:45 +00001065#if _LIBCPP_STD_VER > 11
Louis Dionned2322c82018-11-01 14:41:37 +00001066 _LIBCPP_INLINE_VISIBILITY
Marshall Clow631788a2013-09-11 00:06:45 +00001067 multiset(initializer_list<value_type> __il, const allocator_type& __a)
1068 : multiset(__il, key_compare(), __a) {}
1069#endif
1070
Howard Hinnant192cf032010-09-23 16:27:36 +00001071 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001072 multiset& operator=(initializer_list<value_type> __il)
1073 {
1074 __tree_.__assign_multi(__il.begin(), __il.end());
1075 return *this;
1076 }
1077
Howard Hinnant192cf032010-09-23 16:27:36 +00001078 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001079 multiset& operator=(multiset&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001080 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001081 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001082 __tree_ = _VSTD::move(__s.__tree_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001083 return *this;
1084 }
Eric Fiselier615961b2017-04-18 20:58:03 +00001085#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001086
Howard Hinnant192cf032010-09-23 16:27:36 +00001087 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001088 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001089 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001090 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001091 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001092 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001093 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001094 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001095
Howard Hinnant192cf032010-09-23 16:27:36 +00001096 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001097 reverse_iterator rbegin() _NOEXCEPT
1098 {return reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +00001099 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001100 const_reverse_iterator rbegin() const _NOEXCEPT
1101 {return const_reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +00001102 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001103 reverse_iterator rend() _NOEXCEPT
1104 {return reverse_iterator(begin());}
Howard Hinnant192cf032010-09-23 16:27:36 +00001105 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001106 const_reverse_iterator rend() const _NOEXCEPT
1107 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001108
Howard Hinnant192cf032010-09-23 16:27:36 +00001109 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001110 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001111 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001112 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001113 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001114 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001115 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001116 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001117
Marshall Clow425f5752017-11-15 05:51:26 +00001118 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001119 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant192cf032010-09-23 16:27:36 +00001120 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001121 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001122 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001123 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001124
1125 // modifiers:
Eric Fiselier615961b2017-04-18 20:58:03 +00001126#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001127 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +00001128 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001129 iterator emplace(_Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001130 {return __tree_.__emplace_multi(_VSTD::forward<_Args>(__args)...);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001131 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +00001132 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001133 iterator emplace_hint(const_iterator __p, _Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001134 {return __tree_.__emplace_hint_multi(__p, _VSTD::forward<_Args>(__args)...);}
Eric Fiselier615961b2017-04-18 20:58:03 +00001135#endif // _LIBCPP_CXX03_LANG
1136
Howard Hinnant192cf032010-09-23 16:27:36 +00001137 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001138 iterator insert(const value_type& __v)
1139 {return __tree_.__insert_multi(__v);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001140 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001141 iterator insert(const_iterator __p, const value_type& __v)
1142 {return __tree_.__insert_multi(__p, __v);}
Eric Fiselier615961b2017-04-18 20:58:03 +00001143
Howard Hinnantc51e1022010-05-11 19:42:16 +00001144 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001145 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001146 void insert(_InputIterator __f, _InputIterator __l)
1147 {
1148 for (const_iterator __e = cend(); __f != __l; ++__f)
1149 __tree_.__insert_multi(__e, *__f);
1150 }
1151
Eric Fiselier615961b2017-04-18 20:58:03 +00001152#ifndef _LIBCPP_CXX03_LANG
1153 _LIBCPP_INLINE_VISIBILITY
1154 iterator insert(value_type&& __v)
1155 {return __tree_.__insert_multi(_VSTD::move(__v));}
1156
1157 _LIBCPP_INLINE_VISIBILITY
1158 iterator insert(const_iterator __p, value_type&& __v)
1159 {return __tree_.__insert_multi(__p, _VSTD::move(__v));}
1160
Howard Hinnant192cf032010-09-23 16:27:36 +00001161 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001162 void insert(initializer_list<value_type> __il)
1163 {insert(__il.begin(), __il.end());}
Eric Fiselier615961b2017-04-18 20:58:03 +00001164#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001165
Howard Hinnant192cf032010-09-23 16:27:36 +00001166 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001167 iterator erase(const_iterator __p) {return __tree_.erase(__p);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001168 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001169 size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001170 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001171 iterator erase(const_iterator __f, const_iterator __l)
1172 {return __tree_.erase(__f, __l);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001173 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001174 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001175
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001176#if _LIBCPP_STD_VER > 14
1177 _LIBCPP_INLINE_VISIBILITY
1178 iterator insert(node_type&& __nh)
1179 {
1180 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1181 "node_type with incompatible allocator passed to multiset::insert()");
1182 return __tree_.template __node_handle_insert_multi<node_type>(
1183 _VSTD::move(__nh));
1184 }
1185 _LIBCPP_INLINE_VISIBILITY
1186 iterator insert(const_iterator __hint, node_type&& __nh)
1187 {
1188 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1189 "node_type with incompatible allocator passed to multiset::insert()");
1190 return __tree_.template __node_handle_insert_multi<node_type>(
1191 __hint, _VSTD::move(__nh));
1192 }
1193 _LIBCPP_INLINE_VISIBILITY
1194 node_type extract(key_type const& __key)
1195 {
1196 return __tree_.template __node_handle_extract<node_type>(__key);
1197 }
1198 _LIBCPP_INLINE_VISIBILITY
1199 node_type extract(const_iterator __it)
1200 {
1201 return __tree_.template __node_handle_extract<node_type>(__it);
1202 }
Louis Dionned2322c82018-11-01 14:41:37 +00001203 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001204 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001205 void merge(multiset<key_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001206 {
1207 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1208 "merging container with incompatible allocator");
1209 __tree_.__node_handle_merge_multi(__source.__tree_);
1210 }
Louis Dionned2322c82018-11-01 14:41:37 +00001211 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001212 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001213 void merge(multiset<key_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001214 {
1215 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1216 "merging container with incompatible allocator");
1217 __tree_.__node_handle_merge_multi(__source.__tree_);
1218 }
Louis Dionned2322c82018-11-01 14:41:37 +00001219 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001220 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001221 void merge(set<key_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001222 {
1223 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1224 "merging container with incompatible allocator");
1225 __tree_.__node_handle_merge_multi(__source.__tree_);
1226 }
Louis Dionned2322c82018-11-01 14:41:37 +00001227 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001228 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001229 void merge(set<key_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001230 {
1231 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1232 "merging container with incompatible allocator");
1233 __tree_.__node_handle_merge_multi(__source.__tree_);
1234 }
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001235#endif
1236
Howard Hinnant192cf032010-09-23 16:27:36 +00001237 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001238 void swap(multiset& __s)
1239 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1240 {__tree_.swap(__s.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001241
Howard Hinnant192cf032010-09-23 16:27:36 +00001242 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001243 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001244 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001245 key_compare key_comp() const {return __tree_.value_comp();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001246 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001247 value_compare value_comp() const {return __tree_.value_comp();}
1248
1249 // set operations:
Howard Hinnant192cf032010-09-23 16:27:36 +00001250 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001251 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001252 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001253 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +00001254#if _LIBCPP_STD_VER > 11
1255 template <typename _K2>
1256 _LIBCPP_INLINE_VISIBILITY
1257 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,iterator>::type
1258 find(const _K2& __k) {return __tree_.find(__k);}
1259 template <typename _K2>
1260 _LIBCPP_INLINE_VISIBILITY
1261 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,const_iterator>::type
1262 find(const _K2& __k) const {return __tree_.find(__k);}
1263#endif
1264
Howard Hinnant192cf032010-09-23 16:27:36 +00001265 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001266 size_type count(const key_type& __k) const
1267 {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001268#if _LIBCPP_STD_VER > 11
1269 template <typename _K2>
1270 _LIBCPP_INLINE_VISIBILITY
1271 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
Marshall Clow5571bcd2018-01-07 17:39:57 +00001272 count(const _K2& __k) const {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001273#endif
Marshall Clowc0152142013-08-13 01:11:06 +00001274
Howard Hinnant192cf032010-09-23 16:27:36 +00001275 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001276 iterator lower_bound(const key_type& __k)
1277 {return __tree_.lower_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001278 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001279 const_iterator lower_bound(const key_type& __k) const
1280 {return __tree_.lower_bound(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +00001281#if _LIBCPP_STD_VER > 11
1282 template <typename _K2>
1283 _LIBCPP_INLINE_VISIBILITY
1284 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,iterator>::type
1285 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
1286
1287 template <typename _K2>
1288 _LIBCPP_INLINE_VISIBILITY
1289 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,const_iterator>::type
1290 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
1291#endif
1292
Howard Hinnant192cf032010-09-23 16:27:36 +00001293 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001294 iterator upper_bound(const key_type& __k)
1295 {return __tree_.upper_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001296 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001297 const_iterator upper_bound(const key_type& __k) const
1298 {return __tree_.upper_bound(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +00001299#if _LIBCPP_STD_VER > 11
1300 template <typename _K2>
1301 _LIBCPP_INLINE_VISIBILITY
1302 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,iterator>::type
1303 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
1304 template <typename _K2>
1305 _LIBCPP_INLINE_VISIBILITY
1306 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,const_iterator>::type
1307 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
1308#endif
1309
Howard Hinnant192cf032010-09-23 16:27:36 +00001310 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001311 pair<iterator,iterator> equal_range(const key_type& __k)
1312 {return __tree_.__equal_range_multi(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001313 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001314 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
1315 {return __tree_.__equal_range_multi(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +00001316#if _LIBCPP_STD_VER > 11
1317 template <typename _K2>
1318 _LIBCPP_INLINE_VISIBILITY
1319 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
1320 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
1321 template <typename _K2>
1322 _LIBCPP_INLINE_VISIBILITY
1323 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
1324 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
1325#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001326};
1327
Eric Fiselier615961b2017-04-18 20:58:03 +00001328#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001329
1330template <class _Key, class _Compare, class _Allocator>
1331multiset<_Key, _Compare, _Allocator>::multiset(multiset&& __s, const allocator_type& __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001332 : __tree_(_VSTD::move(__s.__tree_), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001333{
1334 if (__a != __s.get_allocator())
1335 {
1336 const_iterator __e = cend();
1337 while (!__s.empty())
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001338 insert(__e, _VSTD::move(__s.__tree_.remove(__s.begin())->__value_));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001339 }
1340}
1341
Eric Fiselier615961b2017-04-18 20:58:03 +00001342#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001343
1344template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001345inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001346bool
1347operator==(const multiset<_Key, _Compare, _Allocator>& __x,
1348 const multiset<_Key, _Compare, _Allocator>& __y)
1349{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001350 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001351}
1352
1353template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001354inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001355bool
1356operator< (const multiset<_Key, _Compare, _Allocator>& __x,
1357 const multiset<_Key, _Compare, _Allocator>& __y)
1358{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001359 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001360}
1361
1362template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001363inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001364bool
1365operator!=(const multiset<_Key, _Compare, _Allocator>& __x,
1366 const multiset<_Key, _Compare, _Allocator>& __y)
1367{
1368 return !(__x == __y);
1369}
1370
1371template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001372inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001373bool
1374operator> (const multiset<_Key, _Compare, _Allocator>& __x,
1375 const multiset<_Key, _Compare, _Allocator>& __y)
1376{
1377 return __y < __x;
1378}
1379
1380template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001381inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001382bool
1383operator>=(const multiset<_Key, _Compare, _Allocator>& __x,
1384 const multiset<_Key, _Compare, _Allocator>& __y)
1385{
1386 return !(__x < __y);
1387}
1388
1389template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001390inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001391bool
1392operator<=(const multiset<_Key, _Compare, _Allocator>& __x,
1393 const multiset<_Key, _Compare, _Allocator>& __y)
1394{
1395 return !(__y < __x);
1396}
1397
1398template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001399inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001400void
1401swap(multiset<_Key, _Compare, _Allocator>& __x,
1402 multiset<_Key, _Compare, _Allocator>& __y)
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001403 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001404{
1405 __x.swap(__y);
1406}
1407
Marshall Clow29b53f22018-12-14 18:49:35 +00001408#if _LIBCPP_STD_VER > 17
1409template <class _Key, class _Compare, class _Allocator, class _Predicate>
1410inline _LIBCPP_INLINE_VISIBILITY
1411void erase_if(multiset<_Key, _Compare, _Allocator>& __c, _Predicate __pred)
1412{ __libcpp_erase_if_container(__c, __pred); }
1413#endif
1414
Howard Hinnantc51e1022010-05-11 19:42:16 +00001415_LIBCPP_END_NAMESPACE_STD
1416
1417#endif // _LIBCPP_SET