blob: a5e80206519b934b280fb90b4f1e0a9d2b458e02 [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
Marek Kurdejd7e019e2021-04-13 17:10:55 +0200157
Marshall Clowc0152142013-08-13 01:11:06 +0000158 template<typename K>
Zoe Carver3ffbab12019-07-16 03:21:01 +0000159 size_type count(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000160 size_type count(const key_type& k) const;
Marek Kurdejd7e019e2021-04-13 17:10:55 +0200161
162 bool contains(const key_type& x) const; // C++20
163 template<class K> bool contains(const K& x) const; // C++20
164
Howard Hinnantc51e1022010-05-11 19:42:16 +0000165 iterator lower_bound(const key_type& k);
166 const_iterator lower_bound(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000167 template<typename K>
168 iterator lower_bound(const K& x); // C++14
169 template<typename K>
170 const_iterator lower_bound(const K& x) const; // C++14
171
Howard Hinnantc51e1022010-05-11 19:42:16 +0000172 iterator upper_bound(const key_type& k);
173 const_iterator upper_bound(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000174 template<typename K>
175 iterator upper_bound(const K& x); // C++14
176 template<typename K>
177 const_iterator upper_bound(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000178 pair<iterator,iterator> equal_range(const key_type& k);
179 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000180 template<typename K>
181 pair<iterator,iterator> equal_range(const K& x); // C++14
182 template<typename K>
183 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000184};
185
186template <class Key, class Compare, class Allocator>
187bool
188operator==(const set<Key, Compare, Allocator>& x,
189 const set<Key, Compare, Allocator>& y);
190
191template <class Key, class Compare, class Allocator>
192bool
193operator< (const set<Key, Compare, Allocator>& x,
194 const set<Key, Compare, Allocator>& y);
195
196template <class Key, class Compare, class Allocator>
197bool
198operator!=(const set<Key, Compare, Allocator>& x,
199 const set<Key, Compare, Allocator>& y);
200
201template <class Key, class Compare, class Allocator>
202bool
203operator> (const set<Key, Compare, Allocator>& x,
204 const set<Key, Compare, Allocator>& y);
205
206template <class Key, class Compare, class Allocator>
207bool
208operator>=(const set<Key, Compare, Allocator>& x,
209 const set<Key, Compare, Allocator>& y);
210
211template <class Key, class Compare, class Allocator>
212bool
213operator<=(const set<Key, Compare, Allocator>& x,
214 const set<Key, Compare, Allocator>& y);
215
216// specialized algorithms:
217template <class Key, class Compare, class Allocator>
218void
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000219swap(set<Key, Compare, Allocator>& x, set<Key, Compare, Allocator>& y)
220 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000221
Marshall Clow29b53f22018-12-14 18:49:35 +0000222template <class Key, class Compare, class Allocator, class Predicate>
Marek Kurdeja98b1412020-05-02 13:58:03 +0200223typename set<Key, Compare, Allocator>::size_type
224erase_if(set<Key, Compare, Allocator>& c, Predicate pred); // C++20
Marshall Clow29b53f22018-12-14 18:49:35 +0000225
Howard Hinnantc51e1022010-05-11 19:42:16 +0000226template <class Key, class Compare = less<Key>,
227 class Allocator = allocator<Key>>
228class multiset
229{
230public:
231 // types:
232 typedef Key key_type;
233 typedef key_type value_type;
234 typedef Compare key_compare;
235 typedef key_compare value_compare;
236 typedef Allocator allocator_type;
237 typedef typename allocator_type::reference reference;
238 typedef typename allocator_type::const_reference const_reference;
239 typedef typename allocator_type::size_type size_type;
240 typedef typename allocator_type::difference_type difference_type;
241 typedef typename allocator_type::pointer pointer;
242 typedef typename allocator_type::const_pointer const_pointer;
243
244 typedef implementation-defined iterator;
245 typedef implementation-defined const_iterator;
246 typedef std::reverse_iterator<iterator> reverse_iterator;
247 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000248 typedef unspecified node_type; // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000249
250 // construct/copy/destroy:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000251 multiset()
252 noexcept(
253 is_nothrow_default_constructible<allocator_type>::value &&
254 is_nothrow_default_constructible<key_compare>::value &&
255 is_nothrow_copy_constructible<key_compare>::value);
256 explicit multiset(const value_compare& comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000257 multiset(const value_compare& comp, const allocator_type& a);
258 template <class InputIterator>
259 multiset(InputIterator first, InputIterator last,
260 const value_compare& comp = value_compare());
261 template <class InputIterator>
262 multiset(InputIterator first, InputIterator last,
263 const value_compare& comp, const allocator_type& a);
264 multiset(const multiset& s);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000265 multiset(multiset&& s)
266 noexcept(
267 is_nothrow_move_constructible<allocator_type>::value &&
268 is_nothrow_move_constructible<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000269 explicit multiset(const allocator_type& a);
270 multiset(const multiset& s, const allocator_type& a);
271 multiset(multiset&& s, const allocator_type& a);
272 multiset(initializer_list<value_type> il, const value_compare& comp = value_compare());
273 multiset(initializer_list<value_type> il, const value_compare& comp,
274 const allocator_type& a);
Marshall Clow631788a2013-09-11 00:06:45 +0000275 template <class InputIterator>
276 multiset(InputIterator first, InputIterator last, const allocator_type& a)
277 : set(first, last, Compare(), a) {} // C++14
278 multiset(initializer_list<value_type> il, const allocator_type& a)
279 : set(il, Compare(), a) {} // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000280 ~multiset();
281
282 multiset& operator=(const multiset& s);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000283 multiset& operator=(multiset&& s)
284 noexcept(
285 allocator_type::propagate_on_container_move_assignment::value &&
286 is_nothrow_move_assignable<allocator_type>::value &&
287 is_nothrow_move_assignable<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000288 multiset& operator=(initializer_list<value_type> il);
289
290 // iterators:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000291 iterator begin() noexcept;
292 const_iterator begin() const noexcept;
293 iterator end() noexcept;
294 const_iterator end() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000295
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000296 reverse_iterator rbegin() noexcept;
297 const_reverse_iterator rbegin() const noexcept;
298 reverse_iterator rend() noexcept;
299 const_reverse_iterator rend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000300
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000301 const_iterator cbegin() const noexcept;
302 const_iterator cend() const noexcept;
303 const_reverse_iterator crbegin() const noexcept;
304 const_reverse_iterator crend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000305
306 // capacity:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000307 bool empty() const noexcept;
308 size_type size() const noexcept;
309 size_type max_size() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000310
311 // modifiers:
312 template <class... Args>
313 iterator emplace(Args&&... args);
314 template <class... Args>
315 iterator emplace_hint(const_iterator position, Args&&... args);
316 iterator insert(const value_type& v);
317 iterator insert(value_type&& v);
318 iterator insert(const_iterator position, const value_type& v);
319 iterator insert(const_iterator position, value_type&& v);
320 template <class InputIterator>
321 void insert(InputIterator first, InputIterator last);
322 void insert(initializer_list<value_type> il);
323
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000324 node_type extract(const_iterator position); // C++17
325 node_type extract(const key_type& x); // C++17
326 iterator insert(node_type&& nh); // C++17
327 iterator insert(const_iterator hint, node_type&& nh); // C++17
328
Howard Hinnantc51e1022010-05-11 19:42:16 +0000329 iterator erase(const_iterator position);
Marshall Clow22ea5b82015-05-10 13:35:00 +0000330 iterator erase(iterator position); // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000331 size_type erase(const key_type& k);
332 iterator erase(const_iterator first, const_iterator last);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000333 void clear() noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000334
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000335 template<class C2>
336 void merge(multiset<Key, C2, Allocator>& source); // C++17
337 template<class C2>
338 void merge(multiset<Key, C2, Allocator>&& source); // C++17
339 template<class C2>
340 void merge(set<Key, C2, Allocator>& source); // C++17
341 template<class C2>
342 void merge(set<Key, C2, Allocator>&& source); // C++17
343
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000344 void swap(multiset& s)
345 noexcept(
346 __is_nothrow_swappable<key_compare>::value &&
347 (!allocator_type::propagate_on_container_swap::value ||
348 __is_nothrow_swappable<allocator_type>::value));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000349
350 // observers:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000351 allocator_type get_allocator() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000352 key_compare key_comp() const;
353 value_compare value_comp() const;
354
355 // set operations:
356 iterator find(const key_type& k);
357 const_iterator find(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000358 template<typename K>
359 iterator find(const K& x);
360 template<typename K>
361 const_iterator find(const K& x) const; // C++14
Marek Kurdejd7e019e2021-04-13 17:10:55 +0200362
Zoe Carver3ffbab12019-07-16 03:21:01 +0000363 template<typename K>
364 size_type count(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000365 size_type count(const key_type& k) const;
Marek Kurdejd7e019e2021-04-13 17:10:55 +0200366
367 bool contains(const key_type& x) const; // C++20
368 template<class K> bool contains(const K& x) const; // C++20
369
Howard Hinnantc51e1022010-05-11 19:42:16 +0000370 iterator lower_bound(const key_type& k);
371 const_iterator lower_bound(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000372 template<typename K>
373 iterator lower_bound(const K& x); // C++14
374 template<typename K>
375 const_iterator lower_bound(const K& x) const; // C++14
376
Howard Hinnantc51e1022010-05-11 19:42:16 +0000377 iterator upper_bound(const key_type& k);
378 const_iterator upper_bound(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000379 template<typename K>
380 iterator upper_bound(const K& x); // C++14
381 template<typename K>
382 const_iterator upper_bound(const K& x) const; // C++14
383
Howard Hinnantc51e1022010-05-11 19:42:16 +0000384 pair<iterator,iterator> equal_range(const key_type& k);
385 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000386 template<typename K>
387 pair<iterator,iterator> equal_range(const K& x); // C++14
388 template<typename K>
389 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000390};
391
392template <class Key, class Compare, class Allocator>
393bool
394operator==(const multiset<Key, Compare, Allocator>& x,
395 const multiset<Key, Compare, Allocator>& y);
396
397template <class Key, class Compare, class Allocator>
398bool
399operator< (const multiset<Key, Compare, Allocator>& x,
400 const multiset<Key, Compare, Allocator>& y);
401
402template <class Key, class Compare, class Allocator>
403bool
404operator!=(const multiset<Key, Compare, Allocator>& x,
405 const multiset<Key, Compare, Allocator>& y);
406
407template <class Key, class Compare, class Allocator>
408bool
409operator> (const multiset<Key, Compare, Allocator>& x,
410 const multiset<Key, Compare, Allocator>& y);
411
412template <class Key, class Compare, class Allocator>
413bool
414operator>=(const multiset<Key, Compare, Allocator>& x,
415 const multiset<Key, Compare, Allocator>& y);
416
417template <class Key, class Compare, class Allocator>
418bool
419operator<=(const multiset<Key, Compare, Allocator>& x,
420 const multiset<Key, Compare, Allocator>& y);
421
422// specialized algorithms:
423template <class Key, class Compare, class Allocator>
424void
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000425swap(multiset<Key, Compare, Allocator>& x, multiset<Key, Compare, Allocator>& y)
426 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000427
Marshall Clow29b53f22018-12-14 18:49:35 +0000428template <class Key, class Compare, class Allocator, class Predicate>
Marek Kurdeja98b1412020-05-02 13:58:03 +0200429typename multiset<Key, Compare, Allocator>::size_type
430erase_if(multiset<Key, Compare, Allocator>& c, Predicate pred); // C++20
Marshall Clow29b53f22018-12-14 18:49:35 +0000431
Howard Hinnantc51e1022010-05-11 19:42:16 +0000432} // std
433
434*/
435
436#include <__config>
Arthur O'Dwyer597cac42021-05-12 23:04:03 -0400437#include <__debug>
Christopher Di Bella55d7a822021-07-01 09:25:35 -0400438#include <__functional/is_transparent.h>
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000439#include <__node_handle>
Arthur O'Dwyer597cac42021-05-12 23:04:03 -0400440#include <__tree>
Christopher Di Bella41f26e82021-06-05 02:47:47 +0000441#include <__utility/forward.h>
Arthur O'Dwyer7deec122021-03-24 18:19:12 -0400442#include <compare>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000443#include <functional>
Arthur O'Dwyer7deec122021-03-24 18:19:12 -0400444#include <initializer_list>
Arthur O'Dwyerb6738bd2021-03-21 16:53:09 -0400445#include <iterator> // __libcpp_erase_if_container
Marshall Clow0a1e7502018-09-12 19:41:40 +0000446#include <version>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000447
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000448#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000449#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000450#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000451
452_LIBCPP_BEGIN_NAMESPACE_STD
453
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000454template <class _Key, class _Compare, class _Allocator>
455class multiset;
456
Howard Hinnantc51e1022010-05-11 19:42:16 +0000457template <class _Key, class _Compare = less<_Key>,
458 class _Allocator = allocator<_Key> >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000459class _LIBCPP_TEMPLATE_VIS set
Howard Hinnantc51e1022010-05-11 19:42:16 +0000460{
461public:
462 // types:
463 typedef _Key key_type;
464 typedef key_type value_type;
465 typedef _Compare key_compare;
466 typedef key_compare value_compare;
Arthur O'Dwyer6a752e12021-03-03 11:10:49 -0500467 typedef __identity_t<_Allocator> allocator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000468 typedef value_type& reference;
469 typedef const value_type& const_reference;
470
Marshall Clow5128cf32015-11-26 01:24:04 +0000471 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
472 "Allocator::value_type must be same type as value_type");
473
Howard Hinnantc51e1022010-05-11 19:42:16 +0000474private:
475 typedef __tree<value_type, value_compare, allocator_type> __base;
476 typedef allocator_traits<allocator_type> __alloc_traits;
477 typedef typename __base::__node_holder __node_holder;
478
479 __base __tree_;
480
481public:
482 typedef typename __base::pointer pointer;
483 typedef typename __base::const_pointer const_pointer;
484 typedef typename __base::size_type size_type;
485 typedef typename __base::difference_type difference_type;
486 typedef typename __base::const_iterator iterator;
487 typedef typename __base::const_iterator const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000488 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
489 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000490
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000491#if _LIBCPP_STD_VER > 14
492 typedef __set_node_handle<typename __base::__node, allocator_type> node_type;
493 typedef __insert_return_type<iterator, node_type> insert_return_type;
494#endif
495
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000496 template <class _Key2, class _Compare2, class _Alloc2>
497 friend class _LIBCPP_TEMPLATE_VIS set;
498 template <class _Key2, class _Compare2, class _Alloc2>
499 friend class _LIBCPP_TEMPLATE_VIS multiset;
500
Howard Hinnant192cf032010-09-23 16:27:36 +0000501 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +0000502 set()
503 _NOEXCEPT_(
504 is_nothrow_default_constructible<allocator_type>::value &&
505 is_nothrow_default_constructible<key_compare>::value &&
506 is_nothrow_copy_constructible<key_compare>::value)
507 : __tree_(value_compare()) {}
508
509 _LIBCPP_INLINE_VISIBILITY
510 explicit set(const value_compare& __comp)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000511 _NOEXCEPT_(
512 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000513 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000514 : __tree_(__comp) {}
Marshall Clow7086a5a2014-03-10 04:50:10 +0000515
Howard Hinnant192cf032010-09-23 16:27:36 +0000516 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7ed23a72014-03-05 19:06:20 +0000517 explicit set(const value_compare& __comp, const allocator_type& __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000518 : __tree_(__comp, __a) {}
519 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000520 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000521 set(_InputIterator __f, _InputIterator __l,
522 const value_compare& __comp = value_compare())
523 : __tree_(__comp)
524 {
525 insert(__f, __l);
526 }
527
528 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000529 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000530 set(_InputIterator __f, _InputIterator __l, const value_compare& __comp,
531 const allocator_type& __a)
532 : __tree_(__comp, __a)
533 {
534 insert(__f, __l);
535 }
536
Marshall Clow631788a2013-09-11 00:06:45 +0000537#if _LIBCPP_STD_VER > 11
538 template <class _InputIterator>
Louis Dionned2322c82018-11-01 14:41:37 +0000539 _LIBCPP_INLINE_VISIBILITY
Marshall Clow631788a2013-09-11 00:06:45 +0000540 set(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
541 : set(__f, __l, key_compare(), __a) {}
542#endif
543
Howard Hinnant192cf032010-09-23 16:27:36 +0000544 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000545 set(const set& __s)
546 : __tree_(__s.__tree_)
547 {
548 insert(__s.begin(), __s.end());
549 }
550
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000551 _LIBCPP_INLINE_VISIBILITY
552 set& operator=(const set& __s)
553 {
554 __tree_ = __s.__tree_;
555 return *this;
556 }
557
Eric Fiselier615961b2017-04-18 20:58:03 +0000558#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant192cf032010-09-23 16:27:36 +0000559 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000560 set(set&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000561 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000562 : __tree_(_VSTD::move(__s.__tree_)) {}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400563#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000564
Howard Hinnant192cf032010-09-23 16:27:36 +0000565 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000566 explicit set(const allocator_type& __a)
567 : __tree_(__a) {}
568
Howard Hinnant192cf032010-09-23 16:27:36 +0000569 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000570 set(const set& __s, const allocator_type& __a)
571 : __tree_(__s.__tree_.value_comp(), __a)
572 {
573 insert(__s.begin(), __s.end());
574 }
575
Eric Fiselier615961b2017-04-18 20:58:03 +0000576#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000577 set(set&& __s, const allocator_type& __a);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000578
Howard Hinnant192cf032010-09-23 16:27:36 +0000579 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000580 set(initializer_list<value_type> __il, const value_compare& __comp = value_compare())
581 : __tree_(__comp)
582 {
583 insert(__il.begin(), __il.end());
584 }
585
Howard Hinnant192cf032010-09-23 16:27:36 +0000586 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000587 set(initializer_list<value_type> __il, const value_compare& __comp,
588 const allocator_type& __a)
589 : __tree_(__comp, __a)
590 {
591 insert(__il.begin(), __il.end());
592 }
593
Marshall Clow631788a2013-09-11 00:06:45 +0000594#if _LIBCPP_STD_VER > 11
Louis Dionned2322c82018-11-01 14:41:37 +0000595 _LIBCPP_INLINE_VISIBILITY
Marshall Clow631788a2013-09-11 00:06:45 +0000596 set(initializer_list<value_type> __il, const allocator_type& __a)
597 : set(__il, key_compare(), __a) {}
598#endif
599
Howard Hinnant192cf032010-09-23 16:27:36 +0000600 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000601 set& operator=(initializer_list<value_type> __il)
602 {
603 __tree_.__assign_unique(__il.begin(), __il.end());
604 return *this;
605 }
606
Howard Hinnant192cf032010-09-23 16:27:36 +0000607 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000608 set& operator=(set&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000609 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000610 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000611 __tree_ = _VSTD::move(__s.__tree_);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000612 return *this;
613 }
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400614#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000615
Howard Hinnant192cf032010-09-23 16:27:36 +0000616 _LIBCPP_INLINE_VISIBILITY
Louis Dionne69c42c02019-04-11 16:14:56 +0000617 ~set() {
618 static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), "");
619 }
620
621 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000622 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000623 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000624 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000625 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000626 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000627 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000628 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000629
Howard Hinnant192cf032010-09-23 16:27:36 +0000630 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000631 reverse_iterator rbegin() _NOEXCEPT
632 {return reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +0000633 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000634 const_reverse_iterator rbegin() const _NOEXCEPT
635 {return const_reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +0000636 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000637 reverse_iterator rend() _NOEXCEPT
638 {return reverse_iterator(begin());}
Howard Hinnant192cf032010-09-23 16:27:36 +0000639 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000640 const_reverse_iterator rend() const _NOEXCEPT
641 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000642
Howard Hinnant192cf032010-09-23 16:27:36 +0000643 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000644 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000645 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000646 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000647 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000648 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000649 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000650 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000651
Marshall Clow425f5752017-11-15 05:51:26 +0000652 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000653 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant192cf032010-09-23 16:27:36 +0000654 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000655 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000656 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000657 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000658
659 // modifiers:
Eric Fiselier615961b2017-04-18 20:58:03 +0000660#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000661 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +0000662 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000663 pair<iterator, bool> emplace(_Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000664 {return __tree_.__emplace_unique(_VSTD::forward<_Args>(__args)...);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000665 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +0000666 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000667 iterator emplace_hint(const_iterator __p, _Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000668 {return __tree_.__emplace_hint_unique(__p, _VSTD::forward<_Args>(__args)...);}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400669#endif // _LIBCPP_CXX03_LANG
Eric Fiselier615961b2017-04-18 20:58:03 +0000670
Howard Hinnant192cf032010-09-23 16:27:36 +0000671 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000672 pair<iterator,bool> insert(const value_type& __v)
673 {return __tree_.__insert_unique(__v);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000674 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000675 iterator insert(const_iterator __p, const value_type& __v)
676 {return __tree_.__insert_unique(__p, __v);}
Eric Fiselier615961b2017-04-18 20:58:03 +0000677
Howard Hinnantc51e1022010-05-11 19:42:16 +0000678 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000679 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000680 void insert(_InputIterator __f, _InputIterator __l)
681 {
682 for (const_iterator __e = cend(); __f != __l; ++__f)
683 __tree_.__insert_unique(__e, *__f);
684 }
685
Eric Fiselier615961b2017-04-18 20:58:03 +0000686#ifndef _LIBCPP_CXX03_LANG
687 _LIBCPP_INLINE_VISIBILITY
688 pair<iterator,bool> insert(value_type&& __v)
689 {return __tree_.__insert_unique(_VSTD::move(__v));}
690
691 _LIBCPP_INLINE_VISIBILITY
692 iterator insert(const_iterator __p, value_type&& __v)
693 {return __tree_.__insert_unique(__p, _VSTD::move(__v));}
694
Howard Hinnant192cf032010-09-23 16:27:36 +0000695 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000696 void insert(initializer_list<value_type> __il)
697 {insert(__il.begin(), __il.end());}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400698#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000699
Howard Hinnant192cf032010-09-23 16:27:36 +0000700 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000701 iterator erase(const_iterator __p) {return __tree_.erase(__p);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000702 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000703 size_type erase(const key_type& __k)
704 {return __tree_.__erase_unique(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000705 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000706 iterator erase(const_iterator __f, const_iterator __l)
707 {return __tree_.erase(__f, __l);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000708 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000709 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000710
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000711#if _LIBCPP_STD_VER > 14
712 _LIBCPP_INLINE_VISIBILITY
713 insert_return_type insert(node_type&& __nh)
714 {
715 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
716 "node_type with incompatible allocator passed to set::insert()");
717 return __tree_.template __node_handle_insert_unique<
718 node_type, insert_return_type>(_VSTD::move(__nh));
719 }
720 _LIBCPP_INLINE_VISIBILITY
721 iterator insert(const_iterator __hint, node_type&& __nh)
722 {
723 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
724 "node_type with incompatible allocator passed to set::insert()");
725 return __tree_.template __node_handle_insert_unique<node_type>(
726 __hint, _VSTD::move(__nh));
727 }
728 _LIBCPP_INLINE_VISIBILITY
729 node_type extract(key_type const& __key)
730 {
731 return __tree_.template __node_handle_extract<node_type>(__key);
732 }
733 _LIBCPP_INLINE_VISIBILITY
734 node_type extract(const_iterator __it)
735 {
736 return __tree_.template __node_handle_extract<node_type>(__it);
737 }
Louis Dionned2322c82018-11-01 14:41:37 +0000738 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000739 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +0000740 void merge(set<key_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000741 {
742 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
743 "merging container with incompatible allocator");
744 __tree_.__node_handle_merge_unique(__source.__tree_);
745 }
Louis Dionned2322c82018-11-01 14:41:37 +0000746 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000747 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +0000748 void merge(set<key_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000749 {
750 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
751 "merging container with incompatible allocator");
752 __tree_.__node_handle_merge_unique(__source.__tree_);
753 }
Louis Dionned2322c82018-11-01 14:41:37 +0000754 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000755 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +0000756 void merge(multiset<key_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000757 {
758 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
759 "merging container with incompatible allocator");
760 __tree_.__node_handle_merge_unique(__source.__tree_);
761 }
Louis Dionned2322c82018-11-01 14:41:37 +0000762 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000763 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +0000764 void merge(multiset<key_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000765 {
766 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
767 "merging container with incompatible allocator");
768 __tree_.__node_handle_merge_unique(__source.__tree_);
769 }
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000770#endif
771
Howard Hinnant192cf032010-09-23 16:27:36 +0000772 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000773 void swap(set& __s) _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
774 {__tree_.swap(__s.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000775
Howard Hinnant192cf032010-09-23 16:27:36 +0000776 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000777 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000778 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000779 key_compare key_comp() const {return __tree_.value_comp();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000780 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000781 value_compare value_comp() const {return __tree_.value_comp();}
782
783 // set operations:
Howard Hinnant192cf032010-09-23 16:27:36 +0000784 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000785 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000786 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000787 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000788#if _LIBCPP_STD_VER > 11
789 template <typename _K2>
790 _LIBCPP_INLINE_VISIBILITY
791 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
792 find(const _K2& __k) {return __tree_.find(__k);}
793 template <typename _K2>
794 _LIBCPP_INLINE_VISIBILITY
795 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
796 find(const _K2& __k) const {return __tree_.find(__k);}
797#endif
798
Howard Hinnant192cf032010-09-23 16:27:36 +0000799 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000800 size_type count(const key_type& __k) const
801 {return __tree_.__count_unique(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +0000802#if _LIBCPP_STD_VER > 11
803 template <typename _K2>
804 _LIBCPP_INLINE_VISIBILITY
805 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +0000806 count(const _K2& __k) const {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +0000807#endif
Zoe Carver3ffbab12019-07-16 03:21:01 +0000808
809#if _LIBCPP_STD_VER > 17
810 _LIBCPP_INLINE_VISIBILITY
811 bool contains(const key_type& __k) const {return find(__k) != end();}
Marek Kurdejd7e019e2021-04-13 17:10:55 +0200812 template <typename _K2>
813 _LIBCPP_INLINE_VISIBILITY
814 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
815 contains(const _K2& __k) const { return find(__k) != end(); }
Zoe Carver3ffbab12019-07-16 03:21:01 +0000816#endif // _LIBCPP_STD_VER > 17
817
Howard Hinnant192cf032010-09-23 16:27:36 +0000818 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000819 iterator lower_bound(const key_type& __k)
820 {return __tree_.lower_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000821 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000822 const_iterator lower_bound(const key_type& __k) const
823 {return __tree_.lower_bound(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000824#if _LIBCPP_STD_VER > 11
825 template <typename _K2>
826 _LIBCPP_INLINE_VISIBILITY
827 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
828 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
829
830 template <typename _K2>
831 _LIBCPP_INLINE_VISIBILITY
832 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
833 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
834#endif
835
Howard Hinnant192cf032010-09-23 16:27:36 +0000836 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000837 iterator upper_bound(const key_type& __k)
838 {return __tree_.upper_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000839 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000840 const_iterator upper_bound(const key_type& __k) const
841 {return __tree_.upper_bound(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000842#if _LIBCPP_STD_VER > 11
843 template <typename _K2>
844 _LIBCPP_INLINE_VISIBILITY
845 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
846 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
847 template <typename _K2>
848 _LIBCPP_INLINE_VISIBILITY
849 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
850 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
851#endif
852
Howard Hinnant192cf032010-09-23 16:27:36 +0000853 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000854 pair<iterator,iterator> equal_range(const key_type& __k)
855 {return __tree_.__equal_range_unique(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000856 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000857 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
858 {return __tree_.__equal_range_unique(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000859#if _LIBCPP_STD_VER > 11
860 template <typename _K2>
861 _LIBCPP_INLINE_VISIBILITY
862 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +0000863 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000864 template <typename _K2>
865 _LIBCPP_INLINE_VISIBILITY
866 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +0000867 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000868#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000869};
870
Louis Dionned59f8a52021-08-17 11:59:07 -0400871#if _LIBCPP_STD_VER >= 17
Louis Dionne27ecc152019-06-11 18:21:08 +0000872template<class _InputIterator,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500873 class _Compare = less<__iter_value_type<_InputIterator>>,
874 class _Allocator = allocator<__iter_value_type<_InputIterator>>,
Louis Dionne25547162021-08-17 12:26:09 -0400875 class = enable_if_t<__is_allocator<_Allocator>::value, void>,
876 class = enable_if_t<!__is_allocator<_Compare>::value, void>>
Louis Dionne27ecc152019-06-11 18:21:08 +0000877set(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500878 -> set<__iter_value_type<_InputIterator>, _Compare, _Allocator>;
Louis Dionne27ecc152019-06-11 18:21:08 +0000879
880template<class _Key, class _Compare = less<_Key>,
881 class _Allocator = allocator<_Key>,
Louis Dionne25547162021-08-17 12:26:09 -0400882 class = enable_if_t<__is_allocator<_Allocator>::value, void>,
883 class = enable_if_t<!__is_allocator<_Compare>::value, void>>
Louis Dionne27ecc152019-06-11 18:21:08 +0000884set(initializer_list<_Key>, _Compare = _Compare(), _Allocator = _Allocator())
885 -> set<_Key, _Compare, _Allocator>;
886
887template<class _InputIterator, class _Allocator,
Louis Dionne25547162021-08-17 12:26:09 -0400888 class = enable_if_t<__is_allocator<_Allocator>::value, void>>
Louis Dionne27ecc152019-06-11 18:21:08 +0000889set(_InputIterator, _InputIterator, _Allocator)
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500890 -> set<__iter_value_type<_InputIterator>,
891 less<__iter_value_type<_InputIterator>>, _Allocator>;
Louis Dionne27ecc152019-06-11 18:21:08 +0000892
893template<class _Key, class _Allocator,
Louis Dionne25547162021-08-17 12:26:09 -0400894 class = enable_if_t<__is_allocator<_Allocator>::value, void>>
Louis Dionne27ecc152019-06-11 18:21:08 +0000895set(initializer_list<_Key>, _Allocator)
896 -> set<_Key, less<_Key>, _Allocator>;
897#endif
898
Eric Fiselier615961b2017-04-18 20:58:03 +0000899#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000900
901template <class _Key, class _Compare, class _Allocator>
902set<_Key, _Compare, _Allocator>::set(set&& __s, const allocator_type& __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000903 : __tree_(_VSTD::move(__s.__tree_), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000904{
905 if (__a != __s.get_allocator())
906 {
907 const_iterator __e = cend();
908 while (!__s.empty())
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000909 insert(__e, _VSTD::move(__s.__tree_.remove(__s.begin())->__value_));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000910 }
911}
912
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400913#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000914
915template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000916inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000917bool
918operator==(const set<_Key, _Compare, _Allocator>& __x,
919 const set<_Key, _Compare, _Allocator>& __y)
920{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000921 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000922}
923
924template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000925inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000926bool
927operator< (const set<_Key, _Compare, _Allocator>& __x,
928 const set<_Key, _Compare, _Allocator>& __y)
929{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000930 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000931}
932
933template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000934inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000935bool
936operator!=(const set<_Key, _Compare, _Allocator>& __x,
937 const set<_Key, _Compare, _Allocator>& __y)
938{
939 return !(__x == __y);
940}
941
942template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000943inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000944bool
945operator> (const set<_Key, _Compare, _Allocator>& __x,
946 const set<_Key, _Compare, _Allocator>& __y)
947{
948 return __y < __x;
949}
950
951template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000952inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000953bool
954operator>=(const set<_Key, _Compare, _Allocator>& __x,
955 const set<_Key, _Compare, _Allocator>& __y)
956{
957 return !(__x < __y);
958}
959
960template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000961inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000962bool
963operator<=(const set<_Key, _Compare, _Allocator>& __x,
964 const set<_Key, _Compare, _Allocator>& __y)
965{
966 return !(__y < __x);
967}
968
969// specialized algorithms:
970template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000971inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000972void
973swap(set<_Key, _Compare, _Allocator>& __x,
974 set<_Key, _Compare, _Allocator>& __y)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000975 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000976{
977 __x.swap(__y);
978}
979
Marshall Clow29b53f22018-12-14 18:49:35 +0000980#if _LIBCPP_STD_VER > 17
981template <class _Key, class _Compare, class _Allocator, class _Predicate>
982inline _LIBCPP_INLINE_VISIBILITY
Marek Kurdeja98b1412020-05-02 13:58:03 +0200983 typename set<_Key, _Compare, _Allocator>::size_type
984 erase_if(set<_Key, _Compare, _Allocator>& __c, _Predicate __pred) {
Arthur O'Dwyerb6738bd2021-03-21 16:53:09 -0400985 return _VSTD::__libcpp_erase_if_container(__c, __pred);
Marek Kurdeja98b1412020-05-02 13:58:03 +0200986}
Marshall Clow29b53f22018-12-14 18:49:35 +0000987#endif
988
Howard Hinnantc51e1022010-05-11 19:42:16 +0000989template <class _Key, class _Compare = less<_Key>,
990 class _Allocator = allocator<_Key> >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000991class _LIBCPP_TEMPLATE_VIS multiset
Howard Hinnantc51e1022010-05-11 19:42:16 +0000992{
993public:
994 // types:
Arthur O'Dwyer6a752e12021-03-03 11:10:49 -0500995 typedef _Key key_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000996 typedef key_type value_type;
Arthur O'Dwyer6a752e12021-03-03 11:10:49 -0500997 typedef _Compare key_compare;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000998 typedef key_compare value_compare;
Arthur O'Dwyer6a752e12021-03-03 11:10:49 -0500999 typedef __identity_t<_Allocator> allocator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001000 typedef value_type& reference;
1001 typedef const value_type& const_reference;
1002
Marshall Clow5128cf32015-11-26 01:24:04 +00001003 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
1004 "Allocator::value_type must be same type as value_type");
1005
Howard Hinnantc51e1022010-05-11 19:42:16 +00001006private:
1007 typedef __tree<value_type, value_compare, allocator_type> __base;
1008 typedef allocator_traits<allocator_type> __alloc_traits;
1009 typedef typename __base::__node_holder __node_holder;
1010
1011 __base __tree_;
1012
1013public:
1014 typedef typename __base::pointer pointer;
1015 typedef typename __base::const_pointer const_pointer;
1016 typedef typename __base::size_type size_type;
1017 typedef typename __base::difference_type difference_type;
1018 typedef typename __base::const_iterator iterator;
1019 typedef typename __base::const_iterator const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001020 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1021 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001022
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001023#if _LIBCPP_STD_VER > 14
1024 typedef __set_node_handle<typename __base::__node, allocator_type> node_type;
1025#endif
1026
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001027 template <class _Key2, class _Compare2, class _Alloc2>
1028 friend class _LIBCPP_TEMPLATE_VIS set;
1029 template <class _Key2, class _Compare2, class _Alloc2>
1030 friend class _LIBCPP_TEMPLATE_VIS multiset;
1031
Howard Hinnantc51e1022010-05-11 19:42:16 +00001032 // construct/copy/destroy:
Howard Hinnant192cf032010-09-23 16:27:36 +00001033 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +00001034 multiset()
1035 _NOEXCEPT_(
1036 is_nothrow_default_constructible<allocator_type>::value &&
1037 is_nothrow_default_constructible<key_compare>::value &&
1038 is_nothrow_copy_constructible<key_compare>::value)
1039 : __tree_(value_compare()) {}
1040
1041 _LIBCPP_INLINE_VISIBILITY
1042 explicit multiset(const value_compare& __comp)
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001043 _NOEXCEPT_(
1044 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001045 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001046 : __tree_(__comp) {}
Marshall Clow7086a5a2014-03-10 04:50:10 +00001047
Howard Hinnant192cf032010-09-23 16:27:36 +00001048 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7ed23a72014-03-05 19:06:20 +00001049 explicit multiset(const value_compare& __comp, const allocator_type& __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001050 : __tree_(__comp, __a) {}
1051 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001052 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001053 multiset(_InputIterator __f, _InputIterator __l,
1054 const value_compare& __comp = value_compare())
1055 : __tree_(__comp)
1056 {
1057 insert(__f, __l);
1058 }
1059
Marshall Clow631788a2013-09-11 00:06:45 +00001060#if _LIBCPP_STD_VER > 11
1061 template <class _InputIterator>
Louis Dionned2322c82018-11-01 14:41:37 +00001062 _LIBCPP_INLINE_VISIBILITY
Marshall Clow631788a2013-09-11 00:06:45 +00001063 multiset(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
1064 : multiset(__f, __l, key_compare(), __a) {}
1065#endif
1066
Howard Hinnantc51e1022010-05-11 19:42:16 +00001067 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001068 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001069 multiset(_InputIterator __f, _InputIterator __l,
1070 const value_compare& __comp, const allocator_type& __a)
1071 : __tree_(__comp, __a)
1072 {
1073 insert(__f, __l);
1074 }
1075
Howard Hinnant192cf032010-09-23 16:27:36 +00001076 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001077 multiset(const multiset& __s)
1078 : __tree_(__s.__tree_.value_comp(),
1079 __alloc_traits::select_on_container_copy_construction(__s.__tree_.__alloc()))
1080 {
1081 insert(__s.begin(), __s.end());
1082 }
1083
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001084 _LIBCPP_INLINE_VISIBILITY
1085 multiset& operator=(const multiset& __s)
1086 {
1087 __tree_ = __s.__tree_;
1088 return *this;
1089 }
1090
Eric Fiselier615961b2017-04-18 20:58:03 +00001091#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant192cf032010-09-23 16:27:36 +00001092 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001093 multiset(multiset&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001094 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001095 : __tree_(_VSTD::move(__s.__tree_)) {}
Eric Fiselier615961b2017-04-18 20:58:03 +00001096
1097 multiset(multiset&& __s, const allocator_type& __a);
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001098#endif // _LIBCPP_CXX03_LANG
Howard Hinnant192cf032010-09-23 16:27:36 +00001099 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001100 explicit multiset(const allocator_type& __a)
1101 : __tree_(__a) {}
Howard Hinnant192cf032010-09-23 16:27:36 +00001102 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001103 multiset(const multiset& __s, const allocator_type& __a)
1104 : __tree_(__s.__tree_.value_comp(), __a)
1105 {
1106 insert(__s.begin(), __s.end());
1107 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001108
Eric Fiselier615961b2017-04-18 20:58:03 +00001109#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant192cf032010-09-23 16:27:36 +00001110 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001111 multiset(initializer_list<value_type> __il, const value_compare& __comp = value_compare())
1112 : __tree_(__comp)
1113 {
1114 insert(__il.begin(), __il.end());
1115 }
1116
Howard Hinnant192cf032010-09-23 16:27:36 +00001117 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001118 multiset(initializer_list<value_type> __il, const value_compare& __comp,
1119 const allocator_type& __a)
1120 : __tree_(__comp, __a)
1121 {
1122 insert(__il.begin(), __il.end());
1123 }
1124
Marshall Clow631788a2013-09-11 00:06:45 +00001125#if _LIBCPP_STD_VER > 11
Louis Dionned2322c82018-11-01 14:41:37 +00001126 _LIBCPP_INLINE_VISIBILITY
Marshall Clow631788a2013-09-11 00:06:45 +00001127 multiset(initializer_list<value_type> __il, const allocator_type& __a)
1128 : multiset(__il, key_compare(), __a) {}
1129#endif
1130
Howard Hinnant192cf032010-09-23 16:27:36 +00001131 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001132 multiset& operator=(initializer_list<value_type> __il)
1133 {
1134 __tree_.__assign_multi(__il.begin(), __il.end());
1135 return *this;
1136 }
1137
Howard Hinnant192cf032010-09-23 16:27:36 +00001138 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001139 multiset& operator=(multiset&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001140 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001141 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001142 __tree_ = _VSTD::move(__s.__tree_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001143 return *this;
1144 }
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001145#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001146
Howard Hinnant192cf032010-09-23 16:27:36 +00001147 _LIBCPP_INLINE_VISIBILITY
Louis Dionne69c42c02019-04-11 16:14:56 +00001148 ~multiset() {
1149 static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), "");
1150 }
1151
1152 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001153 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001154 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001155 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001156 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001157 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001158 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001159 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001160
Howard Hinnant192cf032010-09-23 16:27:36 +00001161 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001162 reverse_iterator rbegin() _NOEXCEPT
1163 {return reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +00001164 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001165 const_reverse_iterator rbegin() const _NOEXCEPT
1166 {return const_reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +00001167 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001168 reverse_iterator rend() _NOEXCEPT
1169 {return reverse_iterator(begin());}
Howard Hinnant192cf032010-09-23 16:27:36 +00001170 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001171 const_reverse_iterator rend() const _NOEXCEPT
1172 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001173
Howard Hinnant192cf032010-09-23 16:27:36 +00001174 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001175 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001176 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001177 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001178 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001179 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001180 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001181 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001182
Marshall Clow425f5752017-11-15 05:51:26 +00001183 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001184 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant192cf032010-09-23 16:27:36 +00001185 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001186 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001187 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001188 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001189
1190 // modifiers:
Eric Fiselier615961b2017-04-18 20:58:03 +00001191#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001192 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +00001193 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001194 iterator emplace(_Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001195 {return __tree_.__emplace_multi(_VSTD::forward<_Args>(__args)...);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001196 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +00001197 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001198 iterator emplace_hint(const_iterator __p, _Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001199 {return __tree_.__emplace_hint_multi(__p, _VSTD::forward<_Args>(__args)...);}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001200#endif // _LIBCPP_CXX03_LANG
Eric Fiselier615961b2017-04-18 20:58:03 +00001201
Howard Hinnant192cf032010-09-23 16:27:36 +00001202 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001203 iterator insert(const value_type& __v)
1204 {return __tree_.__insert_multi(__v);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001205 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001206 iterator insert(const_iterator __p, const value_type& __v)
1207 {return __tree_.__insert_multi(__p, __v);}
Eric Fiselier615961b2017-04-18 20:58:03 +00001208
Howard Hinnantc51e1022010-05-11 19:42:16 +00001209 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001210 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001211 void insert(_InputIterator __f, _InputIterator __l)
1212 {
1213 for (const_iterator __e = cend(); __f != __l; ++__f)
1214 __tree_.__insert_multi(__e, *__f);
1215 }
1216
Eric Fiselier615961b2017-04-18 20:58:03 +00001217#ifndef _LIBCPP_CXX03_LANG
1218 _LIBCPP_INLINE_VISIBILITY
1219 iterator insert(value_type&& __v)
1220 {return __tree_.__insert_multi(_VSTD::move(__v));}
1221
1222 _LIBCPP_INLINE_VISIBILITY
1223 iterator insert(const_iterator __p, value_type&& __v)
1224 {return __tree_.__insert_multi(__p, _VSTD::move(__v));}
1225
Howard Hinnant192cf032010-09-23 16:27:36 +00001226 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001227 void insert(initializer_list<value_type> __il)
1228 {insert(__il.begin(), __il.end());}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001229#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001230
Howard Hinnant192cf032010-09-23 16:27:36 +00001231 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001232 iterator erase(const_iterator __p) {return __tree_.erase(__p);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001233 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001234 size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001235 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001236 iterator erase(const_iterator __f, const_iterator __l)
1237 {return __tree_.erase(__f, __l);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001238 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001239 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001240
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001241#if _LIBCPP_STD_VER > 14
1242 _LIBCPP_INLINE_VISIBILITY
1243 iterator insert(node_type&& __nh)
1244 {
1245 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1246 "node_type with incompatible allocator passed to multiset::insert()");
1247 return __tree_.template __node_handle_insert_multi<node_type>(
1248 _VSTD::move(__nh));
1249 }
1250 _LIBCPP_INLINE_VISIBILITY
1251 iterator insert(const_iterator __hint, node_type&& __nh)
1252 {
1253 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1254 "node_type with incompatible allocator passed to multiset::insert()");
1255 return __tree_.template __node_handle_insert_multi<node_type>(
1256 __hint, _VSTD::move(__nh));
1257 }
1258 _LIBCPP_INLINE_VISIBILITY
1259 node_type extract(key_type const& __key)
1260 {
1261 return __tree_.template __node_handle_extract<node_type>(__key);
1262 }
1263 _LIBCPP_INLINE_VISIBILITY
1264 node_type extract(const_iterator __it)
1265 {
1266 return __tree_.template __node_handle_extract<node_type>(__it);
1267 }
Louis Dionned2322c82018-11-01 14:41:37 +00001268 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001269 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001270 void merge(multiset<key_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001271 {
1272 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1273 "merging container with incompatible allocator");
1274 __tree_.__node_handle_merge_multi(__source.__tree_);
1275 }
Louis Dionned2322c82018-11-01 14:41:37 +00001276 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001277 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001278 void merge(multiset<key_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001279 {
1280 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1281 "merging container with incompatible allocator");
1282 __tree_.__node_handle_merge_multi(__source.__tree_);
1283 }
Louis Dionned2322c82018-11-01 14:41:37 +00001284 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001285 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001286 void merge(set<key_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001287 {
1288 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1289 "merging container with incompatible allocator");
1290 __tree_.__node_handle_merge_multi(__source.__tree_);
1291 }
Louis Dionned2322c82018-11-01 14:41:37 +00001292 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001293 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001294 void merge(set<key_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001295 {
1296 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1297 "merging container with incompatible allocator");
1298 __tree_.__node_handle_merge_multi(__source.__tree_);
1299 }
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001300#endif
1301
Howard Hinnant192cf032010-09-23 16:27:36 +00001302 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001303 void swap(multiset& __s)
1304 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1305 {__tree_.swap(__s.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001306
Howard Hinnant192cf032010-09-23 16:27:36 +00001307 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001308 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001309 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001310 key_compare key_comp() const {return __tree_.value_comp();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001311 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001312 value_compare value_comp() const {return __tree_.value_comp();}
1313
1314 // set operations:
Howard Hinnant192cf032010-09-23 16:27:36 +00001315 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001316 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001317 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001318 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +00001319#if _LIBCPP_STD_VER > 11
1320 template <typename _K2>
1321 _LIBCPP_INLINE_VISIBILITY
Mark de Wever9d7aa7a2021-05-09 18:22:52 +02001322 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
Marshall Clowc0152142013-08-13 01:11:06 +00001323 find(const _K2& __k) {return __tree_.find(__k);}
1324 template <typename _K2>
1325 _LIBCPP_INLINE_VISIBILITY
Mark de Wever9d7aa7a2021-05-09 18:22:52 +02001326 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
Marshall Clowc0152142013-08-13 01:11:06 +00001327 find(const _K2& __k) const {return __tree_.find(__k);}
1328#endif
1329
Howard Hinnant192cf032010-09-23 16:27:36 +00001330 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001331 size_type count(const key_type& __k) const
1332 {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001333#if _LIBCPP_STD_VER > 11
1334 template <typename _K2>
1335 _LIBCPP_INLINE_VISIBILITY
1336 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
Marshall Clow5571bcd2018-01-07 17:39:57 +00001337 count(const _K2& __k) const {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001338#endif
Marshall Clowc0152142013-08-13 01:11:06 +00001339
Zoe Carver3ffbab12019-07-16 03:21:01 +00001340#if _LIBCPP_STD_VER > 17
1341 _LIBCPP_INLINE_VISIBILITY
1342 bool contains(const key_type& __k) const {return find(__k) != end();}
Marek Kurdejd7e019e2021-04-13 17:10:55 +02001343 template <typename _K2>
1344 _LIBCPP_INLINE_VISIBILITY
1345 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
1346 contains(const _K2& __k) const { return find(__k) != end(); }
Zoe Carver3ffbab12019-07-16 03:21:01 +00001347#endif // _LIBCPP_STD_VER > 17
1348
Howard Hinnant192cf032010-09-23 16:27:36 +00001349 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001350 iterator lower_bound(const key_type& __k)
1351 {return __tree_.lower_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001352 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001353 const_iterator lower_bound(const key_type& __k) const
1354 {return __tree_.lower_bound(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +00001355#if _LIBCPP_STD_VER > 11
1356 template <typename _K2>
1357 _LIBCPP_INLINE_VISIBILITY
Mark de Wever9d7aa7a2021-05-09 18:22:52 +02001358 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
Marshall Clowc0152142013-08-13 01:11:06 +00001359 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
1360
1361 template <typename _K2>
1362 _LIBCPP_INLINE_VISIBILITY
Mark de Wever9d7aa7a2021-05-09 18:22:52 +02001363 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
Marshall Clowc0152142013-08-13 01:11:06 +00001364 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
1365#endif
1366
Howard Hinnant192cf032010-09-23 16:27:36 +00001367 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001368 iterator upper_bound(const key_type& __k)
1369 {return __tree_.upper_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001370 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001371 const_iterator upper_bound(const key_type& __k) const
1372 {return __tree_.upper_bound(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +00001373#if _LIBCPP_STD_VER > 11
1374 template <typename _K2>
1375 _LIBCPP_INLINE_VISIBILITY
Mark de Wever9d7aa7a2021-05-09 18:22:52 +02001376 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
Marshall Clowc0152142013-08-13 01:11:06 +00001377 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
1378 template <typename _K2>
1379 _LIBCPP_INLINE_VISIBILITY
Mark de Wever9d7aa7a2021-05-09 18:22:52 +02001380 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
Marshall Clowc0152142013-08-13 01:11:06 +00001381 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
1382#endif
1383
Howard Hinnant192cf032010-09-23 16:27:36 +00001384 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001385 pair<iterator,iterator> equal_range(const key_type& __k)
1386 {return __tree_.__equal_range_multi(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001387 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001388 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
1389 {return __tree_.__equal_range_multi(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +00001390#if _LIBCPP_STD_VER > 11
1391 template <typename _K2>
1392 _LIBCPP_INLINE_VISIBILITY
Mark de Wever9d7aa7a2021-05-09 18:22:52 +02001393 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
Marshall Clowc0152142013-08-13 01:11:06 +00001394 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
1395 template <typename _K2>
1396 _LIBCPP_INLINE_VISIBILITY
Mark de Wever9d7aa7a2021-05-09 18:22:52 +02001397 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
Marshall Clowc0152142013-08-13 01:11:06 +00001398 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
1399#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001400};
1401
Louis Dionned59f8a52021-08-17 11:59:07 -04001402#if _LIBCPP_STD_VER >= 17
Louis Dionne27ecc152019-06-11 18:21:08 +00001403template<class _InputIterator,
Arthur O'Dwyer56226762021-03-03 23:02:20 -05001404 class _Compare = less<__iter_value_type<_InputIterator>>,
1405 class _Allocator = allocator<__iter_value_type<_InputIterator>>,
Louis Dionne25547162021-08-17 12:26:09 -04001406 class = enable_if_t<__is_allocator<_Allocator>::value, void>,
1407 class = enable_if_t<!__is_allocator<_Compare>::value, void>>
Louis Dionne27ecc152019-06-11 18:21:08 +00001408multiset(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
Arthur O'Dwyer56226762021-03-03 23:02:20 -05001409 -> multiset<__iter_value_type<_InputIterator>, _Compare, _Allocator>;
Louis Dionne27ecc152019-06-11 18:21:08 +00001410
1411template<class _Key, class _Compare = less<_Key>,
1412 class _Allocator = allocator<_Key>,
Louis Dionne25547162021-08-17 12:26:09 -04001413 class = enable_if_t<__is_allocator<_Allocator>::value, void>,
1414 class = enable_if_t<!__is_allocator<_Compare>::value, void>>
Louis Dionne27ecc152019-06-11 18:21:08 +00001415multiset(initializer_list<_Key>, _Compare = _Compare(), _Allocator = _Allocator())
1416 -> multiset<_Key, _Compare, _Allocator>;
1417
1418template<class _InputIterator, class _Allocator,
Louis Dionne25547162021-08-17 12:26:09 -04001419 class = enable_if_t<__is_allocator<_Allocator>::value, void>>
Louis Dionne27ecc152019-06-11 18:21:08 +00001420multiset(_InputIterator, _InputIterator, _Allocator)
Arthur O'Dwyer56226762021-03-03 23:02:20 -05001421 -> multiset<__iter_value_type<_InputIterator>,
1422 less<__iter_value_type<_InputIterator>>, _Allocator>;
Louis Dionne27ecc152019-06-11 18:21:08 +00001423
1424template<class _Key, class _Allocator,
Louis Dionne25547162021-08-17 12:26:09 -04001425 class = enable_if_t<__is_allocator<_Allocator>::value, void>>
Louis Dionne27ecc152019-06-11 18:21:08 +00001426multiset(initializer_list<_Key>, _Allocator)
1427 -> multiset<_Key, less<_Key>, _Allocator>;
1428#endif
1429
Eric Fiselier615961b2017-04-18 20:58:03 +00001430#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001431
1432template <class _Key, class _Compare, class _Allocator>
1433multiset<_Key, _Compare, _Allocator>::multiset(multiset&& __s, const allocator_type& __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001434 : __tree_(_VSTD::move(__s.__tree_), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001435{
1436 if (__a != __s.get_allocator())
1437 {
1438 const_iterator __e = cend();
1439 while (!__s.empty())
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001440 insert(__e, _VSTD::move(__s.__tree_.remove(__s.begin())->__value_));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001441 }
1442}
1443
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001444#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001445
1446template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001447inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001448bool
1449operator==(const multiset<_Key, _Compare, _Allocator>& __x,
1450 const multiset<_Key, _Compare, _Allocator>& __y)
1451{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001452 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001453}
1454
1455template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001456inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001457bool
1458operator< (const multiset<_Key, _Compare, _Allocator>& __x,
1459 const multiset<_Key, _Compare, _Allocator>& __y)
1460{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001461 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001462}
1463
1464template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001465inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001466bool
1467operator!=(const multiset<_Key, _Compare, _Allocator>& __x,
1468 const multiset<_Key, _Compare, _Allocator>& __y)
1469{
1470 return !(__x == __y);
1471}
1472
1473template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001474inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001475bool
1476operator> (const multiset<_Key, _Compare, _Allocator>& __x,
1477 const multiset<_Key, _Compare, _Allocator>& __y)
1478{
1479 return __y < __x;
1480}
1481
1482template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001483inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001484bool
1485operator>=(const multiset<_Key, _Compare, _Allocator>& __x,
1486 const multiset<_Key, _Compare, _Allocator>& __y)
1487{
1488 return !(__x < __y);
1489}
1490
1491template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001492inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001493bool
1494operator<=(const multiset<_Key, _Compare, _Allocator>& __x,
1495 const multiset<_Key, _Compare, _Allocator>& __y)
1496{
1497 return !(__y < __x);
1498}
1499
1500template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001501inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001502void
1503swap(multiset<_Key, _Compare, _Allocator>& __x,
1504 multiset<_Key, _Compare, _Allocator>& __y)
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001505 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001506{
1507 __x.swap(__y);
1508}
1509
Marshall Clow29b53f22018-12-14 18:49:35 +00001510#if _LIBCPP_STD_VER > 17
1511template <class _Key, class _Compare, class _Allocator, class _Predicate>
1512inline _LIBCPP_INLINE_VISIBILITY
Marek Kurdeja98b1412020-05-02 13:58:03 +02001513 typename multiset<_Key, _Compare, _Allocator>::size_type
1514 erase_if(multiset<_Key, _Compare, _Allocator>& __c, _Predicate __pred) {
Arthur O'Dwyerb6738bd2021-03-21 16:53:09 -04001515 return _VSTD::__libcpp_erase_if_container(__c, __pred);
Marek Kurdeja98b1412020-05-02 13:58:03 +02001516}
Marshall Clow29b53f22018-12-14 18:49:35 +00001517#endif
1518
Howard Hinnantc51e1022010-05-11 19:42:16 +00001519_LIBCPP_END_NAMESPACE_STD
1520
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001521#endif // _LIBCPP_SET