blob: 4574f69fa8ae9c67cba863b6e16b5899f1b871f6 [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===---------------------------- set -------------------------------------===//
3//
Chandler Carruthd2012102019-01-19 10:56:40 +00004// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Howard Hinnantc51e1022010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_SET
11#define _LIBCPP_SET
12
13/*
14
15 set synopsis
16
17namespace std
18{
19
20template <class Key, class Compare = less<Key>,
21 class Allocator = allocator<Key>>
22class set
23{
24public:
25 // types:
26 typedef Key key_type;
27 typedef key_type value_type;
28 typedef Compare key_compare;
29 typedef key_compare value_compare;
30 typedef Allocator allocator_type;
31 typedef typename allocator_type::reference reference;
32 typedef typename allocator_type::const_reference const_reference;
33 typedef typename allocator_type::size_type size_type;
34 typedef typename allocator_type::difference_type difference_type;
35 typedef typename allocator_type::pointer pointer;
36 typedef typename allocator_type::const_pointer const_pointer;
37
38 typedef implementation-defined iterator;
39 typedef implementation-defined const_iterator;
40 typedef std::reverse_iterator<iterator> reverse_iterator;
41 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +000042 typedef unspecified node_type; // C++17
43 typedef INSERT_RETURN_TYPE<iterator, node_type> insert_return_type; // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +000044
45 // construct/copy/destroy:
Howard Hinnantf95f4f52011-06-04 15:22:34 +000046 set()
47 noexcept(
48 is_nothrow_default_constructible<allocator_type>::value &&
49 is_nothrow_default_constructible<key_compare>::value &&
50 is_nothrow_copy_constructible<key_compare>::value);
51 explicit set(const value_compare& comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +000052 set(const value_compare& comp, const allocator_type& a);
53 template <class InputIterator>
54 set(InputIterator first, InputIterator last,
55 const value_compare& comp = value_compare());
56 template <class InputIterator>
57 set(InputIterator first, InputIterator last, const value_compare& comp,
58 const allocator_type& a);
59 set(const set& s);
Howard Hinnantf95f4f52011-06-04 15:22:34 +000060 set(set&& s)
61 noexcept(
62 is_nothrow_move_constructible<allocator_type>::value &&
63 is_nothrow_move_constructible<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +000064 explicit set(const allocator_type& a);
65 set(const set& s, const allocator_type& a);
66 set(set&& s, const allocator_type& a);
67 set(initializer_list<value_type> il, const value_compare& comp = value_compare());
68 set(initializer_list<value_type> il, const value_compare& comp,
69 const allocator_type& a);
Marshall Clow631788a2013-09-11 00:06:45 +000070 template <class InputIterator>
71 set(InputIterator first, InputIterator last, const allocator_type& a)
72 : set(first, last, Compare(), a) {} // C++14
73 set(initializer_list<value_type> il, const allocator_type& a)
74 : set(il, Compare(), a) {} // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000075 ~set();
76
77 set& operator=(const set& s);
Howard Hinnantf95f4f52011-06-04 15:22:34 +000078 set& operator=(set&& s)
79 noexcept(
80 allocator_type::propagate_on_container_move_assignment::value &&
81 is_nothrow_move_assignable<allocator_type>::value &&
82 is_nothrow_move_assignable<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +000083 set& operator=(initializer_list<value_type> il);
84
85 // iterators:
Howard Hinnantf95f4f52011-06-04 15:22:34 +000086 iterator begin() noexcept;
87 const_iterator begin() const noexcept;
88 iterator end() noexcept;
89 const_iterator end() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000090
Howard Hinnantf95f4f52011-06-04 15:22:34 +000091 reverse_iterator rbegin() noexcept;
92 const_reverse_iterator rbegin() const noexcept;
93 reverse_iterator rend() noexcept;
94 const_reverse_iterator rend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000095
Howard Hinnantf95f4f52011-06-04 15:22:34 +000096 const_iterator cbegin() const noexcept;
97 const_iterator cend() const noexcept;
98 const_reverse_iterator crbegin() const noexcept;
99 const_reverse_iterator crend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000100
101 // capacity:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000102 bool empty() const noexcept;
103 size_type size() const noexcept;
104 size_type max_size() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000105
106 // modifiers:
107 template <class... Args>
108 pair<iterator, bool> emplace(Args&&... args);
109 template <class... Args>
110 iterator emplace_hint(const_iterator position, Args&&... args);
111 pair<iterator,bool> insert(const value_type& v);
112 pair<iterator,bool> insert(value_type&& v);
113 iterator insert(const_iterator position, const value_type& v);
114 iterator insert(const_iterator position, value_type&& v);
115 template <class InputIterator>
116 void insert(InputIterator first, InputIterator last);
117 void insert(initializer_list<value_type> il);
118
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000119 node_type extract(const_iterator position); // C++17
120 node_type extract(const key_type& x); // C++17
121 insert_return_type insert(node_type&& nh); // C++17
122 iterator insert(const_iterator hint, node_type&& nh); // C++17
123
Howard Hinnantc51e1022010-05-11 19:42:16 +0000124 iterator erase(const_iterator position);
Marshall Clow22ea5b82015-05-10 13:35:00 +0000125 iterator erase(iterator position); // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000126 size_type erase(const key_type& k);
127 iterator erase(const_iterator first, const_iterator last);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000128 void clear() noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000129
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000130 template<class C2>
131 void merge(set<Key, C2, Allocator>& source); // C++17
132 template<class C2>
133 void merge(set<Key, C2, Allocator>&& source); // C++17
134 template<class C2>
135 void merge(multiset<Key, C2, Allocator>& source); // C++17
136 template<class C2>
137 void merge(multiset<Key, C2, Allocator>&& source); // C++17
138
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000139 void swap(set& s)
140 noexcept(
141 __is_nothrow_swappable<key_compare>::value &&
142 (!allocator_type::propagate_on_container_swap::value ||
143 __is_nothrow_swappable<allocator_type>::value));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000144
145 // observers:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000146 allocator_type get_allocator() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000147 key_compare key_comp() const;
148 value_compare value_comp() const;
149
150 // set operations:
151 iterator find(const key_type& k);
152 const_iterator find(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000153 template<typename K>
154 iterator find(const K& x);
155 template<typename K>
156 const_iterator find(const K& x) const; // C++14
157 template<typename K>
158 size_type count(const K& x) const; // C++14
159
Howard Hinnantc51e1022010-05-11 19:42:16 +0000160 size_type count(const key_type& k) const;
161 iterator lower_bound(const key_type& k);
162 const_iterator lower_bound(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000163 template<typename K>
164 iterator lower_bound(const K& x); // C++14
165 template<typename K>
166 const_iterator lower_bound(const K& x) const; // C++14
167
Howard Hinnantc51e1022010-05-11 19:42:16 +0000168 iterator upper_bound(const key_type& k);
169 const_iterator upper_bound(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000170 template<typename K>
171 iterator upper_bound(const K& x); // C++14
172 template<typename K>
173 const_iterator upper_bound(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000174 pair<iterator,iterator> equal_range(const key_type& k);
175 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000176 template<typename K>
177 pair<iterator,iterator> equal_range(const K& x); // C++14
178 template<typename K>
179 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000180};
181
182template <class Key, class Compare, class Allocator>
183bool
184operator==(const set<Key, Compare, Allocator>& x,
185 const set<Key, Compare, Allocator>& y);
186
187template <class Key, class Compare, class Allocator>
188bool
189operator< (const set<Key, Compare, Allocator>& x,
190 const set<Key, Compare, Allocator>& y);
191
192template <class Key, class Compare, class Allocator>
193bool
194operator!=(const set<Key, Compare, Allocator>& x,
195 const set<Key, Compare, Allocator>& y);
196
197template <class Key, class Compare, class Allocator>
198bool
199operator> (const set<Key, Compare, Allocator>& x,
200 const set<Key, Compare, Allocator>& y);
201
202template <class Key, class Compare, class Allocator>
203bool
204operator>=(const set<Key, Compare, Allocator>& x,
205 const set<Key, Compare, Allocator>& y);
206
207template <class Key, class Compare, class Allocator>
208bool
209operator<=(const set<Key, Compare, Allocator>& x,
210 const set<Key, Compare, Allocator>& y);
211
212// specialized algorithms:
213template <class Key, class Compare, class Allocator>
214void
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000215swap(set<Key, Compare, Allocator>& x, set<Key, Compare, Allocator>& y)
216 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000217
Marshall Clow29b53f22018-12-14 18:49:35 +0000218template <class Key, class Compare, class Allocator, class Predicate>
219 void erase_if(set<Key, Compare, Allocator>& c, Predicate pred); // C++20
220
Howard Hinnantc51e1022010-05-11 19:42:16 +0000221template <class Key, class Compare = less<Key>,
222 class Allocator = allocator<Key>>
223class multiset
224{
225public:
226 // types:
227 typedef Key key_type;
228 typedef key_type value_type;
229 typedef Compare key_compare;
230 typedef key_compare value_compare;
231 typedef Allocator allocator_type;
232 typedef typename allocator_type::reference reference;
233 typedef typename allocator_type::const_reference const_reference;
234 typedef typename allocator_type::size_type size_type;
235 typedef typename allocator_type::difference_type difference_type;
236 typedef typename allocator_type::pointer pointer;
237 typedef typename allocator_type::const_pointer const_pointer;
238
239 typedef implementation-defined iterator;
240 typedef implementation-defined const_iterator;
241 typedef std::reverse_iterator<iterator> reverse_iterator;
242 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000243 typedef unspecified node_type; // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000244
245 // construct/copy/destroy:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000246 multiset()
247 noexcept(
248 is_nothrow_default_constructible<allocator_type>::value &&
249 is_nothrow_default_constructible<key_compare>::value &&
250 is_nothrow_copy_constructible<key_compare>::value);
251 explicit multiset(const value_compare& comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000252 multiset(const value_compare& comp, const allocator_type& a);
253 template <class InputIterator>
254 multiset(InputIterator first, InputIterator last,
255 const value_compare& comp = value_compare());
256 template <class InputIterator>
257 multiset(InputIterator first, InputIterator last,
258 const value_compare& comp, const allocator_type& a);
259 multiset(const multiset& s);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000260 multiset(multiset&& s)
261 noexcept(
262 is_nothrow_move_constructible<allocator_type>::value &&
263 is_nothrow_move_constructible<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000264 explicit multiset(const allocator_type& a);
265 multiset(const multiset& s, const allocator_type& a);
266 multiset(multiset&& s, const allocator_type& a);
267 multiset(initializer_list<value_type> il, const value_compare& comp = value_compare());
268 multiset(initializer_list<value_type> il, const value_compare& comp,
269 const allocator_type& a);
Marshall Clow631788a2013-09-11 00:06:45 +0000270 template <class InputIterator>
271 multiset(InputIterator first, InputIterator last, const allocator_type& a)
272 : set(first, last, Compare(), a) {} // C++14
273 multiset(initializer_list<value_type> il, const allocator_type& a)
274 : set(il, Compare(), a) {} // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000275 ~multiset();
276
277 multiset& operator=(const multiset& s);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000278 multiset& operator=(multiset&& s)
279 noexcept(
280 allocator_type::propagate_on_container_move_assignment::value &&
281 is_nothrow_move_assignable<allocator_type>::value &&
282 is_nothrow_move_assignable<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000283 multiset& operator=(initializer_list<value_type> il);
284
285 // iterators:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000286 iterator begin() noexcept;
287 const_iterator begin() const noexcept;
288 iterator end() noexcept;
289 const_iterator end() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000290
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000291 reverse_iterator rbegin() noexcept;
292 const_reverse_iterator rbegin() const noexcept;
293 reverse_iterator rend() noexcept;
294 const_reverse_iterator rend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000295
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000296 const_iterator cbegin() const noexcept;
297 const_iterator cend() const noexcept;
298 const_reverse_iterator crbegin() const noexcept;
299 const_reverse_iterator crend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000300
301 // capacity:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000302 bool empty() const noexcept;
303 size_type size() const noexcept;
304 size_type max_size() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000305
306 // modifiers:
307 template <class... Args>
308 iterator emplace(Args&&... args);
309 template <class... Args>
310 iterator emplace_hint(const_iterator position, Args&&... args);
311 iterator insert(const value_type& v);
312 iterator insert(value_type&& v);
313 iterator insert(const_iterator position, const value_type& v);
314 iterator insert(const_iterator position, value_type&& v);
315 template <class InputIterator>
316 void insert(InputIterator first, InputIterator last);
317 void insert(initializer_list<value_type> il);
318
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000319 node_type extract(const_iterator position); // C++17
320 node_type extract(const key_type& x); // C++17
321 iterator insert(node_type&& nh); // C++17
322 iterator insert(const_iterator hint, node_type&& nh); // C++17
323
Howard Hinnantc51e1022010-05-11 19:42:16 +0000324 iterator erase(const_iterator position);
Marshall Clow22ea5b82015-05-10 13:35:00 +0000325 iterator erase(iterator position); // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000326 size_type erase(const key_type& k);
327 iterator erase(const_iterator first, const_iterator last);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000328 void clear() noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000329
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000330 template<class C2>
331 void merge(multiset<Key, C2, Allocator>& source); // C++17
332 template<class C2>
333 void merge(multiset<Key, C2, Allocator>&& source); // C++17
334 template<class C2>
335 void merge(set<Key, C2, Allocator>& source); // C++17
336 template<class C2>
337 void merge(set<Key, C2, Allocator>&& source); // C++17
338
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000339 void swap(multiset& s)
340 noexcept(
341 __is_nothrow_swappable<key_compare>::value &&
342 (!allocator_type::propagate_on_container_swap::value ||
343 __is_nothrow_swappable<allocator_type>::value));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000344
345 // observers:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000346 allocator_type get_allocator() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000347 key_compare key_comp() const;
348 value_compare value_comp() const;
349
350 // set operations:
351 iterator find(const key_type& k);
352 const_iterator find(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000353 template<typename K>
354 iterator find(const K& x);
355 template<typename K>
356 const_iterator find(const K& x) const; // C++14
357
Howard Hinnantc51e1022010-05-11 19:42:16 +0000358 size_type count(const key_type& k) const;
359 iterator lower_bound(const key_type& k);
360 const_iterator lower_bound(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000361 template<typename K>
362 iterator lower_bound(const K& x); // C++14
363 template<typename K>
364 const_iterator lower_bound(const K& x) const; // C++14
365
Howard Hinnantc51e1022010-05-11 19:42:16 +0000366 iterator upper_bound(const key_type& k);
367 const_iterator upper_bound(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000368 template<typename K>
369 iterator upper_bound(const K& x); // C++14
370 template<typename K>
371 const_iterator upper_bound(const K& x) const; // C++14
372
Howard Hinnantc51e1022010-05-11 19:42:16 +0000373 pair<iterator,iterator> equal_range(const key_type& k);
374 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000375 template<typename K>
376 pair<iterator,iterator> equal_range(const K& x); // C++14
377 template<typename K>
378 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000379};
380
381template <class Key, class Compare, class Allocator>
382bool
383operator==(const multiset<Key, Compare, Allocator>& x,
384 const multiset<Key, Compare, Allocator>& y);
385
386template <class Key, class Compare, class Allocator>
387bool
388operator< (const multiset<Key, Compare, Allocator>& x,
389 const multiset<Key, Compare, Allocator>& y);
390
391template <class Key, class Compare, class Allocator>
392bool
393operator!=(const multiset<Key, Compare, Allocator>& x,
394 const multiset<Key, Compare, Allocator>& y);
395
396template <class Key, class Compare, class Allocator>
397bool
398operator> (const multiset<Key, Compare, Allocator>& x,
399 const multiset<Key, Compare, Allocator>& y);
400
401template <class Key, class Compare, class Allocator>
402bool
403operator>=(const multiset<Key, Compare, Allocator>& x,
404 const multiset<Key, Compare, Allocator>& y);
405
406template <class Key, class Compare, class Allocator>
407bool
408operator<=(const multiset<Key, Compare, Allocator>& x,
409 const multiset<Key, Compare, Allocator>& y);
410
411// specialized algorithms:
412template <class Key, class Compare, class Allocator>
413void
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000414swap(multiset<Key, Compare, Allocator>& x, multiset<Key, Compare, Allocator>& y)
415 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000416
Marshall Clow29b53f22018-12-14 18:49:35 +0000417template <class Key, class Compare, class Allocator, class Predicate>
418 void erase_if(multiset<Key, Compare, Allocator>& c, Predicate pred); // C++20
419
Howard Hinnantc51e1022010-05-11 19:42:16 +0000420} // std
421
422*/
423
424#include <__config>
425#include <__tree>
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000426#include <__node_handle>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000427#include <functional>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000428#include <version>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000429
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000430#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000431#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000432#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000433
434_LIBCPP_BEGIN_NAMESPACE_STD
435
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000436template <class _Key, class _Compare, class _Allocator>
437class multiset;
438
Howard Hinnantc51e1022010-05-11 19:42:16 +0000439template <class _Key, class _Compare = less<_Key>,
440 class _Allocator = allocator<_Key> >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000441class _LIBCPP_TEMPLATE_VIS set
Howard Hinnantc51e1022010-05-11 19:42:16 +0000442{
443public:
444 // types:
445 typedef _Key key_type;
446 typedef key_type value_type;
447 typedef _Compare key_compare;
448 typedef key_compare value_compare;
449 typedef _Allocator allocator_type;
450 typedef value_type& reference;
451 typedef const value_type& const_reference;
452
Marshall Clow5128cf32015-11-26 01:24:04 +0000453 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
454 "Allocator::value_type must be same type as value_type");
455
Howard Hinnantc51e1022010-05-11 19:42:16 +0000456private:
457 typedef __tree<value_type, value_compare, allocator_type> __base;
458 typedef allocator_traits<allocator_type> __alloc_traits;
459 typedef typename __base::__node_holder __node_holder;
460
461 __base __tree_;
462
463public:
464 typedef typename __base::pointer pointer;
465 typedef typename __base::const_pointer const_pointer;
466 typedef typename __base::size_type size_type;
467 typedef typename __base::difference_type difference_type;
468 typedef typename __base::const_iterator iterator;
469 typedef typename __base::const_iterator const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000470 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
471 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000472
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000473#if _LIBCPP_STD_VER > 14
474 typedef __set_node_handle<typename __base::__node, allocator_type> node_type;
475 typedef __insert_return_type<iterator, node_type> insert_return_type;
476#endif
477
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000478 template <class _Key2, class _Compare2, class _Alloc2>
479 friend class _LIBCPP_TEMPLATE_VIS set;
480 template <class _Key2, class _Compare2, class _Alloc2>
481 friend class _LIBCPP_TEMPLATE_VIS multiset;
482
Howard Hinnant192cf032010-09-23 16:27:36 +0000483 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +0000484 set()
485 _NOEXCEPT_(
486 is_nothrow_default_constructible<allocator_type>::value &&
487 is_nothrow_default_constructible<key_compare>::value &&
488 is_nothrow_copy_constructible<key_compare>::value)
489 : __tree_(value_compare()) {}
490
491 _LIBCPP_INLINE_VISIBILITY
492 explicit set(const value_compare& __comp)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000493 _NOEXCEPT_(
494 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000495 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000496 : __tree_(__comp) {}
Marshall Clow7086a5a2014-03-10 04:50:10 +0000497
Howard Hinnant192cf032010-09-23 16:27:36 +0000498 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7ed23a72014-03-05 19:06:20 +0000499 explicit set(const value_compare& __comp, const allocator_type& __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000500 : __tree_(__comp, __a) {}
501 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000502 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000503 set(_InputIterator __f, _InputIterator __l,
504 const value_compare& __comp = value_compare())
505 : __tree_(__comp)
506 {
507 insert(__f, __l);
508 }
509
510 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000511 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000512 set(_InputIterator __f, _InputIterator __l, const value_compare& __comp,
513 const allocator_type& __a)
514 : __tree_(__comp, __a)
515 {
516 insert(__f, __l);
517 }
518
Marshall Clow631788a2013-09-11 00:06:45 +0000519#if _LIBCPP_STD_VER > 11
520 template <class _InputIterator>
Louis Dionned2322c82018-11-01 14:41:37 +0000521 _LIBCPP_INLINE_VISIBILITY
Marshall Clow631788a2013-09-11 00:06:45 +0000522 set(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
523 : set(__f, __l, key_compare(), __a) {}
524#endif
525
Howard Hinnant192cf032010-09-23 16:27:36 +0000526 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000527 set(const set& __s)
528 : __tree_(__s.__tree_)
529 {
530 insert(__s.begin(), __s.end());
531 }
532
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000533 _LIBCPP_INLINE_VISIBILITY
534 set& operator=(const set& __s)
535 {
536 __tree_ = __s.__tree_;
537 return *this;
538 }
539
Eric Fiselier615961b2017-04-18 20:58:03 +0000540#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant192cf032010-09-23 16:27:36 +0000541 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000542 set(set&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000543 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000544 : __tree_(_VSTD::move(__s.__tree_)) {}
Eric Fiselier615961b2017-04-18 20:58:03 +0000545#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000546
Howard Hinnant192cf032010-09-23 16:27:36 +0000547 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000548 explicit set(const allocator_type& __a)
549 : __tree_(__a) {}
550
Howard Hinnant192cf032010-09-23 16:27:36 +0000551 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000552 set(const set& __s, const allocator_type& __a)
553 : __tree_(__s.__tree_.value_comp(), __a)
554 {
555 insert(__s.begin(), __s.end());
556 }
557
Eric Fiselier615961b2017-04-18 20:58:03 +0000558#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000559 set(set&& __s, const allocator_type& __a);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000560
Howard Hinnant192cf032010-09-23 16:27:36 +0000561 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000562 set(initializer_list<value_type> __il, const value_compare& __comp = value_compare())
563 : __tree_(__comp)
564 {
565 insert(__il.begin(), __il.end());
566 }
567
Howard Hinnant192cf032010-09-23 16:27:36 +0000568 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000569 set(initializer_list<value_type> __il, const value_compare& __comp,
570 const allocator_type& __a)
571 : __tree_(__comp, __a)
572 {
573 insert(__il.begin(), __il.end());
574 }
575
Marshall Clow631788a2013-09-11 00:06:45 +0000576#if _LIBCPP_STD_VER > 11
Louis Dionned2322c82018-11-01 14:41:37 +0000577 _LIBCPP_INLINE_VISIBILITY
Marshall Clow631788a2013-09-11 00:06:45 +0000578 set(initializer_list<value_type> __il, const allocator_type& __a)
579 : set(__il, key_compare(), __a) {}
580#endif
581
Howard Hinnant192cf032010-09-23 16:27:36 +0000582 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000583 set& operator=(initializer_list<value_type> __il)
584 {
585 __tree_.__assign_unique(__il.begin(), __il.end());
586 return *this;
587 }
588
Howard Hinnant192cf032010-09-23 16:27:36 +0000589 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000590 set& operator=(set&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000591 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000592 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000593 __tree_ = _VSTD::move(__s.__tree_);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000594 return *this;
595 }
Eric Fiselier615961b2017-04-18 20:58:03 +0000596#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000597
Howard Hinnant192cf032010-09-23 16:27:36 +0000598 _LIBCPP_INLINE_VISIBILITY
Louis Dionne69c42c02019-04-11 16:14:56 +0000599 ~set() {
600 static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), "");
601 }
602
603 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000604 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000605 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000606 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000607 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000608 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000609 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000610 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000611
Howard Hinnant192cf032010-09-23 16:27:36 +0000612 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000613 reverse_iterator rbegin() _NOEXCEPT
614 {return reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +0000615 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000616 const_reverse_iterator rbegin() const _NOEXCEPT
617 {return const_reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +0000618 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000619 reverse_iterator rend() _NOEXCEPT
620 {return reverse_iterator(begin());}
Howard Hinnant192cf032010-09-23 16:27:36 +0000621 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000622 const_reverse_iterator rend() const _NOEXCEPT
623 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000624
Howard Hinnant192cf032010-09-23 16:27:36 +0000625 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000626 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000627 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000628 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000629 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000630 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000631 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000632 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000633
Marshall Clow425f5752017-11-15 05:51:26 +0000634 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000635 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant192cf032010-09-23 16:27:36 +0000636 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000637 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000638 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000639 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000640
641 // modifiers:
Eric Fiselier615961b2017-04-18 20:58:03 +0000642#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000643 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +0000644 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000645 pair<iterator, bool> emplace(_Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000646 {return __tree_.__emplace_unique(_VSTD::forward<_Args>(__args)...);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000647 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +0000648 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000649 iterator emplace_hint(const_iterator __p, _Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000650 {return __tree_.__emplace_hint_unique(__p, _VSTD::forward<_Args>(__args)...);}
Eric Fiselier615961b2017-04-18 20:58:03 +0000651#endif // _LIBCPP_CXX03_LANG
652
Howard Hinnant192cf032010-09-23 16:27:36 +0000653 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000654 pair<iterator,bool> insert(const value_type& __v)
655 {return __tree_.__insert_unique(__v);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000656 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000657 iterator insert(const_iterator __p, const value_type& __v)
658 {return __tree_.__insert_unique(__p, __v);}
Eric Fiselier615961b2017-04-18 20:58:03 +0000659
Howard Hinnantc51e1022010-05-11 19:42:16 +0000660 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000661 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000662 void insert(_InputIterator __f, _InputIterator __l)
663 {
664 for (const_iterator __e = cend(); __f != __l; ++__f)
665 __tree_.__insert_unique(__e, *__f);
666 }
667
Eric Fiselier615961b2017-04-18 20:58:03 +0000668#ifndef _LIBCPP_CXX03_LANG
669 _LIBCPP_INLINE_VISIBILITY
670 pair<iterator,bool> insert(value_type&& __v)
671 {return __tree_.__insert_unique(_VSTD::move(__v));}
672
673 _LIBCPP_INLINE_VISIBILITY
674 iterator insert(const_iterator __p, value_type&& __v)
675 {return __tree_.__insert_unique(__p, _VSTD::move(__v));}
676
Howard Hinnant192cf032010-09-23 16:27:36 +0000677 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000678 void insert(initializer_list<value_type> __il)
679 {insert(__il.begin(), __il.end());}
Eric Fiselier615961b2017-04-18 20:58:03 +0000680#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000681
Howard Hinnant192cf032010-09-23 16:27:36 +0000682 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000683 iterator erase(const_iterator __p) {return __tree_.erase(__p);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000684 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000685 size_type erase(const key_type& __k)
686 {return __tree_.__erase_unique(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000687 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000688 iterator erase(const_iterator __f, const_iterator __l)
689 {return __tree_.erase(__f, __l);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000690 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000691 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000692
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000693#if _LIBCPP_STD_VER > 14
694 _LIBCPP_INLINE_VISIBILITY
695 insert_return_type insert(node_type&& __nh)
696 {
697 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
698 "node_type with incompatible allocator passed to set::insert()");
699 return __tree_.template __node_handle_insert_unique<
700 node_type, insert_return_type>(_VSTD::move(__nh));
701 }
702 _LIBCPP_INLINE_VISIBILITY
703 iterator insert(const_iterator __hint, node_type&& __nh)
704 {
705 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
706 "node_type with incompatible allocator passed to set::insert()");
707 return __tree_.template __node_handle_insert_unique<node_type>(
708 __hint, _VSTD::move(__nh));
709 }
710 _LIBCPP_INLINE_VISIBILITY
711 node_type extract(key_type const& __key)
712 {
713 return __tree_.template __node_handle_extract<node_type>(__key);
714 }
715 _LIBCPP_INLINE_VISIBILITY
716 node_type extract(const_iterator __it)
717 {
718 return __tree_.template __node_handle_extract<node_type>(__it);
719 }
Louis Dionned2322c82018-11-01 14:41:37 +0000720 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000721 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +0000722 void merge(set<key_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000723 {
724 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
725 "merging container with incompatible allocator");
726 __tree_.__node_handle_merge_unique(__source.__tree_);
727 }
Louis Dionned2322c82018-11-01 14:41:37 +0000728 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000729 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +0000730 void merge(set<key_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000731 {
732 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
733 "merging container with incompatible allocator");
734 __tree_.__node_handle_merge_unique(__source.__tree_);
735 }
Louis Dionned2322c82018-11-01 14:41:37 +0000736 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000737 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +0000738 void merge(multiset<key_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000739 {
740 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
741 "merging container with incompatible allocator");
742 __tree_.__node_handle_merge_unique(__source.__tree_);
743 }
Louis Dionned2322c82018-11-01 14:41:37 +0000744 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000745 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +0000746 void merge(multiset<key_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000747 {
748 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
749 "merging container with incompatible allocator");
750 __tree_.__node_handle_merge_unique(__source.__tree_);
751 }
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000752#endif
753
Howard Hinnant192cf032010-09-23 16:27:36 +0000754 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000755 void swap(set& __s) _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
756 {__tree_.swap(__s.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000757
Howard Hinnant192cf032010-09-23 16:27:36 +0000758 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000759 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000760 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000761 key_compare key_comp() const {return __tree_.value_comp();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000762 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000763 value_compare value_comp() const {return __tree_.value_comp();}
764
765 // set operations:
Howard Hinnant192cf032010-09-23 16:27:36 +0000766 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000767 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000768 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000769 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000770#if _LIBCPP_STD_VER > 11
771 template <typename _K2>
772 _LIBCPP_INLINE_VISIBILITY
773 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
774 find(const _K2& __k) {return __tree_.find(__k);}
775 template <typename _K2>
776 _LIBCPP_INLINE_VISIBILITY
777 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
778 find(const _K2& __k) const {return __tree_.find(__k);}
779#endif
780
Howard Hinnant192cf032010-09-23 16:27:36 +0000781 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000782 size_type count(const key_type& __k) const
783 {return __tree_.__count_unique(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +0000784#if _LIBCPP_STD_VER > 11
785 template <typename _K2>
786 _LIBCPP_INLINE_VISIBILITY
787 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +0000788 count(const _K2& __k) const {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +0000789#endif
Howard Hinnant192cf032010-09-23 16:27:36 +0000790 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000791 iterator lower_bound(const key_type& __k)
792 {return __tree_.lower_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000793 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000794 const_iterator lower_bound(const key_type& __k) const
795 {return __tree_.lower_bound(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000796#if _LIBCPP_STD_VER > 11
797 template <typename _K2>
798 _LIBCPP_INLINE_VISIBILITY
799 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
800 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
801
802 template <typename _K2>
803 _LIBCPP_INLINE_VISIBILITY
804 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
805 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
806#endif
807
Howard Hinnant192cf032010-09-23 16:27:36 +0000808 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000809 iterator upper_bound(const key_type& __k)
810 {return __tree_.upper_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000811 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000812 const_iterator upper_bound(const key_type& __k) const
813 {return __tree_.upper_bound(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000814#if _LIBCPP_STD_VER > 11
815 template <typename _K2>
816 _LIBCPP_INLINE_VISIBILITY
817 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
818 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
819 template <typename _K2>
820 _LIBCPP_INLINE_VISIBILITY
821 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
822 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
823#endif
824
Howard Hinnant192cf032010-09-23 16:27:36 +0000825 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000826 pair<iterator,iterator> equal_range(const key_type& __k)
827 {return __tree_.__equal_range_unique(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000828 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000829 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
830 {return __tree_.__equal_range_unique(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000831#if _LIBCPP_STD_VER > 11
832 template <typename _K2>
833 _LIBCPP_INLINE_VISIBILITY
834 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +0000835 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000836 template <typename _K2>
837 _LIBCPP_INLINE_VISIBILITY
838 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +0000839 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000840#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000841};
842
Eric Fiselier615961b2017-04-18 20:58:03 +0000843#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000844
845template <class _Key, class _Compare, class _Allocator>
846set<_Key, _Compare, _Allocator>::set(set&& __s, const allocator_type& __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000847 : __tree_(_VSTD::move(__s.__tree_), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000848{
849 if (__a != __s.get_allocator())
850 {
851 const_iterator __e = cend();
852 while (!__s.empty())
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000853 insert(__e, _VSTD::move(__s.__tree_.remove(__s.begin())->__value_));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000854 }
855}
856
Eric Fiselier615961b2017-04-18 20:58:03 +0000857#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000858
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 __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
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{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000874 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000875}
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 !(__x == __y);
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 __y < __x;
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 !(__x < __y);
902}
903
904template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000905inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000906bool
907operator<=(const set<_Key, _Compare, _Allocator>& __x,
908 const set<_Key, _Compare, _Allocator>& __y)
909{
910 return !(__y < __x);
911}
912
913// specialized algorithms:
914template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000915inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000916void
917swap(set<_Key, _Compare, _Allocator>& __x,
918 set<_Key, _Compare, _Allocator>& __y)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000919 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000920{
921 __x.swap(__y);
922}
923
Marshall Clow29b53f22018-12-14 18:49:35 +0000924#if _LIBCPP_STD_VER > 17
925template <class _Key, class _Compare, class _Allocator, class _Predicate>
926inline _LIBCPP_INLINE_VISIBILITY
927void erase_if(set<_Key, _Compare, _Allocator>& __c, _Predicate __pred)
928{ __libcpp_erase_if_container(__c, __pred); }
929#endif
930
Howard Hinnantc51e1022010-05-11 19:42:16 +0000931template <class _Key, class _Compare = less<_Key>,
932 class _Allocator = allocator<_Key> >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000933class _LIBCPP_TEMPLATE_VIS multiset
Howard Hinnantc51e1022010-05-11 19:42:16 +0000934{
935public:
936 // types:
937 typedef _Key key_type;
938 typedef key_type value_type;
939 typedef _Compare key_compare;
940 typedef key_compare value_compare;
941 typedef _Allocator allocator_type;
942 typedef value_type& reference;
943 typedef const value_type& const_reference;
944
Marshall Clow5128cf32015-11-26 01:24:04 +0000945 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
946 "Allocator::value_type must be same type as value_type");
947
Howard Hinnantc51e1022010-05-11 19:42:16 +0000948private:
949 typedef __tree<value_type, value_compare, allocator_type> __base;
950 typedef allocator_traits<allocator_type> __alloc_traits;
951 typedef typename __base::__node_holder __node_holder;
952
953 __base __tree_;
954
955public:
956 typedef typename __base::pointer pointer;
957 typedef typename __base::const_pointer const_pointer;
958 typedef typename __base::size_type size_type;
959 typedef typename __base::difference_type difference_type;
960 typedef typename __base::const_iterator iterator;
961 typedef typename __base::const_iterator const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000962 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
963 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000964
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000965#if _LIBCPP_STD_VER > 14
966 typedef __set_node_handle<typename __base::__node, allocator_type> node_type;
967#endif
968
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000969 template <class _Key2, class _Compare2, class _Alloc2>
970 friend class _LIBCPP_TEMPLATE_VIS set;
971 template <class _Key2, class _Compare2, class _Alloc2>
972 friend class _LIBCPP_TEMPLATE_VIS multiset;
973
Howard Hinnantc51e1022010-05-11 19:42:16 +0000974 // construct/copy/destroy:
Howard Hinnant192cf032010-09-23 16:27:36 +0000975 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +0000976 multiset()
977 _NOEXCEPT_(
978 is_nothrow_default_constructible<allocator_type>::value &&
979 is_nothrow_default_constructible<key_compare>::value &&
980 is_nothrow_copy_constructible<key_compare>::value)
981 : __tree_(value_compare()) {}
982
983 _LIBCPP_INLINE_VISIBILITY
984 explicit multiset(const value_compare& __comp)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000985 _NOEXCEPT_(
986 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000987 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000988 : __tree_(__comp) {}
Marshall Clow7086a5a2014-03-10 04:50:10 +0000989
Howard Hinnant192cf032010-09-23 16:27:36 +0000990 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7ed23a72014-03-05 19:06:20 +0000991 explicit multiset(const value_compare& __comp, const allocator_type& __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000992 : __tree_(__comp, __a) {}
993 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000994 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000995 multiset(_InputIterator __f, _InputIterator __l,
996 const value_compare& __comp = value_compare())
997 : __tree_(__comp)
998 {
999 insert(__f, __l);
1000 }
1001
Marshall Clow631788a2013-09-11 00:06:45 +00001002#if _LIBCPP_STD_VER > 11
1003 template <class _InputIterator>
Louis Dionned2322c82018-11-01 14:41:37 +00001004 _LIBCPP_INLINE_VISIBILITY
Marshall Clow631788a2013-09-11 00:06:45 +00001005 multiset(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
1006 : multiset(__f, __l, key_compare(), __a) {}
1007#endif
1008
Howard Hinnantc51e1022010-05-11 19:42:16 +00001009 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001010 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001011 multiset(_InputIterator __f, _InputIterator __l,
1012 const value_compare& __comp, const allocator_type& __a)
1013 : __tree_(__comp, __a)
1014 {
1015 insert(__f, __l);
1016 }
1017
Howard Hinnant192cf032010-09-23 16:27:36 +00001018 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001019 multiset(const multiset& __s)
1020 : __tree_(__s.__tree_.value_comp(),
1021 __alloc_traits::select_on_container_copy_construction(__s.__tree_.__alloc()))
1022 {
1023 insert(__s.begin(), __s.end());
1024 }
1025
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001026 _LIBCPP_INLINE_VISIBILITY
1027 multiset& operator=(const multiset& __s)
1028 {
1029 __tree_ = __s.__tree_;
1030 return *this;
1031 }
1032
Eric Fiselier615961b2017-04-18 20:58:03 +00001033#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant192cf032010-09-23 16:27:36 +00001034 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001035 multiset(multiset&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001036 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001037 : __tree_(_VSTD::move(__s.__tree_)) {}
Eric Fiselier615961b2017-04-18 20:58:03 +00001038
1039 multiset(multiset&& __s, const allocator_type& __a);
1040#endif // _LIBCPP_CXX03_LANG
Howard Hinnant192cf032010-09-23 16:27:36 +00001041 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001042 explicit multiset(const allocator_type& __a)
1043 : __tree_(__a) {}
Howard Hinnant192cf032010-09-23 16:27:36 +00001044 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001045 multiset(const multiset& __s, const allocator_type& __a)
1046 : __tree_(__s.__tree_.value_comp(), __a)
1047 {
1048 insert(__s.begin(), __s.end());
1049 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001050
Eric Fiselier615961b2017-04-18 20:58:03 +00001051#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant192cf032010-09-23 16:27:36 +00001052 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001053 multiset(initializer_list<value_type> __il, const value_compare& __comp = value_compare())
1054 : __tree_(__comp)
1055 {
1056 insert(__il.begin(), __il.end());
1057 }
1058
Howard Hinnant192cf032010-09-23 16:27:36 +00001059 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001060 multiset(initializer_list<value_type> __il, const value_compare& __comp,
1061 const allocator_type& __a)
1062 : __tree_(__comp, __a)
1063 {
1064 insert(__il.begin(), __il.end());
1065 }
1066
Marshall Clow631788a2013-09-11 00:06:45 +00001067#if _LIBCPP_STD_VER > 11
Louis Dionned2322c82018-11-01 14:41:37 +00001068 _LIBCPP_INLINE_VISIBILITY
Marshall Clow631788a2013-09-11 00:06:45 +00001069 multiset(initializer_list<value_type> __il, const allocator_type& __a)
1070 : multiset(__il, key_compare(), __a) {}
1071#endif
1072
Howard Hinnant192cf032010-09-23 16:27:36 +00001073 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001074 multiset& operator=(initializer_list<value_type> __il)
1075 {
1076 __tree_.__assign_multi(__il.begin(), __il.end());
1077 return *this;
1078 }
1079
Howard Hinnant192cf032010-09-23 16:27:36 +00001080 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001081 multiset& operator=(multiset&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001082 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001083 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001084 __tree_ = _VSTD::move(__s.__tree_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001085 return *this;
1086 }
Eric Fiselier615961b2017-04-18 20:58:03 +00001087#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001088
Howard Hinnant192cf032010-09-23 16:27:36 +00001089 _LIBCPP_INLINE_VISIBILITY
Louis Dionne69c42c02019-04-11 16:14:56 +00001090 ~multiset() {
1091 static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), "");
1092 }
1093
1094 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001095 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001096 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001097 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001098 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001099 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001100 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001101 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001102
Howard Hinnant192cf032010-09-23 16:27:36 +00001103 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001104 reverse_iterator rbegin() _NOEXCEPT
1105 {return reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +00001106 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001107 const_reverse_iterator rbegin() const _NOEXCEPT
1108 {return const_reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +00001109 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001110 reverse_iterator rend() _NOEXCEPT
1111 {return reverse_iterator(begin());}
Howard Hinnant192cf032010-09-23 16:27:36 +00001112 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001113 const_reverse_iterator rend() const _NOEXCEPT
1114 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001115
Howard Hinnant192cf032010-09-23 16:27:36 +00001116 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001117 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001118 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001119 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001120 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001121 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001122 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001123 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001124
Marshall Clow425f5752017-11-15 05:51:26 +00001125 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001126 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant192cf032010-09-23 16:27:36 +00001127 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001128 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001129 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001130 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001131
1132 // modifiers:
Eric Fiselier615961b2017-04-18 20:58:03 +00001133#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001134 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +00001135 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001136 iterator emplace(_Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001137 {return __tree_.__emplace_multi(_VSTD::forward<_Args>(__args)...);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001138 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +00001139 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001140 iterator emplace_hint(const_iterator __p, _Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001141 {return __tree_.__emplace_hint_multi(__p, _VSTD::forward<_Args>(__args)...);}
Eric Fiselier615961b2017-04-18 20:58:03 +00001142#endif // _LIBCPP_CXX03_LANG
1143
Howard Hinnant192cf032010-09-23 16:27:36 +00001144 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001145 iterator insert(const value_type& __v)
1146 {return __tree_.__insert_multi(__v);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001147 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001148 iterator insert(const_iterator __p, const value_type& __v)
1149 {return __tree_.__insert_multi(__p, __v);}
Eric Fiselier615961b2017-04-18 20:58:03 +00001150
Howard Hinnantc51e1022010-05-11 19:42:16 +00001151 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001152 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001153 void insert(_InputIterator __f, _InputIterator __l)
1154 {
1155 for (const_iterator __e = cend(); __f != __l; ++__f)
1156 __tree_.__insert_multi(__e, *__f);
1157 }
1158
Eric Fiselier615961b2017-04-18 20:58:03 +00001159#ifndef _LIBCPP_CXX03_LANG
1160 _LIBCPP_INLINE_VISIBILITY
1161 iterator insert(value_type&& __v)
1162 {return __tree_.__insert_multi(_VSTD::move(__v));}
1163
1164 _LIBCPP_INLINE_VISIBILITY
1165 iterator insert(const_iterator __p, value_type&& __v)
1166 {return __tree_.__insert_multi(__p, _VSTD::move(__v));}
1167
Howard Hinnant192cf032010-09-23 16:27:36 +00001168 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001169 void insert(initializer_list<value_type> __il)
1170 {insert(__il.begin(), __il.end());}
Eric Fiselier615961b2017-04-18 20:58:03 +00001171#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001172
Howard Hinnant192cf032010-09-23 16:27:36 +00001173 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001174 iterator erase(const_iterator __p) {return __tree_.erase(__p);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001175 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001176 size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001177 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001178 iterator erase(const_iterator __f, const_iterator __l)
1179 {return __tree_.erase(__f, __l);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001180 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001181 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001182
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001183#if _LIBCPP_STD_VER > 14
1184 _LIBCPP_INLINE_VISIBILITY
1185 iterator insert(node_type&& __nh)
1186 {
1187 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1188 "node_type with incompatible allocator passed to multiset::insert()");
1189 return __tree_.template __node_handle_insert_multi<node_type>(
1190 _VSTD::move(__nh));
1191 }
1192 _LIBCPP_INLINE_VISIBILITY
1193 iterator insert(const_iterator __hint, node_type&& __nh)
1194 {
1195 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1196 "node_type with incompatible allocator passed to multiset::insert()");
1197 return __tree_.template __node_handle_insert_multi<node_type>(
1198 __hint, _VSTD::move(__nh));
1199 }
1200 _LIBCPP_INLINE_VISIBILITY
1201 node_type extract(key_type const& __key)
1202 {
1203 return __tree_.template __node_handle_extract<node_type>(__key);
1204 }
1205 _LIBCPP_INLINE_VISIBILITY
1206 node_type extract(const_iterator __it)
1207 {
1208 return __tree_.template __node_handle_extract<node_type>(__it);
1209 }
Louis Dionned2322c82018-11-01 14:41:37 +00001210 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001211 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001212 void merge(multiset<key_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001213 {
1214 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1215 "merging container with incompatible allocator");
1216 __tree_.__node_handle_merge_multi(__source.__tree_);
1217 }
Louis Dionned2322c82018-11-01 14:41:37 +00001218 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001219 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001220 void merge(multiset<key_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001221 {
1222 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1223 "merging container with incompatible allocator");
1224 __tree_.__node_handle_merge_multi(__source.__tree_);
1225 }
Louis Dionned2322c82018-11-01 14:41:37 +00001226 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001227 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001228 void merge(set<key_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001229 {
1230 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1231 "merging container with incompatible allocator");
1232 __tree_.__node_handle_merge_multi(__source.__tree_);
1233 }
Louis Dionned2322c82018-11-01 14:41:37 +00001234 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001235 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001236 void merge(set<key_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001237 {
1238 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1239 "merging container with incompatible allocator");
1240 __tree_.__node_handle_merge_multi(__source.__tree_);
1241 }
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001242#endif
1243
Howard Hinnant192cf032010-09-23 16:27:36 +00001244 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001245 void swap(multiset& __s)
1246 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1247 {__tree_.swap(__s.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001248
Howard Hinnant192cf032010-09-23 16:27:36 +00001249 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001250 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001251 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001252 key_compare key_comp() const {return __tree_.value_comp();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001253 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001254 value_compare value_comp() const {return __tree_.value_comp();}
1255
1256 // set operations:
Howard Hinnant192cf032010-09-23 16:27:36 +00001257 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001258 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001259 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001260 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +00001261#if _LIBCPP_STD_VER > 11
1262 template <typename _K2>
1263 _LIBCPP_INLINE_VISIBILITY
1264 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,iterator>::type
1265 find(const _K2& __k) {return __tree_.find(__k);}
1266 template <typename _K2>
1267 _LIBCPP_INLINE_VISIBILITY
1268 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,const_iterator>::type
1269 find(const _K2& __k) const {return __tree_.find(__k);}
1270#endif
1271
Howard Hinnant192cf032010-09-23 16:27:36 +00001272 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001273 size_type count(const key_type& __k) const
1274 {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001275#if _LIBCPP_STD_VER > 11
1276 template <typename _K2>
1277 _LIBCPP_INLINE_VISIBILITY
1278 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
Marshall Clow5571bcd2018-01-07 17:39:57 +00001279 count(const _K2& __k) const {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001280#endif
Marshall Clowc0152142013-08-13 01:11:06 +00001281
Howard Hinnant192cf032010-09-23 16:27:36 +00001282 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001283 iterator lower_bound(const key_type& __k)
1284 {return __tree_.lower_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001285 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001286 const_iterator lower_bound(const key_type& __k) const
1287 {return __tree_.lower_bound(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +00001288#if _LIBCPP_STD_VER > 11
1289 template <typename _K2>
1290 _LIBCPP_INLINE_VISIBILITY
1291 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,iterator>::type
1292 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
1293
1294 template <typename _K2>
1295 _LIBCPP_INLINE_VISIBILITY
1296 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,const_iterator>::type
1297 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
1298#endif
1299
Howard Hinnant192cf032010-09-23 16:27:36 +00001300 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001301 iterator upper_bound(const key_type& __k)
1302 {return __tree_.upper_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001303 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001304 const_iterator upper_bound(const key_type& __k) const
1305 {return __tree_.upper_bound(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +00001306#if _LIBCPP_STD_VER > 11
1307 template <typename _K2>
1308 _LIBCPP_INLINE_VISIBILITY
1309 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,iterator>::type
1310 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
1311 template <typename _K2>
1312 _LIBCPP_INLINE_VISIBILITY
1313 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,const_iterator>::type
1314 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
1315#endif
1316
Howard Hinnant192cf032010-09-23 16:27:36 +00001317 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001318 pair<iterator,iterator> equal_range(const key_type& __k)
1319 {return __tree_.__equal_range_multi(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001320 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001321 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
1322 {return __tree_.__equal_range_multi(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +00001323#if _LIBCPP_STD_VER > 11
1324 template <typename _K2>
1325 _LIBCPP_INLINE_VISIBILITY
1326 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
1327 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
1328 template <typename _K2>
1329 _LIBCPP_INLINE_VISIBILITY
1330 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
1331 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
1332#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001333};
1334
Eric Fiselier615961b2017-04-18 20:58:03 +00001335#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001336
1337template <class _Key, class _Compare, class _Allocator>
1338multiset<_Key, _Compare, _Allocator>::multiset(multiset&& __s, const allocator_type& __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001339 : __tree_(_VSTD::move(__s.__tree_), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001340{
1341 if (__a != __s.get_allocator())
1342 {
1343 const_iterator __e = cend();
1344 while (!__s.empty())
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001345 insert(__e, _VSTD::move(__s.__tree_.remove(__s.begin())->__value_));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001346 }
1347}
1348
Eric Fiselier615961b2017-04-18 20:58:03 +00001349#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001350
1351template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001352inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001353bool
1354operator==(const multiset<_Key, _Compare, _Allocator>& __x,
1355 const multiset<_Key, _Compare, _Allocator>& __y)
1356{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001357 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001358}
1359
1360template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001361inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001362bool
1363operator< (const multiset<_Key, _Compare, _Allocator>& __x,
1364 const multiset<_Key, _Compare, _Allocator>& __y)
1365{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001366 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001367}
1368
1369template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001370inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001371bool
1372operator!=(const multiset<_Key, _Compare, _Allocator>& __x,
1373 const multiset<_Key, _Compare, _Allocator>& __y)
1374{
1375 return !(__x == __y);
1376}
1377
1378template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001379inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001380bool
1381operator> (const multiset<_Key, _Compare, _Allocator>& __x,
1382 const multiset<_Key, _Compare, _Allocator>& __y)
1383{
1384 return __y < __x;
1385}
1386
1387template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001388inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001389bool
1390operator>=(const multiset<_Key, _Compare, _Allocator>& __x,
1391 const multiset<_Key, _Compare, _Allocator>& __y)
1392{
1393 return !(__x < __y);
1394}
1395
1396template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001397inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001398bool
1399operator<=(const multiset<_Key, _Compare, _Allocator>& __x,
1400 const multiset<_Key, _Compare, _Allocator>& __y)
1401{
1402 return !(__y < __x);
1403}
1404
1405template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001406inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001407void
1408swap(multiset<_Key, _Compare, _Allocator>& __x,
1409 multiset<_Key, _Compare, _Allocator>& __y)
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001410 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001411{
1412 __x.swap(__y);
1413}
1414
Marshall Clow29b53f22018-12-14 18:49:35 +00001415#if _LIBCPP_STD_VER > 17
1416template <class _Key, class _Compare, class _Allocator, class _Predicate>
1417inline _LIBCPP_INLINE_VISIBILITY
1418void erase_if(multiset<_Key, _Compare, _Allocator>& __c, _Predicate __pred)
1419{ __libcpp_erase_if_container(__c, __pred); }
1420#endif
1421
Howard Hinnantc51e1022010-05-11 19:42:16 +00001422_LIBCPP_END_NAMESPACE_STD
1423
1424#endif // _LIBCPP_SET