blob: 0da484b2248d10a4b17461dc6b71e6496ea8f148 [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>
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000438#include <__node_handle>
Arthur O'Dwyer597cac42021-05-12 23:04:03 -0400439#include <__tree>
Christopher Di Bella41f26e82021-06-05 02:47:47 +0000440#include <__utility/forward.h>
Arthur O'Dwyer7deec122021-03-24 18:19:12 -0400441#include <compare>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000442#include <functional>
Arthur O'Dwyer7deec122021-03-24 18:19:12 -0400443#include <initializer_list>
Arthur O'Dwyerb6738bd2021-03-21 16:53:09 -0400444#include <iterator> // __libcpp_erase_if_container
Marshall Clow0a1e7502018-09-12 19:41:40 +0000445#include <version>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000446
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000447#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000448#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000449#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000450
451_LIBCPP_BEGIN_NAMESPACE_STD
452
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000453template <class _Key, class _Compare, class _Allocator>
454class multiset;
455
Howard Hinnantc51e1022010-05-11 19:42:16 +0000456template <class _Key, class _Compare = less<_Key>,
457 class _Allocator = allocator<_Key> >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000458class _LIBCPP_TEMPLATE_VIS set
Howard Hinnantc51e1022010-05-11 19:42:16 +0000459{
460public:
461 // types:
462 typedef _Key key_type;
463 typedef key_type value_type;
464 typedef _Compare key_compare;
465 typedef key_compare value_compare;
Arthur O'Dwyer6a752e12021-03-03 11:10:49 -0500466 typedef __identity_t<_Allocator> allocator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000467 typedef value_type& reference;
468 typedef const value_type& const_reference;
469
Marshall Clow5128cf32015-11-26 01:24:04 +0000470 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
471 "Allocator::value_type must be same type as value_type");
472
Howard Hinnantc51e1022010-05-11 19:42:16 +0000473private:
474 typedef __tree<value_type, value_compare, allocator_type> __base;
475 typedef allocator_traits<allocator_type> __alloc_traits;
476 typedef typename __base::__node_holder __node_holder;
477
478 __base __tree_;
479
480public:
481 typedef typename __base::pointer pointer;
482 typedef typename __base::const_pointer const_pointer;
483 typedef typename __base::size_type size_type;
484 typedef typename __base::difference_type difference_type;
485 typedef typename __base::const_iterator iterator;
486 typedef typename __base::const_iterator const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000487 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
488 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000489
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000490#if _LIBCPP_STD_VER > 14
491 typedef __set_node_handle<typename __base::__node, allocator_type> node_type;
492 typedef __insert_return_type<iterator, node_type> insert_return_type;
493#endif
494
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000495 template <class _Key2, class _Compare2, class _Alloc2>
496 friend class _LIBCPP_TEMPLATE_VIS set;
497 template <class _Key2, class _Compare2, class _Alloc2>
498 friend class _LIBCPP_TEMPLATE_VIS multiset;
499
Howard Hinnant192cf032010-09-23 16:27:36 +0000500 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +0000501 set()
502 _NOEXCEPT_(
503 is_nothrow_default_constructible<allocator_type>::value &&
504 is_nothrow_default_constructible<key_compare>::value &&
505 is_nothrow_copy_constructible<key_compare>::value)
506 : __tree_(value_compare()) {}
507
508 _LIBCPP_INLINE_VISIBILITY
509 explicit set(const value_compare& __comp)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000510 _NOEXCEPT_(
511 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000512 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000513 : __tree_(__comp) {}
Marshall Clow7086a5a2014-03-10 04:50:10 +0000514
Howard Hinnant192cf032010-09-23 16:27:36 +0000515 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7ed23a72014-03-05 19:06:20 +0000516 explicit set(const value_compare& __comp, const allocator_type& __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000517 : __tree_(__comp, __a) {}
518 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000519 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000520 set(_InputIterator __f, _InputIterator __l,
521 const value_compare& __comp = value_compare())
522 : __tree_(__comp)
523 {
524 insert(__f, __l);
525 }
526
527 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000528 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000529 set(_InputIterator __f, _InputIterator __l, const value_compare& __comp,
530 const allocator_type& __a)
531 : __tree_(__comp, __a)
532 {
533 insert(__f, __l);
534 }
535
Marshall Clow631788a2013-09-11 00:06:45 +0000536#if _LIBCPP_STD_VER > 11
537 template <class _InputIterator>
Louis Dionned2322c82018-11-01 14:41:37 +0000538 _LIBCPP_INLINE_VISIBILITY
Marshall Clow631788a2013-09-11 00:06:45 +0000539 set(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
540 : set(__f, __l, key_compare(), __a) {}
541#endif
542
Howard Hinnant192cf032010-09-23 16:27:36 +0000543 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000544 set(const set& __s)
545 : __tree_(__s.__tree_)
546 {
547 insert(__s.begin(), __s.end());
548 }
549
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000550 _LIBCPP_INLINE_VISIBILITY
551 set& operator=(const set& __s)
552 {
553 __tree_ = __s.__tree_;
554 return *this;
555 }
556
Eric Fiselier615961b2017-04-18 20:58:03 +0000557#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant192cf032010-09-23 16:27:36 +0000558 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000559 set(set&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000560 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000561 : __tree_(_VSTD::move(__s.__tree_)) {}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400562#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000563
Howard Hinnant192cf032010-09-23 16:27:36 +0000564 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000565 explicit set(const allocator_type& __a)
566 : __tree_(__a) {}
567
Howard Hinnant192cf032010-09-23 16:27:36 +0000568 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000569 set(const set& __s, const allocator_type& __a)
570 : __tree_(__s.__tree_.value_comp(), __a)
571 {
572 insert(__s.begin(), __s.end());
573 }
574
Eric Fiselier615961b2017-04-18 20:58:03 +0000575#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000576 set(set&& __s, const allocator_type& __a);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000577
Howard Hinnant192cf032010-09-23 16:27:36 +0000578 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000579 set(initializer_list<value_type> __il, const value_compare& __comp = value_compare())
580 : __tree_(__comp)
581 {
582 insert(__il.begin(), __il.end());
583 }
584
Howard Hinnant192cf032010-09-23 16:27:36 +0000585 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000586 set(initializer_list<value_type> __il, const value_compare& __comp,
587 const allocator_type& __a)
588 : __tree_(__comp, __a)
589 {
590 insert(__il.begin(), __il.end());
591 }
592
Marshall Clow631788a2013-09-11 00:06:45 +0000593#if _LIBCPP_STD_VER > 11
Louis Dionned2322c82018-11-01 14:41:37 +0000594 _LIBCPP_INLINE_VISIBILITY
Marshall Clow631788a2013-09-11 00:06:45 +0000595 set(initializer_list<value_type> __il, const allocator_type& __a)
596 : set(__il, key_compare(), __a) {}
597#endif
598
Howard Hinnant192cf032010-09-23 16:27:36 +0000599 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000600 set& operator=(initializer_list<value_type> __il)
601 {
602 __tree_.__assign_unique(__il.begin(), __il.end());
603 return *this;
604 }
605
Howard Hinnant192cf032010-09-23 16:27:36 +0000606 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000607 set& operator=(set&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000608 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000609 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000610 __tree_ = _VSTD::move(__s.__tree_);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000611 return *this;
612 }
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400613#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000614
Howard Hinnant192cf032010-09-23 16:27:36 +0000615 _LIBCPP_INLINE_VISIBILITY
Louis Dionne69c42c02019-04-11 16:14:56 +0000616 ~set() {
617 static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), "");
618 }
619
620 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000621 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000622 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000623 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000624 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000625 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000626 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000627 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000628
Howard Hinnant192cf032010-09-23 16:27:36 +0000629 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000630 reverse_iterator rbegin() _NOEXCEPT
631 {return reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +0000632 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000633 const_reverse_iterator rbegin() const _NOEXCEPT
634 {return const_reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +0000635 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000636 reverse_iterator rend() _NOEXCEPT
637 {return reverse_iterator(begin());}
Howard Hinnant192cf032010-09-23 16:27:36 +0000638 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000639 const_reverse_iterator rend() const _NOEXCEPT
640 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000641
Howard Hinnant192cf032010-09-23 16:27:36 +0000642 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000643 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000644 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000645 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000646 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000647 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000648 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000649 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000650
Marshall Clow425f5752017-11-15 05:51:26 +0000651 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000652 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant192cf032010-09-23 16:27:36 +0000653 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000654 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000655 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000656 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000657
658 // modifiers:
Eric Fiselier615961b2017-04-18 20:58:03 +0000659#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000660 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +0000661 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000662 pair<iterator, bool> emplace(_Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000663 {return __tree_.__emplace_unique(_VSTD::forward<_Args>(__args)...);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000664 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +0000665 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000666 iterator emplace_hint(const_iterator __p, _Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000667 {return __tree_.__emplace_hint_unique(__p, _VSTD::forward<_Args>(__args)...);}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400668#endif // _LIBCPP_CXX03_LANG
Eric Fiselier615961b2017-04-18 20:58:03 +0000669
Howard Hinnant192cf032010-09-23 16:27:36 +0000670 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000671 pair<iterator,bool> insert(const value_type& __v)
672 {return __tree_.__insert_unique(__v);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000673 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000674 iterator insert(const_iterator __p, const value_type& __v)
675 {return __tree_.__insert_unique(__p, __v);}
Eric Fiselier615961b2017-04-18 20:58:03 +0000676
Howard Hinnantc51e1022010-05-11 19:42:16 +0000677 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000678 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000679 void insert(_InputIterator __f, _InputIterator __l)
680 {
681 for (const_iterator __e = cend(); __f != __l; ++__f)
682 __tree_.__insert_unique(__e, *__f);
683 }
684
Eric Fiselier615961b2017-04-18 20:58:03 +0000685#ifndef _LIBCPP_CXX03_LANG
686 _LIBCPP_INLINE_VISIBILITY
687 pair<iterator,bool> insert(value_type&& __v)
688 {return __tree_.__insert_unique(_VSTD::move(__v));}
689
690 _LIBCPP_INLINE_VISIBILITY
691 iterator insert(const_iterator __p, value_type&& __v)
692 {return __tree_.__insert_unique(__p, _VSTD::move(__v));}
693
Howard Hinnant192cf032010-09-23 16:27:36 +0000694 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000695 void insert(initializer_list<value_type> __il)
696 {insert(__il.begin(), __il.end());}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400697#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000698
Howard Hinnant192cf032010-09-23 16:27:36 +0000699 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000700 iterator erase(const_iterator __p) {return __tree_.erase(__p);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000701 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000702 size_type erase(const key_type& __k)
703 {return __tree_.__erase_unique(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000704 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000705 iterator erase(const_iterator __f, const_iterator __l)
706 {return __tree_.erase(__f, __l);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000707 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000708 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000709
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000710#if _LIBCPP_STD_VER > 14
711 _LIBCPP_INLINE_VISIBILITY
712 insert_return_type insert(node_type&& __nh)
713 {
714 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
715 "node_type with incompatible allocator passed to set::insert()");
716 return __tree_.template __node_handle_insert_unique<
717 node_type, insert_return_type>(_VSTD::move(__nh));
718 }
719 _LIBCPP_INLINE_VISIBILITY
720 iterator insert(const_iterator __hint, node_type&& __nh)
721 {
722 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
723 "node_type with incompatible allocator passed to set::insert()");
724 return __tree_.template __node_handle_insert_unique<node_type>(
725 __hint, _VSTD::move(__nh));
726 }
727 _LIBCPP_INLINE_VISIBILITY
728 node_type extract(key_type const& __key)
729 {
730 return __tree_.template __node_handle_extract<node_type>(__key);
731 }
732 _LIBCPP_INLINE_VISIBILITY
733 node_type extract(const_iterator __it)
734 {
735 return __tree_.template __node_handle_extract<node_type>(__it);
736 }
Louis Dionned2322c82018-11-01 14:41:37 +0000737 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000738 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +0000739 void merge(set<key_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000740 {
741 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
742 "merging container with incompatible allocator");
743 __tree_.__node_handle_merge_unique(__source.__tree_);
744 }
Louis Dionned2322c82018-11-01 14:41:37 +0000745 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000746 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +0000747 void merge(set<key_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000748 {
749 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
750 "merging container with incompatible allocator");
751 __tree_.__node_handle_merge_unique(__source.__tree_);
752 }
Louis Dionned2322c82018-11-01 14:41:37 +0000753 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000754 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +0000755 void merge(multiset<key_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000756 {
757 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
758 "merging container with incompatible allocator");
759 __tree_.__node_handle_merge_unique(__source.__tree_);
760 }
Louis Dionned2322c82018-11-01 14:41:37 +0000761 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000762 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +0000763 void merge(multiset<key_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000764 {
765 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
766 "merging container with incompatible allocator");
767 __tree_.__node_handle_merge_unique(__source.__tree_);
768 }
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000769#endif
770
Howard Hinnant192cf032010-09-23 16:27:36 +0000771 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000772 void swap(set& __s) _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
773 {__tree_.swap(__s.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000774
Howard Hinnant192cf032010-09-23 16:27:36 +0000775 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000776 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000777 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000778 key_compare key_comp() const {return __tree_.value_comp();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000779 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000780 value_compare value_comp() const {return __tree_.value_comp();}
781
782 // set operations:
Howard Hinnant192cf032010-09-23 16:27:36 +0000783 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000784 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000785 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000786 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000787#if _LIBCPP_STD_VER > 11
788 template <typename _K2>
789 _LIBCPP_INLINE_VISIBILITY
790 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
791 find(const _K2& __k) {return __tree_.find(__k);}
792 template <typename _K2>
793 _LIBCPP_INLINE_VISIBILITY
794 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
795 find(const _K2& __k) const {return __tree_.find(__k);}
796#endif
797
Howard Hinnant192cf032010-09-23 16:27:36 +0000798 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000799 size_type count(const key_type& __k) const
800 {return __tree_.__count_unique(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +0000801#if _LIBCPP_STD_VER > 11
802 template <typename _K2>
803 _LIBCPP_INLINE_VISIBILITY
804 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +0000805 count(const _K2& __k) const {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +0000806#endif
Zoe Carver3ffbab12019-07-16 03:21:01 +0000807
808#if _LIBCPP_STD_VER > 17
809 _LIBCPP_INLINE_VISIBILITY
810 bool contains(const key_type& __k) const {return find(__k) != end();}
Marek Kurdejd7e019e2021-04-13 17:10:55 +0200811 template <typename _K2>
812 _LIBCPP_INLINE_VISIBILITY
813 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
814 contains(const _K2& __k) const { return find(__k) != end(); }
Zoe Carver3ffbab12019-07-16 03:21:01 +0000815#endif // _LIBCPP_STD_VER > 17
816
Howard Hinnant192cf032010-09-23 16:27:36 +0000817 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000818 iterator lower_bound(const key_type& __k)
819 {return __tree_.lower_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000820 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000821 const_iterator lower_bound(const key_type& __k) const
822 {return __tree_.lower_bound(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000823#if _LIBCPP_STD_VER > 11
824 template <typename _K2>
825 _LIBCPP_INLINE_VISIBILITY
826 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
827 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
828
829 template <typename _K2>
830 _LIBCPP_INLINE_VISIBILITY
831 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
832 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
833#endif
834
Howard Hinnant192cf032010-09-23 16:27:36 +0000835 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000836 iterator upper_bound(const key_type& __k)
837 {return __tree_.upper_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000838 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000839 const_iterator upper_bound(const key_type& __k) const
840 {return __tree_.upper_bound(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000841#if _LIBCPP_STD_VER > 11
842 template <typename _K2>
843 _LIBCPP_INLINE_VISIBILITY
844 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
845 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
846 template <typename _K2>
847 _LIBCPP_INLINE_VISIBILITY
848 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
849 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
850#endif
851
Howard Hinnant192cf032010-09-23 16:27:36 +0000852 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000853 pair<iterator,iterator> equal_range(const key_type& __k)
854 {return __tree_.__equal_range_unique(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000855 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000856 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
857 {return __tree_.__equal_range_unique(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000858#if _LIBCPP_STD_VER > 11
859 template <typename _K2>
860 _LIBCPP_INLINE_VISIBILITY
861 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +0000862 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000863 template <typename _K2>
864 _LIBCPP_INLINE_VISIBILITY
865 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +0000866 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000867#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000868};
869
Louis Dionne27ecc152019-06-11 18:21:08 +0000870#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
871template<class _InputIterator,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500872 class _Compare = less<__iter_value_type<_InputIterator>>,
873 class _Allocator = allocator<__iter_value_type<_InputIterator>>,
Louis Dionne6c7da9a2019-07-19 17:13:39 +0000874 class = _EnableIf<__is_allocator<_Allocator>::value, void>,
875 class = _EnableIf<!__is_allocator<_Compare>::value, void>>
Louis Dionne27ecc152019-06-11 18:21:08 +0000876set(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500877 -> set<__iter_value_type<_InputIterator>, _Compare, _Allocator>;
Louis Dionne27ecc152019-06-11 18:21:08 +0000878
879template<class _Key, class _Compare = less<_Key>,
880 class _Allocator = allocator<_Key>,
Louis Dionne6c7da9a2019-07-19 17:13:39 +0000881 class = _EnableIf<__is_allocator<_Allocator>::value, void>,
882 class = _EnableIf<!__is_allocator<_Compare>::value, void>>
Louis Dionne27ecc152019-06-11 18:21:08 +0000883set(initializer_list<_Key>, _Compare = _Compare(), _Allocator = _Allocator())
884 -> set<_Key, _Compare, _Allocator>;
885
886template<class _InputIterator, class _Allocator,
Louis Dionne6c7da9a2019-07-19 17:13:39 +0000887 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
Louis Dionne27ecc152019-06-11 18:21:08 +0000888set(_InputIterator, _InputIterator, _Allocator)
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500889 -> set<__iter_value_type<_InputIterator>,
890 less<__iter_value_type<_InputIterator>>, _Allocator>;
Louis Dionne27ecc152019-06-11 18:21:08 +0000891
892template<class _Key, class _Allocator,
Louis Dionne6c7da9a2019-07-19 17:13:39 +0000893 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
Louis Dionne27ecc152019-06-11 18:21:08 +0000894set(initializer_list<_Key>, _Allocator)
895 -> set<_Key, less<_Key>, _Allocator>;
896#endif
897
Eric Fiselier615961b2017-04-18 20:58:03 +0000898#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000899
900template <class _Key, class _Compare, class _Allocator>
901set<_Key, _Compare, _Allocator>::set(set&& __s, const allocator_type& __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000902 : __tree_(_VSTD::move(__s.__tree_), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000903{
904 if (__a != __s.get_allocator())
905 {
906 const_iterator __e = cend();
907 while (!__s.empty())
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000908 insert(__e, _VSTD::move(__s.__tree_.remove(__s.begin())->__value_));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000909 }
910}
911
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400912#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000913
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 +0000916bool
917operator==(const set<_Key, _Compare, _Allocator>& __x,
918 const set<_Key, _Compare, _Allocator>& __y)
919{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000920 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000921}
922
923template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000924inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000925bool
926operator< (const set<_Key, _Compare, _Allocator>& __x,
927 const set<_Key, _Compare, _Allocator>& __y)
928{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000929 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000930}
931
932template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000933inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000934bool
935operator!=(const set<_Key, _Compare, _Allocator>& __x,
936 const set<_Key, _Compare, _Allocator>& __y)
937{
938 return !(__x == __y);
939}
940
941template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000942inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000943bool
944operator> (const set<_Key, _Compare, _Allocator>& __x,
945 const set<_Key, _Compare, _Allocator>& __y)
946{
947 return __y < __x;
948}
949
950template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000951inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000952bool
953operator>=(const set<_Key, _Compare, _Allocator>& __x,
954 const set<_Key, _Compare, _Allocator>& __y)
955{
956 return !(__x < __y);
957}
958
959template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000960inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000961bool
962operator<=(const set<_Key, _Compare, _Allocator>& __x,
963 const set<_Key, _Compare, _Allocator>& __y)
964{
965 return !(__y < __x);
966}
967
968// specialized algorithms:
969template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000970inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000971void
972swap(set<_Key, _Compare, _Allocator>& __x,
973 set<_Key, _Compare, _Allocator>& __y)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000974 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000975{
976 __x.swap(__y);
977}
978
Marshall Clow29b53f22018-12-14 18:49:35 +0000979#if _LIBCPP_STD_VER > 17
980template <class _Key, class _Compare, class _Allocator, class _Predicate>
981inline _LIBCPP_INLINE_VISIBILITY
Marek Kurdeja98b1412020-05-02 13:58:03 +0200982 typename set<_Key, _Compare, _Allocator>::size_type
983 erase_if(set<_Key, _Compare, _Allocator>& __c, _Predicate __pred) {
Arthur O'Dwyerb6738bd2021-03-21 16:53:09 -0400984 return _VSTD::__libcpp_erase_if_container(__c, __pred);
Marek Kurdeja98b1412020-05-02 13:58:03 +0200985}
Marshall Clow29b53f22018-12-14 18:49:35 +0000986#endif
987
Howard Hinnantc51e1022010-05-11 19:42:16 +0000988template <class _Key, class _Compare = less<_Key>,
989 class _Allocator = allocator<_Key> >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000990class _LIBCPP_TEMPLATE_VIS multiset
Howard Hinnantc51e1022010-05-11 19:42:16 +0000991{
992public:
993 // types:
Arthur O'Dwyer6a752e12021-03-03 11:10:49 -0500994 typedef _Key key_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000995 typedef key_type value_type;
Arthur O'Dwyer6a752e12021-03-03 11:10:49 -0500996 typedef _Compare key_compare;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000997 typedef key_compare value_compare;
Arthur O'Dwyer6a752e12021-03-03 11:10:49 -0500998 typedef __identity_t<_Allocator> allocator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000999 typedef value_type& reference;
1000 typedef const value_type& const_reference;
1001
Marshall Clow5128cf32015-11-26 01:24:04 +00001002 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
1003 "Allocator::value_type must be same type as value_type");
1004
Howard Hinnantc51e1022010-05-11 19:42:16 +00001005private:
1006 typedef __tree<value_type, value_compare, allocator_type> __base;
1007 typedef allocator_traits<allocator_type> __alloc_traits;
1008 typedef typename __base::__node_holder __node_holder;
1009
1010 __base __tree_;
1011
1012public:
1013 typedef typename __base::pointer pointer;
1014 typedef typename __base::const_pointer const_pointer;
1015 typedef typename __base::size_type size_type;
1016 typedef typename __base::difference_type difference_type;
1017 typedef typename __base::const_iterator iterator;
1018 typedef typename __base::const_iterator const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001019 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1020 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001021
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001022#if _LIBCPP_STD_VER > 14
1023 typedef __set_node_handle<typename __base::__node, allocator_type> node_type;
1024#endif
1025
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001026 template <class _Key2, class _Compare2, class _Alloc2>
1027 friend class _LIBCPP_TEMPLATE_VIS set;
1028 template <class _Key2, class _Compare2, class _Alloc2>
1029 friend class _LIBCPP_TEMPLATE_VIS multiset;
1030
Howard Hinnantc51e1022010-05-11 19:42:16 +00001031 // construct/copy/destroy:
Howard Hinnant192cf032010-09-23 16:27:36 +00001032 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +00001033 multiset()
1034 _NOEXCEPT_(
1035 is_nothrow_default_constructible<allocator_type>::value &&
1036 is_nothrow_default_constructible<key_compare>::value &&
1037 is_nothrow_copy_constructible<key_compare>::value)
1038 : __tree_(value_compare()) {}
1039
1040 _LIBCPP_INLINE_VISIBILITY
1041 explicit multiset(const value_compare& __comp)
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001042 _NOEXCEPT_(
1043 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001044 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001045 : __tree_(__comp) {}
Marshall Clow7086a5a2014-03-10 04:50:10 +00001046
Howard Hinnant192cf032010-09-23 16:27:36 +00001047 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7ed23a72014-03-05 19:06:20 +00001048 explicit multiset(const value_compare& __comp, const allocator_type& __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001049 : __tree_(__comp, __a) {}
1050 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001051 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001052 multiset(_InputIterator __f, _InputIterator __l,
1053 const value_compare& __comp = value_compare())
1054 : __tree_(__comp)
1055 {
1056 insert(__f, __l);
1057 }
1058
Marshall Clow631788a2013-09-11 00:06:45 +00001059#if _LIBCPP_STD_VER > 11
1060 template <class _InputIterator>
Louis Dionned2322c82018-11-01 14:41:37 +00001061 _LIBCPP_INLINE_VISIBILITY
Marshall Clow631788a2013-09-11 00:06:45 +00001062 multiset(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
1063 : multiset(__f, __l, key_compare(), __a) {}
1064#endif
1065
Howard Hinnantc51e1022010-05-11 19:42:16 +00001066 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001067 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001068 multiset(_InputIterator __f, _InputIterator __l,
1069 const value_compare& __comp, const allocator_type& __a)
1070 : __tree_(__comp, __a)
1071 {
1072 insert(__f, __l);
1073 }
1074
Howard Hinnant192cf032010-09-23 16:27:36 +00001075 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001076 multiset(const multiset& __s)
1077 : __tree_(__s.__tree_.value_comp(),
1078 __alloc_traits::select_on_container_copy_construction(__s.__tree_.__alloc()))
1079 {
1080 insert(__s.begin(), __s.end());
1081 }
1082
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001083 _LIBCPP_INLINE_VISIBILITY
1084 multiset& operator=(const multiset& __s)
1085 {
1086 __tree_ = __s.__tree_;
1087 return *this;
1088 }
1089
Eric Fiselier615961b2017-04-18 20:58:03 +00001090#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant192cf032010-09-23 16:27:36 +00001091 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001092 multiset(multiset&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001093 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001094 : __tree_(_VSTD::move(__s.__tree_)) {}
Eric Fiselier615961b2017-04-18 20:58:03 +00001095
1096 multiset(multiset&& __s, const allocator_type& __a);
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001097#endif // _LIBCPP_CXX03_LANG
Howard Hinnant192cf032010-09-23 16:27:36 +00001098 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001099 explicit multiset(const allocator_type& __a)
1100 : __tree_(__a) {}
Howard Hinnant192cf032010-09-23 16:27:36 +00001101 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001102 multiset(const multiset& __s, const allocator_type& __a)
1103 : __tree_(__s.__tree_.value_comp(), __a)
1104 {
1105 insert(__s.begin(), __s.end());
1106 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001107
Eric Fiselier615961b2017-04-18 20:58:03 +00001108#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant192cf032010-09-23 16:27:36 +00001109 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001110 multiset(initializer_list<value_type> __il, const value_compare& __comp = value_compare())
1111 : __tree_(__comp)
1112 {
1113 insert(__il.begin(), __il.end());
1114 }
1115
Howard Hinnant192cf032010-09-23 16:27:36 +00001116 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001117 multiset(initializer_list<value_type> __il, const value_compare& __comp,
1118 const allocator_type& __a)
1119 : __tree_(__comp, __a)
1120 {
1121 insert(__il.begin(), __il.end());
1122 }
1123
Marshall Clow631788a2013-09-11 00:06:45 +00001124#if _LIBCPP_STD_VER > 11
Louis Dionned2322c82018-11-01 14:41:37 +00001125 _LIBCPP_INLINE_VISIBILITY
Marshall Clow631788a2013-09-11 00:06:45 +00001126 multiset(initializer_list<value_type> __il, const allocator_type& __a)
1127 : multiset(__il, key_compare(), __a) {}
1128#endif
1129
Howard Hinnant192cf032010-09-23 16:27:36 +00001130 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001131 multiset& operator=(initializer_list<value_type> __il)
1132 {
1133 __tree_.__assign_multi(__il.begin(), __il.end());
1134 return *this;
1135 }
1136
Howard Hinnant192cf032010-09-23 16:27:36 +00001137 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001138 multiset& operator=(multiset&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001139 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001140 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001141 __tree_ = _VSTD::move(__s.__tree_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001142 return *this;
1143 }
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001144#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001145
Howard Hinnant192cf032010-09-23 16:27:36 +00001146 _LIBCPP_INLINE_VISIBILITY
Louis Dionne69c42c02019-04-11 16:14:56 +00001147 ~multiset() {
1148 static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), "");
1149 }
1150
1151 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001152 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001153 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001154 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001155 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001156 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001157 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001158 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001159
Howard Hinnant192cf032010-09-23 16:27:36 +00001160 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001161 reverse_iterator rbegin() _NOEXCEPT
1162 {return reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +00001163 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001164 const_reverse_iterator rbegin() const _NOEXCEPT
1165 {return const_reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +00001166 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001167 reverse_iterator rend() _NOEXCEPT
1168 {return reverse_iterator(begin());}
Howard Hinnant192cf032010-09-23 16:27:36 +00001169 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001170 const_reverse_iterator rend() const _NOEXCEPT
1171 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001172
Howard Hinnant192cf032010-09-23 16:27:36 +00001173 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001174 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001175 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001176 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001177 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001178 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001179 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001180 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001181
Marshall Clow425f5752017-11-15 05:51:26 +00001182 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001183 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant192cf032010-09-23 16:27:36 +00001184 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001185 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001186 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001187 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001188
1189 // modifiers:
Eric Fiselier615961b2017-04-18 20:58:03 +00001190#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001191 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +00001192 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001193 iterator emplace(_Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001194 {return __tree_.__emplace_multi(_VSTD::forward<_Args>(__args)...);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001195 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +00001196 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001197 iterator emplace_hint(const_iterator __p, _Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001198 {return __tree_.__emplace_hint_multi(__p, _VSTD::forward<_Args>(__args)...);}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001199#endif // _LIBCPP_CXX03_LANG
Eric Fiselier615961b2017-04-18 20:58:03 +00001200
Howard Hinnant192cf032010-09-23 16:27:36 +00001201 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001202 iterator insert(const value_type& __v)
1203 {return __tree_.__insert_multi(__v);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001204 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001205 iterator insert(const_iterator __p, const value_type& __v)
1206 {return __tree_.__insert_multi(__p, __v);}
Eric Fiselier615961b2017-04-18 20:58:03 +00001207
Howard Hinnantc51e1022010-05-11 19:42:16 +00001208 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001209 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001210 void insert(_InputIterator __f, _InputIterator __l)
1211 {
1212 for (const_iterator __e = cend(); __f != __l; ++__f)
1213 __tree_.__insert_multi(__e, *__f);
1214 }
1215
Eric Fiselier615961b2017-04-18 20:58:03 +00001216#ifndef _LIBCPP_CXX03_LANG
1217 _LIBCPP_INLINE_VISIBILITY
1218 iterator insert(value_type&& __v)
1219 {return __tree_.__insert_multi(_VSTD::move(__v));}
1220
1221 _LIBCPP_INLINE_VISIBILITY
1222 iterator insert(const_iterator __p, value_type&& __v)
1223 {return __tree_.__insert_multi(__p, _VSTD::move(__v));}
1224
Howard Hinnant192cf032010-09-23 16:27:36 +00001225 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001226 void insert(initializer_list<value_type> __il)
1227 {insert(__il.begin(), __il.end());}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001228#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001229
Howard Hinnant192cf032010-09-23 16:27:36 +00001230 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001231 iterator erase(const_iterator __p) {return __tree_.erase(__p);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001232 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001233 size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001234 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001235 iterator erase(const_iterator __f, const_iterator __l)
1236 {return __tree_.erase(__f, __l);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001237 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001238 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001239
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001240#if _LIBCPP_STD_VER > 14
1241 _LIBCPP_INLINE_VISIBILITY
1242 iterator insert(node_type&& __nh)
1243 {
1244 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1245 "node_type with incompatible allocator passed to multiset::insert()");
1246 return __tree_.template __node_handle_insert_multi<node_type>(
1247 _VSTD::move(__nh));
1248 }
1249 _LIBCPP_INLINE_VISIBILITY
1250 iterator insert(const_iterator __hint, node_type&& __nh)
1251 {
1252 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1253 "node_type with incompatible allocator passed to multiset::insert()");
1254 return __tree_.template __node_handle_insert_multi<node_type>(
1255 __hint, _VSTD::move(__nh));
1256 }
1257 _LIBCPP_INLINE_VISIBILITY
1258 node_type extract(key_type const& __key)
1259 {
1260 return __tree_.template __node_handle_extract<node_type>(__key);
1261 }
1262 _LIBCPP_INLINE_VISIBILITY
1263 node_type extract(const_iterator __it)
1264 {
1265 return __tree_.template __node_handle_extract<node_type>(__it);
1266 }
Louis Dionned2322c82018-11-01 14:41:37 +00001267 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001268 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001269 void merge(multiset<key_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001270 {
1271 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1272 "merging container with incompatible allocator");
1273 __tree_.__node_handle_merge_multi(__source.__tree_);
1274 }
Louis Dionned2322c82018-11-01 14:41:37 +00001275 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001276 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001277 void merge(multiset<key_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001278 {
1279 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1280 "merging container with incompatible allocator");
1281 __tree_.__node_handle_merge_multi(__source.__tree_);
1282 }
Louis Dionned2322c82018-11-01 14:41:37 +00001283 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001284 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001285 void merge(set<key_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001286 {
1287 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1288 "merging container with incompatible allocator");
1289 __tree_.__node_handle_merge_multi(__source.__tree_);
1290 }
Louis Dionned2322c82018-11-01 14:41:37 +00001291 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001292 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001293 void merge(set<key_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001294 {
1295 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1296 "merging container with incompatible allocator");
1297 __tree_.__node_handle_merge_multi(__source.__tree_);
1298 }
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001299#endif
1300
Howard Hinnant192cf032010-09-23 16:27:36 +00001301 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001302 void swap(multiset& __s)
1303 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1304 {__tree_.swap(__s.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001305
Howard Hinnant192cf032010-09-23 16:27:36 +00001306 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001307 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001308 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001309 key_compare key_comp() const {return __tree_.value_comp();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001310 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001311 value_compare value_comp() const {return __tree_.value_comp();}
1312
1313 // set operations:
Howard Hinnant192cf032010-09-23 16:27:36 +00001314 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001315 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001316 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001317 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +00001318#if _LIBCPP_STD_VER > 11
1319 template <typename _K2>
1320 _LIBCPP_INLINE_VISIBILITY
Mark de Wever9d7aa7a2021-05-09 18:22:52 +02001321 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
Marshall Clowc0152142013-08-13 01:11:06 +00001322 find(const _K2& __k) {return __tree_.find(__k);}
1323 template <typename _K2>
1324 _LIBCPP_INLINE_VISIBILITY
Mark de Wever9d7aa7a2021-05-09 18:22:52 +02001325 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
Marshall Clowc0152142013-08-13 01:11:06 +00001326 find(const _K2& __k) const {return __tree_.find(__k);}
1327#endif
1328
Howard Hinnant192cf032010-09-23 16:27:36 +00001329 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001330 size_type count(const key_type& __k) const
1331 {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001332#if _LIBCPP_STD_VER > 11
1333 template <typename _K2>
1334 _LIBCPP_INLINE_VISIBILITY
1335 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
Marshall Clow5571bcd2018-01-07 17:39:57 +00001336 count(const _K2& __k) const {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001337#endif
Marshall Clowc0152142013-08-13 01:11:06 +00001338
Zoe Carver3ffbab12019-07-16 03:21:01 +00001339#if _LIBCPP_STD_VER > 17
1340 _LIBCPP_INLINE_VISIBILITY
1341 bool contains(const key_type& __k) const {return find(__k) != end();}
Marek Kurdejd7e019e2021-04-13 17:10:55 +02001342 template <typename _K2>
1343 _LIBCPP_INLINE_VISIBILITY
1344 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
1345 contains(const _K2& __k) const { return find(__k) != end(); }
Zoe Carver3ffbab12019-07-16 03:21:01 +00001346#endif // _LIBCPP_STD_VER > 17
1347
Howard Hinnant192cf032010-09-23 16:27:36 +00001348 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001349 iterator lower_bound(const key_type& __k)
1350 {return __tree_.lower_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001351 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001352 const_iterator lower_bound(const key_type& __k) const
1353 {return __tree_.lower_bound(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +00001354#if _LIBCPP_STD_VER > 11
1355 template <typename _K2>
1356 _LIBCPP_INLINE_VISIBILITY
Mark de Wever9d7aa7a2021-05-09 18:22:52 +02001357 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
Marshall Clowc0152142013-08-13 01:11:06 +00001358 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
1359
1360 template <typename _K2>
1361 _LIBCPP_INLINE_VISIBILITY
Mark de Wever9d7aa7a2021-05-09 18:22:52 +02001362 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
Marshall Clowc0152142013-08-13 01:11:06 +00001363 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
1364#endif
1365
Howard Hinnant192cf032010-09-23 16:27:36 +00001366 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001367 iterator upper_bound(const key_type& __k)
1368 {return __tree_.upper_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001369 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001370 const_iterator upper_bound(const key_type& __k) const
1371 {return __tree_.upper_bound(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +00001372#if _LIBCPP_STD_VER > 11
1373 template <typename _K2>
1374 _LIBCPP_INLINE_VISIBILITY
Mark de Wever9d7aa7a2021-05-09 18:22:52 +02001375 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
Marshall Clowc0152142013-08-13 01:11:06 +00001376 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
1377 template <typename _K2>
1378 _LIBCPP_INLINE_VISIBILITY
Mark de Wever9d7aa7a2021-05-09 18:22:52 +02001379 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
Marshall Clowc0152142013-08-13 01:11:06 +00001380 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
1381#endif
1382
Howard Hinnant192cf032010-09-23 16:27:36 +00001383 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001384 pair<iterator,iterator> equal_range(const key_type& __k)
1385 {return __tree_.__equal_range_multi(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001386 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001387 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
1388 {return __tree_.__equal_range_multi(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +00001389#if _LIBCPP_STD_VER > 11
1390 template <typename _K2>
1391 _LIBCPP_INLINE_VISIBILITY
Mark de Wever9d7aa7a2021-05-09 18:22:52 +02001392 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
Marshall Clowc0152142013-08-13 01:11:06 +00001393 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
1394 template <typename _K2>
1395 _LIBCPP_INLINE_VISIBILITY
Mark de Wever9d7aa7a2021-05-09 18:22:52 +02001396 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
Marshall Clowc0152142013-08-13 01:11:06 +00001397 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
1398#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001399};
1400
Louis Dionne27ecc152019-06-11 18:21:08 +00001401#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
1402template<class _InputIterator,
Arthur O'Dwyer56226762021-03-03 23:02:20 -05001403 class _Compare = less<__iter_value_type<_InputIterator>>,
1404 class _Allocator = allocator<__iter_value_type<_InputIterator>>,
Louis Dionne6c7da9a2019-07-19 17:13:39 +00001405 class = _EnableIf<__is_allocator<_Allocator>::value, void>,
1406 class = _EnableIf<!__is_allocator<_Compare>::value, void>>
Louis Dionne27ecc152019-06-11 18:21:08 +00001407multiset(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
Arthur O'Dwyer56226762021-03-03 23:02:20 -05001408 -> multiset<__iter_value_type<_InputIterator>, _Compare, _Allocator>;
Louis Dionne27ecc152019-06-11 18:21:08 +00001409
1410template<class _Key, class _Compare = less<_Key>,
1411 class _Allocator = allocator<_Key>,
Louis Dionne6c7da9a2019-07-19 17:13:39 +00001412 class = _EnableIf<__is_allocator<_Allocator>::value, void>,
1413 class = _EnableIf<!__is_allocator<_Compare>::value, void>>
Louis Dionne27ecc152019-06-11 18:21:08 +00001414multiset(initializer_list<_Key>, _Compare = _Compare(), _Allocator = _Allocator())
1415 -> multiset<_Key, _Compare, _Allocator>;
1416
1417template<class _InputIterator, class _Allocator,
Louis Dionne6c7da9a2019-07-19 17:13:39 +00001418 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
Louis Dionne27ecc152019-06-11 18:21:08 +00001419multiset(_InputIterator, _InputIterator, _Allocator)
Arthur O'Dwyer56226762021-03-03 23:02:20 -05001420 -> multiset<__iter_value_type<_InputIterator>,
1421 less<__iter_value_type<_InputIterator>>, _Allocator>;
Louis Dionne27ecc152019-06-11 18:21:08 +00001422
1423template<class _Key, class _Allocator,
Louis Dionne6c7da9a2019-07-19 17:13:39 +00001424 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
Louis Dionne27ecc152019-06-11 18:21:08 +00001425multiset(initializer_list<_Key>, _Allocator)
1426 -> multiset<_Key, less<_Key>, _Allocator>;
1427#endif
1428
Eric Fiselier615961b2017-04-18 20:58:03 +00001429#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001430
1431template <class _Key, class _Compare, class _Allocator>
1432multiset<_Key, _Compare, _Allocator>::multiset(multiset&& __s, const allocator_type& __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001433 : __tree_(_VSTD::move(__s.__tree_), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001434{
1435 if (__a != __s.get_allocator())
1436 {
1437 const_iterator __e = cend();
1438 while (!__s.empty())
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001439 insert(__e, _VSTD::move(__s.__tree_.remove(__s.begin())->__value_));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001440 }
1441}
1442
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001443#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001444
1445template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001446inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001447bool
1448operator==(const multiset<_Key, _Compare, _Allocator>& __x,
1449 const multiset<_Key, _Compare, _Allocator>& __y)
1450{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001451 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001452}
1453
1454template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001455inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001456bool
1457operator< (const multiset<_Key, _Compare, _Allocator>& __x,
1458 const multiset<_Key, _Compare, _Allocator>& __y)
1459{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001460 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001461}
1462
1463template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001464inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001465bool
1466operator!=(const multiset<_Key, _Compare, _Allocator>& __x,
1467 const multiset<_Key, _Compare, _Allocator>& __y)
1468{
1469 return !(__x == __y);
1470}
1471
1472template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001473inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001474bool
1475operator> (const multiset<_Key, _Compare, _Allocator>& __x,
1476 const multiset<_Key, _Compare, _Allocator>& __y)
1477{
1478 return __y < __x;
1479}
1480
1481template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001482inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001483bool
1484operator>=(const multiset<_Key, _Compare, _Allocator>& __x,
1485 const multiset<_Key, _Compare, _Allocator>& __y)
1486{
1487 return !(__x < __y);
1488}
1489
1490template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001491inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001492bool
1493operator<=(const multiset<_Key, _Compare, _Allocator>& __x,
1494 const multiset<_Key, _Compare, _Allocator>& __y)
1495{
1496 return !(__y < __x);
1497}
1498
1499template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001500inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001501void
1502swap(multiset<_Key, _Compare, _Allocator>& __x,
1503 multiset<_Key, _Compare, _Allocator>& __y)
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001504 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001505{
1506 __x.swap(__y);
1507}
1508
Marshall Clow29b53f22018-12-14 18:49:35 +00001509#if _LIBCPP_STD_VER > 17
1510template <class _Key, class _Compare, class _Allocator, class _Predicate>
1511inline _LIBCPP_INLINE_VISIBILITY
Marek Kurdeja98b1412020-05-02 13:58:03 +02001512 typename multiset<_Key, _Compare, _Allocator>::size_type
1513 erase_if(multiset<_Key, _Compare, _Allocator>& __c, _Predicate __pred) {
Arthur O'Dwyerb6738bd2021-03-21 16:53:09 -04001514 return _VSTD::__libcpp_erase_if_container(__c, __pred);
Marek Kurdeja98b1412020-05-02 13:58:03 +02001515}
Marshall Clow29b53f22018-12-14 18:49:35 +00001516#endif
1517
Howard Hinnantc51e1022010-05-11 19:42:16 +00001518_LIBCPP_END_NAMESPACE_STD
1519
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001520#endif // _LIBCPP_SET