blob: fb15ecfa0211a5b8b07efc59370cef55c7699dc5 [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
Howard Hinnantc51e1022010-05-11 19:42:16 +0000219template <class Key, class Compare = less<Key>,
220 class Allocator = allocator<Key>>
221class multiset
222{
223public:
224 // types:
225 typedef Key key_type;
226 typedef key_type value_type;
227 typedef Compare key_compare;
228 typedef key_compare value_compare;
229 typedef Allocator allocator_type;
230 typedef typename allocator_type::reference reference;
231 typedef typename allocator_type::const_reference const_reference;
232 typedef typename allocator_type::size_type size_type;
233 typedef typename allocator_type::difference_type difference_type;
234 typedef typename allocator_type::pointer pointer;
235 typedef typename allocator_type::const_pointer const_pointer;
236
237 typedef implementation-defined iterator;
238 typedef implementation-defined const_iterator;
239 typedef std::reverse_iterator<iterator> reverse_iterator;
240 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000241 typedef unspecified node_type; // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000242
243 // construct/copy/destroy:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000244 multiset()
245 noexcept(
246 is_nothrow_default_constructible<allocator_type>::value &&
247 is_nothrow_default_constructible<key_compare>::value &&
248 is_nothrow_copy_constructible<key_compare>::value);
249 explicit multiset(const value_compare& comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000250 multiset(const value_compare& comp, const allocator_type& a);
251 template <class InputIterator>
252 multiset(InputIterator first, InputIterator last,
253 const value_compare& comp = value_compare());
254 template <class InputIterator>
255 multiset(InputIterator first, InputIterator last,
256 const value_compare& comp, const allocator_type& a);
257 multiset(const multiset& s);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000258 multiset(multiset&& s)
259 noexcept(
260 is_nothrow_move_constructible<allocator_type>::value &&
261 is_nothrow_move_constructible<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000262 explicit multiset(const allocator_type& a);
263 multiset(const multiset& s, const allocator_type& a);
264 multiset(multiset&& s, const allocator_type& a);
265 multiset(initializer_list<value_type> il, const value_compare& comp = value_compare());
266 multiset(initializer_list<value_type> il, const value_compare& comp,
267 const allocator_type& a);
Marshall Clow631788a2013-09-11 00:06:45 +0000268 template <class InputIterator>
269 multiset(InputIterator first, InputIterator last, const allocator_type& a)
270 : set(first, last, Compare(), a) {} // C++14
271 multiset(initializer_list<value_type> il, const allocator_type& a)
272 : set(il, Compare(), a) {} // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000273 ~multiset();
274
275 multiset& operator=(const multiset& s);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000276 multiset& operator=(multiset&& s)
277 noexcept(
278 allocator_type::propagate_on_container_move_assignment::value &&
279 is_nothrow_move_assignable<allocator_type>::value &&
280 is_nothrow_move_assignable<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000281 multiset& operator=(initializer_list<value_type> il);
282
283 // iterators:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000284 iterator begin() noexcept;
285 const_iterator begin() const noexcept;
286 iterator end() noexcept;
287 const_iterator end() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000288
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000289 reverse_iterator rbegin() noexcept;
290 const_reverse_iterator rbegin() const noexcept;
291 reverse_iterator rend() noexcept;
292 const_reverse_iterator rend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000293
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000294 const_iterator cbegin() const noexcept;
295 const_iterator cend() const noexcept;
296 const_reverse_iterator crbegin() const noexcept;
297 const_reverse_iterator crend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000298
299 // capacity:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000300 bool empty() const noexcept;
301 size_type size() const noexcept;
302 size_type max_size() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000303
304 // modifiers:
305 template <class... Args>
306 iterator emplace(Args&&... args);
307 template <class... Args>
308 iterator emplace_hint(const_iterator position, Args&&... args);
309 iterator insert(const value_type& v);
310 iterator insert(value_type&& v);
311 iterator insert(const_iterator position, const value_type& v);
312 iterator insert(const_iterator position, value_type&& v);
313 template <class InputIterator>
314 void insert(InputIterator first, InputIterator last);
315 void insert(initializer_list<value_type> il);
316
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000317 node_type extract(const_iterator position); // C++17
318 node_type extract(const key_type& x); // C++17
319 iterator insert(node_type&& nh); // C++17
320 iterator insert(const_iterator hint, node_type&& nh); // C++17
321
Howard Hinnantc51e1022010-05-11 19:42:16 +0000322 iterator erase(const_iterator position);
Marshall Clow22ea5b82015-05-10 13:35:00 +0000323 iterator erase(iterator position); // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000324 size_type erase(const key_type& k);
325 iterator erase(const_iterator first, const_iterator last);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000326 void clear() noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000327
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000328 template<class C2>
329 void merge(multiset<Key, C2, Allocator>& source); // C++17
330 template<class C2>
331 void merge(multiset<Key, C2, Allocator>&& source); // C++17
332 template<class C2>
333 void merge(set<Key, C2, Allocator>& source); // C++17
334 template<class C2>
335 void merge(set<Key, C2, Allocator>&& source); // C++17
336
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000337 void swap(multiset& s)
338 noexcept(
339 __is_nothrow_swappable<key_compare>::value &&
340 (!allocator_type::propagate_on_container_swap::value ||
341 __is_nothrow_swappable<allocator_type>::value));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000342
343 // observers:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000344 allocator_type get_allocator() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000345 key_compare key_comp() const;
346 value_compare value_comp() const;
347
348 // set operations:
349 iterator find(const key_type& k);
350 const_iterator find(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000351 template<typename K>
352 iterator find(const K& x);
353 template<typename K>
354 const_iterator find(const K& x) const; // C++14
355
Howard Hinnantc51e1022010-05-11 19:42:16 +0000356 size_type count(const key_type& k) const;
357 iterator lower_bound(const key_type& k);
358 const_iterator lower_bound(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000359 template<typename K>
360 iterator lower_bound(const K& x); // C++14
361 template<typename K>
362 const_iterator lower_bound(const K& x) const; // C++14
363
Howard Hinnantc51e1022010-05-11 19:42:16 +0000364 iterator upper_bound(const key_type& k);
365 const_iterator upper_bound(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000366 template<typename K>
367 iterator upper_bound(const K& x); // C++14
368 template<typename K>
369 const_iterator upper_bound(const K& x) const; // C++14
370
Howard Hinnantc51e1022010-05-11 19:42:16 +0000371 pair<iterator,iterator> equal_range(const key_type& k);
372 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000373 template<typename K>
374 pair<iterator,iterator> equal_range(const K& x); // C++14
375 template<typename K>
376 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000377};
378
379template <class Key, class Compare, class Allocator>
380bool
381operator==(const multiset<Key, Compare, Allocator>& x,
382 const multiset<Key, Compare, Allocator>& y);
383
384template <class Key, class Compare, class Allocator>
385bool
386operator< (const multiset<Key, Compare, Allocator>& x,
387 const multiset<Key, Compare, Allocator>& y);
388
389template <class Key, class Compare, class Allocator>
390bool
391operator!=(const multiset<Key, Compare, Allocator>& x,
392 const multiset<Key, Compare, Allocator>& y);
393
394template <class Key, class Compare, class Allocator>
395bool
396operator> (const multiset<Key, Compare, Allocator>& x,
397 const multiset<Key, Compare, Allocator>& y);
398
399template <class Key, class Compare, class Allocator>
400bool
401operator>=(const multiset<Key, Compare, Allocator>& x,
402 const multiset<Key, Compare, Allocator>& y);
403
404template <class Key, class Compare, class Allocator>
405bool
406operator<=(const multiset<Key, Compare, Allocator>& x,
407 const multiset<Key, Compare, Allocator>& y);
408
409// specialized algorithms:
410template <class Key, class Compare, class Allocator>
411void
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000412swap(multiset<Key, Compare, Allocator>& x, multiset<Key, Compare, Allocator>& y)
413 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000414
415} // std
416
417*/
418
419#include <__config>
420#include <__tree>
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000421#include <__node_handle>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000422#include <functional>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000423#include <version>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000424
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000425#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000426#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000427#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000428
429_LIBCPP_BEGIN_NAMESPACE_STD
430
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000431template <class _Key, class _Compare, class _Allocator>
432class multiset;
433
Howard Hinnantc51e1022010-05-11 19:42:16 +0000434template <class _Key, class _Compare = less<_Key>,
435 class _Allocator = allocator<_Key> >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000436class _LIBCPP_TEMPLATE_VIS set
Howard Hinnantc51e1022010-05-11 19:42:16 +0000437{
438public:
439 // types:
440 typedef _Key key_type;
441 typedef key_type value_type;
442 typedef _Compare key_compare;
443 typedef key_compare value_compare;
444 typedef _Allocator allocator_type;
445 typedef value_type& reference;
446 typedef const value_type& const_reference;
447
Louis Dionne878a3a82018-12-06 21:46:17 +0000448 static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), "");
Marshall Clow5128cf32015-11-26 01:24:04 +0000449 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
450 "Allocator::value_type must be same type as value_type");
451
Howard Hinnantc51e1022010-05-11 19:42:16 +0000452private:
453 typedef __tree<value_type, value_compare, allocator_type> __base;
454 typedef allocator_traits<allocator_type> __alloc_traits;
455 typedef typename __base::__node_holder __node_holder;
456
457 __base __tree_;
458
459public:
460 typedef typename __base::pointer pointer;
461 typedef typename __base::const_pointer const_pointer;
462 typedef typename __base::size_type size_type;
463 typedef typename __base::difference_type difference_type;
464 typedef typename __base::const_iterator iterator;
465 typedef typename __base::const_iterator const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000466 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
467 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000468
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000469#if _LIBCPP_STD_VER > 14
470 typedef __set_node_handle<typename __base::__node, allocator_type> node_type;
471 typedef __insert_return_type<iterator, node_type> insert_return_type;
472#endif
473
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000474 template <class _Key2, class _Compare2, class _Alloc2>
475 friend class _LIBCPP_TEMPLATE_VIS set;
476 template <class _Key2, class _Compare2, class _Alloc2>
477 friend class _LIBCPP_TEMPLATE_VIS multiset;
478
Howard Hinnant192cf032010-09-23 16:27:36 +0000479 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +0000480 set()
481 _NOEXCEPT_(
482 is_nothrow_default_constructible<allocator_type>::value &&
483 is_nothrow_default_constructible<key_compare>::value &&
484 is_nothrow_copy_constructible<key_compare>::value)
485 : __tree_(value_compare()) {}
486
487 _LIBCPP_INLINE_VISIBILITY
488 explicit set(const value_compare& __comp)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000489 _NOEXCEPT_(
490 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000491 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000492 : __tree_(__comp) {}
Marshall Clow7086a5a2014-03-10 04:50:10 +0000493
Howard Hinnant192cf032010-09-23 16:27:36 +0000494 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7ed23a72014-03-05 19:06:20 +0000495 explicit set(const value_compare& __comp, const allocator_type& __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000496 : __tree_(__comp, __a) {}
497 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000498 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000499 set(_InputIterator __f, _InputIterator __l,
500 const value_compare& __comp = value_compare())
501 : __tree_(__comp)
502 {
503 insert(__f, __l);
504 }
505
506 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000507 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000508 set(_InputIterator __f, _InputIterator __l, const value_compare& __comp,
509 const allocator_type& __a)
510 : __tree_(__comp, __a)
511 {
512 insert(__f, __l);
513 }
514
Marshall Clow631788a2013-09-11 00:06:45 +0000515#if _LIBCPP_STD_VER > 11
516 template <class _InputIterator>
Louis Dionned2322c82018-11-01 14:41:37 +0000517 _LIBCPP_INLINE_VISIBILITY
Marshall Clow631788a2013-09-11 00:06:45 +0000518 set(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
519 : set(__f, __l, key_compare(), __a) {}
520#endif
521
Howard Hinnant192cf032010-09-23 16:27:36 +0000522 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000523 set(const set& __s)
524 : __tree_(__s.__tree_)
525 {
526 insert(__s.begin(), __s.end());
527 }
528
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000529 _LIBCPP_INLINE_VISIBILITY
530 set& operator=(const set& __s)
531 {
532 __tree_ = __s.__tree_;
533 return *this;
534 }
535
Eric Fiselier615961b2017-04-18 20:58:03 +0000536#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant192cf032010-09-23 16:27:36 +0000537 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000538 set(set&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000539 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000540 : __tree_(_VSTD::move(__s.__tree_)) {}
Eric Fiselier615961b2017-04-18 20:58:03 +0000541#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000542
Howard Hinnant192cf032010-09-23 16:27:36 +0000543 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000544 explicit set(const allocator_type& __a)
545 : __tree_(__a) {}
546
Howard Hinnant192cf032010-09-23 16:27:36 +0000547 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000548 set(const set& __s, const allocator_type& __a)
549 : __tree_(__s.__tree_.value_comp(), __a)
550 {
551 insert(__s.begin(), __s.end());
552 }
553
Eric Fiselier615961b2017-04-18 20:58:03 +0000554#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000555 set(set&& __s, const allocator_type& __a);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000556
Howard Hinnant192cf032010-09-23 16:27:36 +0000557 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000558 set(initializer_list<value_type> __il, const value_compare& __comp = value_compare())
559 : __tree_(__comp)
560 {
561 insert(__il.begin(), __il.end());
562 }
563
Howard Hinnant192cf032010-09-23 16:27:36 +0000564 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000565 set(initializer_list<value_type> __il, const value_compare& __comp,
566 const allocator_type& __a)
567 : __tree_(__comp, __a)
568 {
569 insert(__il.begin(), __il.end());
570 }
571
Marshall Clow631788a2013-09-11 00:06:45 +0000572#if _LIBCPP_STD_VER > 11
Louis Dionned2322c82018-11-01 14:41:37 +0000573 _LIBCPP_INLINE_VISIBILITY
Marshall Clow631788a2013-09-11 00:06:45 +0000574 set(initializer_list<value_type> __il, const allocator_type& __a)
575 : set(__il, key_compare(), __a) {}
576#endif
577
Howard Hinnant192cf032010-09-23 16:27:36 +0000578 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000579 set& operator=(initializer_list<value_type> __il)
580 {
581 __tree_.__assign_unique(__il.begin(), __il.end());
582 return *this;
583 }
584
Howard Hinnant192cf032010-09-23 16:27:36 +0000585 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000586 set& operator=(set&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000587 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000588 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000589 __tree_ = _VSTD::move(__s.__tree_);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000590 return *this;
591 }
Eric Fiselier615961b2017-04-18 20:58:03 +0000592#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000593
Howard Hinnant192cf032010-09-23 16:27:36 +0000594 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000595 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000596 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000597 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000598 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000599 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000600 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000601 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000602
Howard Hinnant192cf032010-09-23 16:27:36 +0000603 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000604 reverse_iterator rbegin() _NOEXCEPT
605 {return reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +0000606 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000607 const_reverse_iterator rbegin() const _NOEXCEPT
608 {return const_reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +0000609 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000610 reverse_iterator rend() _NOEXCEPT
611 {return reverse_iterator(begin());}
Howard Hinnant192cf032010-09-23 16:27:36 +0000612 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000613 const_reverse_iterator rend() const _NOEXCEPT
614 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000615
Howard Hinnant192cf032010-09-23 16:27:36 +0000616 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000617 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000618 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000619 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000620 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000621 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000622 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000623 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000624
Marshall Clow425f5752017-11-15 05:51:26 +0000625 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000626 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant192cf032010-09-23 16:27:36 +0000627 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000628 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000629 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000630 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000631
632 // modifiers:
Eric Fiselier615961b2017-04-18 20:58:03 +0000633#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000634 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +0000635 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000636 pair<iterator, bool> emplace(_Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000637 {return __tree_.__emplace_unique(_VSTD::forward<_Args>(__args)...);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000638 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +0000639 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000640 iterator emplace_hint(const_iterator __p, _Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000641 {return __tree_.__emplace_hint_unique(__p, _VSTD::forward<_Args>(__args)...);}
Eric Fiselier615961b2017-04-18 20:58:03 +0000642#endif // _LIBCPP_CXX03_LANG
643
Howard Hinnant192cf032010-09-23 16:27:36 +0000644 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000645 pair<iterator,bool> insert(const value_type& __v)
646 {return __tree_.__insert_unique(__v);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000647 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000648 iterator insert(const_iterator __p, const value_type& __v)
649 {return __tree_.__insert_unique(__p, __v);}
Eric Fiselier615961b2017-04-18 20:58:03 +0000650
Howard Hinnantc51e1022010-05-11 19:42:16 +0000651 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000652 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000653 void insert(_InputIterator __f, _InputIterator __l)
654 {
655 for (const_iterator __e = cend(); __f != __l; ++__f)
656 __tree_.__insert_unique(__e, *__f);
657 }
658
Eric Fiselier615961b2017-04-18 20:58:03 +0000659#ifndef _LIBCPP_CXX03_LANG
660 _LIBCPP_INLINE_VISIBILITY
661 pair<iterator,bool> insert(value_type&& __v)
662 {return __tree_.__insert_unique(_VSTD::move(__v));}
663
664 _LIBCPP_INLINE_VISIBILITY
665 iterator insert(const_iterator __p, value_type&& __v)
666 {return __tree_.__insert_unique(__p, _VSTD::move(__v));}
667
Howard Hinnant192cf032010-09-23 16:27:36 +0000668 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000669 void insert(initializer_list<value_type> __il)
670 {insert(__il.begin(), __il.end());}
Eric Fiselier615961b2017-04-18 20:58:03 +0000671#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000672
Howard Hinnant192cf032010-09-23 16:27:36 +0000673 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000674 iterator erase(const_iterator __p) {return __tree_.erase(__p);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000675 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000676 size_type erase(const key_type& __k)
677 {return __tree_.__erase_unique(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000678 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000679 iterator erase(const_iterator __f, const_iterator __l)
680 {return __tree_.erase(__f, __l);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000681 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000682 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000683
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000684#if _LIBCPP_STD_VER > 14
685 _LIBCPP_INLINE_VISIBILITY
686 insert_return_type insert(node_type&& __nh)
687 {
688 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
689 "node_type with incompatible allocator passed to set::insert()");
690 return __tree_.template __node_handle_insert_unique<
691 node_type, insert_return_type>(_VSTD::move(__nh));
692 }
693 _LIBCPP_INLINE_VISIBILITY
694 iterator insert(const_iterator __hint, node_type&& __nh)
695 {
696 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
697 "node_type with incompatible allocator passed to set::insert()");
698 return __tree_.template __node_handle_insert_unique<node_type>(
699 __hint, _VSTD::move(__nh));
700 }
701 _LIBCPP_INLINE_VISIBILITY
702 node_type extract(key_type const& __key)
703 {
704 return __tree_.template __node_handle_extract<node_type>(__key);
705 }
706 _LIBCPP_INLINE_VISIBILITY
707 node_type extract(const_iterator __it)
708 {
709 return __tree_.template __node_handle_extract<node_type>(__it);
710 }
Louis Dionned2322c82018-11-01 14:41:37 +0000711 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000712 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +0000713 void merge(set<key_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000714 {
715 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
716 "merging container with incompatible allocator");
717 __tree_.__node_handle_merge_unique(__source.__tree_);
718 }
Louis Dionned2322c82018-11-01 14:41:37 +0000719 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000720 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +0000721 void merge(set<key_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000722 {
723 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
724 "merging container with incompatible allocator");
725 __tree_.__node_handle_merge_unique(__source.__tree_);
726 }
Louis Dionned2322c82018-11-01 14:41:37 +0000727 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000728 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +0000729 void merge(multiset<key_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000730 {
731 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
732 "merging container with incompatible allocator");
733 __tree_.__node_handle_merge_unique(__source.__tree_);
734 }
Louis Dionned2322c82018-11-01 14:41:37 +0000735 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000736 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +0000737 void merge(multiset<key_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000738 {
739 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
740 "merging container with incompatible allocator");
741 __tree_.__node_handle_merge_unique(__source.__tree_);
742 }
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000743#endif
744
Howard Hinnant192cf032010-09-23 16:27:36 +0000745 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000746 void swap(set& __s) _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
747 {__tree_.swap(__s.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000748
Howard Hinnant192cf032010-09-23 16:27:36 +0000749 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000750 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000751 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000752 key_compare key_comp() const {return __tree_.value_comp();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000753 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000754 value_compare value_comp() const {return __tree_.value_comp();}
755
756 // set operations:
Howard Hinnant192cf032010-09-23 16:27:36 +0000757 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000758 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000759 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000760 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000761#if _LIBCPP_STD_VER > 11
762 template <typename _K2>
763 _LIBCPP_INLINE_VISIBILITY
764 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
765 find(const _K2& __k) {return __tree_.find(__k);}
766 template <typename _K2>
767 _LIBCPP_INLINE_VISIBILITY
768 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
769 find(const _K2& __k) const {return __tree_.find(__k);}
770#endif
771
Howard Hinnant192cf032010-09-23 16:27:36 +0000772 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000773 size_type count(const key_type& __k) const
774 {return __tree_.__count_unique(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +0000775#if _LIBCPP_STD_VER > 11
776 template <typename _K2>
777 _LIBCPP_INLINE_VISIBILITY
778 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +0000779 count(const _K2& __k) const {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +0000780#endif
Howard Hinnant192cf032010-09-23 16:27:36 +0000781 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000782 iterator lower_bound(const key_type& __k)
783 {return __tree_.lower_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000784 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000785 const_iterator lower_bound(const key_type& __k) const
786 {return __tree_.lower_bound(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000787#if _LIBCPP_STD_VER > 11
788 template <typename _K2>
789 _LIBCPP_INLINE_VISIBILITY
790 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
791 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
792
793 template <typename _K2>
794 _LIBCPP_INLINE_VISIBILITY
795 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
796 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
797#endif
798
Howard Hinnant192cf032010-09-23 16:27:36 +0000799 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000800 iterator upper_bound(const key_type& __k)
801 {return __tree_.upper_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000802 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000803 const_iterator upper_bound(const key_type& __k) const
804 {return __tree_.upper_bound(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000805#if _LIBCPP_STD_VER > 11
806 template <typename _K2>
807 _LIBCPP_INLINE_VISIBILITY
808 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
809 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
810 template <typename _K2>
811 _LIBCPP_INLINE_VISIBILITY
812 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
813 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
814#endif
815
Howard Hinnant192cf032010-09-23 16:27:36 +0000816 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000817 pair<iterator,iterator> equal_range(const key_type& __k)
818 {return __tree_.__equal_range_unique(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000819 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000820 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
821 {return __tree_.__equal_range_unique(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000822#if _LIBCPP_STD_VER > 11
823 template <typename _K2>
824 _LIBCPP_INLINE_VISIBILITY
825 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +0000826 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000827 template <typename _K2>
828 _LIBCPP_INLINE_VISIBILITY
829 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +0000830 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000831#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000832};
833
Eric Fiselier615961b2017-04-18 20:58:03 +0000834#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000835
836template <class _Key, class _Compare, class _Allocator>
837set<_Key, _Compare, _Allocator>::set(set&& __s, const allocator_type& __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000838 : __tree_(_VSTD::move(__s.__tree_), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000839{
840 if (__a != __s.get_allocator())
841 {
842 const_iterator __e = cend();
843 while (!__s.empty())
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000844 insert(__e, _VSTD::move(__s.__tree_.remove(__s.begin())->__value_));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000845 }
846}
847
Eric Fiselier615961b2017-04-18 20:58:03 +0000848#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000849
850template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000851inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000852bool
853operator==(const set<_Key, _Compare, _Allocator>& __x,
854 const set<_Key, _Compare, _Allocator>& __y)
855{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000856 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000857}
858
859template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000860inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000861bool
862operator< (const set<_Key, _Compare, _Allocator>& __x,
863 const set<_Key, _Compare, _Allocator>& __y)
864{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000865 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000866}
867
868template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000869inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000870bool
871operator!=(const set<_Key, _Compare, _Allocator>& __x,
872 const set<_Key, _Compare, _Allocator>& __y)
873{
874 return !(__x == __y);
875}
876
877template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000878inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000879bool
880operator> (const set<_Key, _Compare, _Allocator>& __x,
881 const set<_Key, _Compare, _Allocator>& __y)
882{
883 return __y < __x;
884}
885
886template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000887inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000888bool
889operator>=(const set<_Key, _Compare, _Allocator>& __x,
890 const set<_Key, _Compare, _Allocator>& __y)
891{
892 return !(__x < __y);
893}
894
895template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000896inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000897bool
898operator<=(const set<_Key, _Compare, _Allocator>& __x,
899 const set<_Key, _Compare, _Allocator>& __y)
900{
901 return !(__y < __x);
902}
903
904// specialized algorithms:
905template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000906inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000907void
908swap(set<_Key, _Compare, _Allocator>& __x,
909 set<_Key, _Compare, _Allocator>& __y)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000910 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000911{
912 __x.swap(__y);
913}
914
Howard Hinnantc51e1022010-05-11 19:42:16 +0000915template <class _Key, class _Compare = less<_Key>,
916 class _Allocator = allocator<_Key> >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000917class _LIBCPP_TEMPLATE_VIS multiset
Howard Hinnantc51e1022010-05-11 19:42:16 +0000918{
919public:
920 // types:
921 typedef _Key key_type;
922 typedef key_type value_type;
923 typedef _Compare key_compare;
924 typedef key_compare value_compare;
925 typedef _Allocator allocator_type;
926 typedef value_type& reference;
927 typedef const value_type& const_reference;
928
Louis Dionne878a3a82018-12-06 21:46:17 +0000929 static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), "");
Marshall Clow5128cf32015-11-26 01:24:04 +0000930 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
931 "Allocator::value_type must be same type as value_type");
932
Howard Hinnantc51e1022010-05-11 19:42:16 +0000933private:
934 typedef __tree<value_type, value_compare, allocator_type> __base;
935 typedef allocator_traits<allocator_type> __alloc_traits;
936 typedef typename __base::__node_holder __node_holder;
937
938 __base __tree_;
939
940public:
941 typedef typename __base::pointer pointer;
942 typedef typename __base::const_pointer const_pointer;
943 typedef typename __base::size_type size_type;
944 typedef typename __base::difference_type difference_type;
945 typedef typename __base::const_iterator iterator;
946 typedef typename __base::const_iterator const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000947 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
948 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000949
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000950#if _LIBCPP_STD_VER > 14
951 typedef __set_node_handle<typename __base::__node, allocator_type> node_type;
952#endif
953
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000954 template <class _Key2, class _Compare2, class _Alloc2>
955 friend class _LIBCPP_TEMPLATE_VIS set;
956 template <class _Key2, class _Compare2, class _Alloc2>
957 friend class _LIBCPP_TEMPLATE_VIS multiset;
958
Howard Hinnantc51e1022010-05-11 19:42:16 +0000959 // construct/copy/destroy:
Howard Hinnant192cf032010-09-23 16:27:36 +0000960 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +0000961 multiset()
962 _NOEXCEPT_(
963 is_nothrow_default_constructible<allocator_type>::value &&
964 is_nothrow_default_constructible<key_compare>::value &&
965 is_nothrow_copy_constructible<key_compare>::value)
966 : __tree_(value_compare()) {}
967
968 _LIBCPP_INLINE_VISIBILITY
969 explicit multiset(const value_compare& __comp)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000970 _NOEXCEPT_(
971 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000972 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000973 : __tree_(__comp) {}
Marshall Clow7086a5a2014-03-10 04:50:10 +0000974
Howard Hinnant192cf032010-09-23 16:27:36 +0000975 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7ed23a72014-03-05 19:06:20 +0000976 explicit multiset(const value_compare& __comp, const allocator_type& __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000977 : __tree_(__comp, __a) {}
978 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000979 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000980 multiset(_InputIterator __f, _InputIterator __l,
981 const value_compare& __comp = value_compare())
982 : __tree_(__comp)
983 {
984 insert(__f, __l);
985 }
986
Marshall Clow631788a2013-09-11 00:06:45 +0000987#if _LIBCPP_STD_VER > 11
988 template <class _InputIterator>
Louis Dionned2322c82018-11-01 14:41:37 +0000989 _LIBCPP_INLINE_VISIBILITY
Marshall Clow631788a2013-09-11 00:06:45 +0000990 multiset(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
991 : multiset(__f, __l, key_compare(), __a) {}
992#endif
993
Howard Hinnantc51e1022010-05-11 19:42:16 +0000994 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000995 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000996 multiset(_InputIterator __f, _InputIterator __l,
997 const value_compare& __comp, const allocator_type& __a)
998 : __tree_(__comp, __a)
999 {
1000 insert(__f, __l);
1001 }
1002
Howard Hinnant192cf032010-09-23 16:27:36 +00001003 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001004 multiset(const multiset& __s)
1005 : __tree_(__s.__tree_.value_comp(),
1006 __alloc_traits::select_on_container_copy_construction(__s.__tree_.__alloc()))
1007 {
1008 insert(__s.begin(), __s.end());
1009 }
1010
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001011 _LIBCPP_INLINE_VISIBILITY
1012 multiset& operator=(const multiset& __s)
1013 {
1014 __tree_ = __s.__tree_;
1015 return *this;
1016 }
1017
Eric Fiselier615961b2017-04-18 20:58:03 +00001018#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant192cf032010-09-23 16:27:36 +00001019 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001020 multiset(multiset&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001021 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001022 : __tree_(_VSTD::move(__s.__tree_)) {}
Eric Fiselier615961b2017-04-18 20:58:03 +00001023
1024 multiset(multiset&& __s, const allocator_type& __a);
1025#endif // _LIBCPP_CXX03_LANG
Howard Hinnant192cf032010-09-23 16:27:36 +00001026 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001027 explicit multiset(const allocator_type& __a)
1028 : __tree_(__a) {}
Howard Hinnant192cf032010-09-23 16:27:36 +00001029 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001030 multiset(const multiset& __s, const allocator_type& __a)
1031 : __tree_(__s.__tree_.value_comp(), __a)
1032 {
1033 insert(__s.begin(), __s.end());
1034 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001035
Eric Fiselier615961b2017-04-18 20:58:03 +00001036#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant192cf032010-09-23 16:27:36 +00001037 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001038 multiset(initializer_list<value_type> __il, const value_compare& __comp = value_compare())
1039 : __tree_(__comp)
1040 {
1041 insert(__il.begin(), __il.end());
1042 }
1043
Howard Hinnant192cf032010-09-23 16:27:36 +00001044 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001045 multiset(initializer_list<value_type> __il, const value_compare& __comp,
1046 const allocator_type& __a)
1047 : __tree_(__comp, __a)
1048 {
1049 insert(__il.begin(), __il.end());
1050 }
1051
Marshall Clow631788a2013-09-11 00:06:45 +00001052#if _LIBCPP_STD_VER > 11
Louis Dionned2322c82018-11-01 14:41:37 +00001053 _LIBCPP_INLINE_VISIBILITY
Marshall Clow631788a2013-09-11 00:06:45 +00001054 multiset(initializer_list<value_type> __il, const allocator_type& __a)
1055 : multiset(__il, key_compare(), __a) {}
1056#endif
1057
Howard Hinnant192cf032010-09-23 16:27:36 +00001058 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001059 multiset& operator=(initializer_list<value_type> __il)
1060 {
1061 __tree_.__assign_multi(__il.begin(), __il.end());
1062 return *this;
1063 }
1064
Howard Hinnant192cf032010-09-23 16:27:36 +00001065 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001066 multiset& operator=(multiset&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001067 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001068 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001069 __tree_ = _VSTD::move(__s.__tree_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001070 return *this;
1071 }
Eric Fiselier615961b2017-04-18 20:58:03 +00001072#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001073
Howard Hinnant192cf032010-09-23 16:27:36 +00001074 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001075 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001076 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001077 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001078 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001079 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001080 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001081 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001082
Howard Hinnant192cf032010-09-23 16:27:36 +00001083 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001084 reverse_iterator rbegin() _NOEXCEPT
1085 {return reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +00001086 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001087 const_reverse_iterator rbegin() const _NOEXCEPT
1088 {return const_reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +00001089 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001090 reverse_iterator rend() _NOEXCEPT
1091 {return reverse_iterator(begin());}
Howard Hinnant192cf032010-09-23 16:27:36 +00001092 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001093 const_reverse_iterator rend() const _NOEXCEPT
1094 {return const_reverse_iterator(begin());}
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 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001098 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001099 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001100 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001101 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001102 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001103 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001104
Marshall Clow425f5752017-11-15 05:51:26 +00001105 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001106 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant192cf032010-09-23 16:27:36 +00001107 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001108 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001109 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001110 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001111
1112 // modifiers:
Eric Fiselier615961b2017-04-18 20:58:03 +00001113#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001114 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +00001115 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001116 iterator emplace(_Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001117 {return __tree_.__emplace_multi(_VSTD::forward<_Args>(__args)...);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001118 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +00001119 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001120 iterator emplace_hint(const_iterator __p, _Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001121 {return __tree_.__emplace_hint_multi(__p, _VSTD::forward<_Args>(__args)...);}
Eric Fiselier615961b2017-04-18 20:58:03 +00001122#endif // _LIBCPP_CXX03_LANG
1123
Howard Hinnant192cf032010-09-23 16:27:36 +00001124 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001125 iterator insert(const value_type& __v)
1126 {return __tree_.__insert_multi(__v);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001127 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001128 iterator insert(const_iterator __p, const value_type& __v)
1129 {return __tree_.__insert_multi(__p, __v);}
Eric Fiselier615961b2017-04-18 20:58:03 +00001130
Howard Hinnantc51e1022010-05-11 19:42:16 +00001131 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001132 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001133 void insert(_InputIterator __f, _InputIterator __l)
1134 {
1135 for (const_iterator __e = cend(); __f != __l; ++__f)
1136 __tree_.__insert_multi(__e, *__f);
1137 }
1138
Eric Fiselier615961b2017-04-18 20:58:03 +00001139#ifndef _LIBCPP_CXX03_LANG
1140 _LIBCPP_INLINE_VISIBILITY
1141 iterator insert(value_type&& __v)
1142 {return __tree_.__insert_multi(_VSTD::move(__v));}
1143
1144 _LIBCPP_INLINE_VISIBILITY
1145 iterator insert(const_iterator __p, value_type&& __v)
1146 {return __tree_.__insert_multi(__p, _VSTD::move(__v));}
1147
Howard Hinnant192cf032010-09-23 16:27:36 +00001148 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001149 void insert(initializer_list<value_type> __il)
1150 {insert(__il.begin(), __il.end());}
Eric Fiselier615961b2017-04-18 20:58:03 +00001151#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001152
Howard Hinnant192cf032010-09-23 16:27:36 +00001153 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001154 iterator erase(const_iterator __p) {return __tree_.erase(__p);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001155 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001156 size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001157 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001158 iterator erase(const_iterator __f, const_iterator __l)
1159 {return __tree_.erase(__f, __l);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001160 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001161 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001162
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001163#if _LIBCPP_STD_VER > 14
1164 _LIBCPP_INLINE_VISIBILITY
1165 iterator insert(node_type&& __nh)
1166 {
1167 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1168 "node_type with incompatible allocator passed to multiset::insert()");
1169 return __tree_.template __node_handle_insert_multi<node_type>(
1170 _VSTD::move(__nh));
1171 }
1172 _LIBCPP_INLINE_VISIBILITY
1173 iterator insert(const_iterator __hint, node_type&& __nh)
1174 {
1175 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1176 "node_type with incompatible allocator passed to multiset::insert()");
1177 return __tree_.template __node_handle_insert_multi<node_type>(
1178 __hint, _VSTD::move(__nh));
1179 }
1180 _LIBCPP_INLINE_VISIBILITY
1181 node_type extract(key_type const& __key)
1182 {
1183 return __tree_.template __node_handle_extract<node_type>(__key);
1184 }
1185 _LIBCPP_INLINE_VISIBILITY
1186 node_type extract(const_iterator __it)
1187 {
1188 return __tree_.template __node_handle_extract<node_type>(__it);
1189 }
Louis Dionned2322c82018-11-01 14:41:37 +00001190 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001191 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001192 void merge(multiset<key_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001193 {
1194 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1195 "merging container with incompatible allocator");
1196 __tree_.__node_handle_merge_multi(__source.__tree_);
1197 }
Louis Dionned2322c82018-11-01 14:41:37 +00001198 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001199 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001200 void merge(multiset<key_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001201 {
1202 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1203 "merging container with incompatible allocator");
1204 __tree_.__node_handle_merge_multi(__source.__tree_);
1205 }
Louis Dionned2322c82018-11-01 14:41:37 +00001206 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001207 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001208 void merge(set<key_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001209 {
1210 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1211 "merging container with incompatible allocator");
1212 __tree_.__node_handle_merge_multi(__source.__tree_);
1213 }
Louis Dionned2322c82018-11-01 14:41:37 +00001214 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001215 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001216 void merge(set<key_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001217 {
1218 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1219 "merging container with incompatible allocator");
1220 __tree_.__node_handle_merge_multi(__source.__tree_);
1221 }
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001222#endif
1223
Howard Hinnant192cf032010-09-23 16:27:36 +00001224 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001225 void swap(multiset& __s)
1226 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1227 {__tree_.swap(__s.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001228
Howard Hinnant192cf032010-09-23 16:27:36 +00001229 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001230 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001231 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001232 key_compare key_comp() const {return __tree_.value_comp();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001233 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001234 value_compare value_comp() const {return __tree_.value_comp();}
1235
1236 // set operations:
Howard Hinnant192cf032010-09-23 16:27:36 +00001237 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001238 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001239 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001240 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +00001241#if _LIBCPP_STD_VER > 11
1242 template <typename _K2>
1243 _LIBCPP_INLINE_VISIBILITY
1244 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,iterator>::type
1245 find(const _K2& __k) {return __tree_.find(__k);}
1246 template <typename _K2>
1247 _LIBCPP_INLINE_VISIBILITY
1248 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,const_iterator>::type
1249 find(const _K2& __k) const {return __tree_.find(__k);}
1250#endif
1251
Howard Hinnant192cf032010-09-23 16:27:36 +00001252 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001253 size_type count(const key_type& __k) const
1254 {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001255#if _LIBCPP_STD_VER > 11
1256 template <typename _K2>
1257 _LIBCPP_INLINE_VISIBILITY
1258 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
Marshall Clow5571bcd2018-01-07 17:39:57 +00001259 count(const _K2& __k) const {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001260#endif
Marshall Clowc0152142013-08-13 01:11:06 +00001261
Howard Hinnant192cf032010-09-23 16:27:36 +00001262 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001263 iterator lower_bound(const key_type& __k)
1264 {return __tree_.lower_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001265 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001266 const_iterator lower_bound(const key_type& __k) const
1267 {return __tree_.lower_bound(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +00001268#if _LIBCPP_STD_VER > 11
1269 template <typename _K2>
1270 _LIBCPP_INLINE_VISIBILITY
1271 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,iterator>::type
1272 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
1273
1274 template <typename _K2>
1275 _LIBCPP_INLINE_VISIBILITY
1276 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,const_iterator>::type
1277 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
1278#endif
1279
Howard Hinnant192cf032010-09-23 16:27:36 +00001280 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001281 iterator upper_bound(const key_type& __k)
1282 {return __tree_.upper_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001283 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001284 const_iterator upper_bound(const key_type& __k) const
1285 {return __tree_.upper_bound(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +00001286#if _LIBCPP_STD_VER > 11
1287 template <typename _K2>
1288 _LIBCPP_INLINE_VISIBILITY
1289 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,iterator>::type
1290 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
1291 template <typename _K2>
1292 _LIBCPP_INLINE_VISIBILITY
1293 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,const_iterator>::type
1294 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
1295#endif
1296
Howard Hinnant192cf032010-09-23 16:27:36 +00001297 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001298 pair<iterator,iterator> equal_range(const key_type& __k)
1299 {return __tree_.__equal_range_multi(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001300 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001301 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
1302 {return __tree_.__equal_range_multi(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +00001303#if _LIBCPP_STD_VER > 11
1304 template <typename _K2>
1305 _LIBCPP_INLINE_VISIBILITY
1306 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
1307 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
1308 template <typename _K2>
1309 _LIBCPP_INLINE_VISIBILITY
1310 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
1311 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
1312#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001313};
1314
Eric Fiselier615961b2017-04-18 20:58:03 +00001315#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001316
1317template <class _Key, class _Compare, class _Allocator>
1318multiset<_Key, _Compare, _Allocator>::multiset(multiset&& __s, const allocator_type& __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001319 : __tree_(_VSTD::move(__s.__tree_), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001320{
1321 if (__a != __s.get_allocator())
1322 {
1323 const_iterator __e = cend();
1324 while (!__s.empty())
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001325 insert(__e, _VSTD::move(__s.__tree_.remove(__s.begin())->__value_));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001326 }
1327}
1328
Eric Fiselier615961b2017-04-18 20:58:03 +00001329#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001330
1331template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001332inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001333bool
1334operator==(const multiset<_Key, _Compare, _Allocator>& __x,
1335 const multiset<_Key, _Compare, _Allocator>& __y)
1336{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001337 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001338}
1339
1340template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001341inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001342bool
1343operator< (const multiset<_Key, _Compare, _Allocator>& __x,
1344 const multiset<_Key, _Compare, _Allocator>& __y)
1345{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001346 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001347}
1348
1349template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001350inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001351bool
1352operator!=(const multiset<_Key, _Compare, _Allocator>& __x,
1353 const multiset<_Key, _Compare, _Allocator>& __y)
1354{
1355 return !(__x == __y);
1356}
1357
1358template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001359inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001360bool
1361operator> (const multiset<_Key, _Compare, _Allocator>& __x,
1362 const multiset<_Key, _Compare, _Allocator>& __y)
1363{
1364 return __y < __x;
1365}
1366
1367template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001368inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001369bool
1370operator>=(const multiset<_Key, _Compare, _Allocator>& __x,
1371 const multiset<_Key, _Compare, _Allocator>& __y)
1372{
1373 return !(__x < __y);
1374}
1375
1376template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001377inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001378bool
1379operator<=(const multiset<_Key, _Compare, _Allocator>& __x,
1380 const multiset<_Key, _Compare, _Allocator>& __y)
1381{
1382 return !(__y < __x);
1383}
1384
1385template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001386inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001387void
1388swap(multiset<_Key, _Compare, _Allocator>& __x,
1389 multiset<_Key, _Compare, _Allocator>& __y)
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001390 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001391{
1392 __x.swap(__y);
1393}
1394
Howard Hinnantc51e1022010-05-11 19:42:16 +00001395_LIBCPP_END_NAMESPACE_STD
1396
1397#endif // _LIBCPP_SET