blob: b9d2895fa7c8a2b9b40ef713bebe60c233f8a203 [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>
Arthur O'Dwyer7deec122021-03-24 18:19:12 -0400440#include <compare>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000441#include <functional>
Arthur O'Dwyer7deec122021-03-24 18:19:12 -0400442#include <initializer_list>
Arthur O'Dwyerb6738bd2021-03-21 16:53:09 -0400443#include <iterator> // __libcpp_erase_if_container
Marshall Clow0a1e7502018-09-12 19:41:40 +0000444#include <version>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000445
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000446#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000447#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000448#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000449
450_LIBCPP_BEGIN_NAMESPACE_STD
451
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000452template <class _Key, class _Compare, class _Allocator>
453class multiset;
454
Howard Hinnantc51e1022010-05-11 19:42:16 +0000455template <class _Key, class _Compare = less<_Key>,
456 class _Allocator = allocator<_Key> >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000457class _LIBCPP_TEMPLATE_VIS set
Howard Hinnantc51e1022010-05-11 19:42:16 +0000458{
459public:
460 // types:
461 typedef _Key key_type;
462 typedef key_type value_type;
463 typedef _Compare key_compare;
464 typedef key_compare value_compare;
Arthur O'Dwyer6a752e12021-03-03 11:10:49 -0500465 typedef __identity_t<_Allocator> allocator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000466 typedef value_type& reference;
467 typedef const value_type& const_reference;
468
Marshall Clow5128cf32015-11-26 01:24:04 +0000469 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
470 "Allocator::value_type must be same type as value_type");
471
Howard Hinnantc51e1022010-05-11 19:42:16 +0000472private:
473 typedef __tree<value_type, value_compare, allocator_type> __base;
474 typedef allocator_traits<allocator_type> __alloc_traits;
475 typedef typename __base::__node_holder __node_holder;
476
477 __base __tree_;
478
479public:
480 typedef typename __base::pointer pointer;
481 typedef typename __base::const_pointer const_pointer;
482 typedef typename __base::size_type size_type;
483 typedef typename __base::difference_type difference_type;
484 typedef typename __base::const_iterator iterator;
485 typedef typename __base::const_iterator const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000486 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
487 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000488
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000489#if _LIBCPP_STD_VER > 14
490 typedef __set_node_handle<typename __base::__node, allocator_type> node_type;
491 typedef __insert_return_type<iterator, node_type> insert_return_type;
492#endif
493
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000494 template <class _Key2, class _Compare2, class _Alloc2>
495 friend class _LIBCPP_TEMPLATE_VIS set;
496 template <class _Key2, class _Compare2, class _Alloc2>
497 friend class _LIBCPP_TEMPLATE_VIS multiset;
498
Howard Hinnant192cf032010-09-23 16:27:36 +0000499 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +0000500 set()
501 _NOEXCEPT_(
502 is_nothrow_default_constructible<allocator_type>::value &&
503 is_nothrow_default_constructible<key_compare>::value &&
504 is_nothrow_copy_constructible<key_compare>::value)
505 : __tree_(value_compare()) {}
506
507 _LIBCPP_INLINE_VISIBILITY
508 explicit set(const value_compare& __comp)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000509 _NOEXCEPT_(
510 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000511 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000512 : __tree_(__comp) {}
Marshall Clow7086a5a2014-03-10 04:50:10 +0000513
Howard Hinnant192cf032010-09-23 16:27:36 +0000514 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7ed23a72014-03-05 19:06:20 +0000515 explicit set(const value_compare& __comp, const allocator_type& __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000516 : __tree_(__comp, __a) {}
517 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000518 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000519 set(_InputIterator __f, _InputIterator __l,
520 const value_compare& __comp = value_compare())
521 : __tree_(__comp)
522 {
523 insert(__f, __l);
524 }
525
526 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000527 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000528 set(_InputIterator __f, _InputIterator __l, const value_compare& __comp,
529 const allocator_type& __a)
530 : __tree_(__comp, __a)
531 {
532 insert(__f, __l);
533 }
534
Marshall Clow631788a2013-09-11 00:06:45 +0000535#if _LIBCPP_STD_VER > 11
536 template <class _InputIterator>
Louis Dionned2322c82018-11-01 14:41:37 +0000537 _LIBCPP_INLINE_VISIBILITY
Marshall Clow631788a2013-09-11 00:06:45 +0000538 set(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
539 : set(__f, __l, key_compare(), __a) {}
540#endif
541
Howard Hinnant192cf032010-09-23 16:27:36 +0000542 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000543 set(const set& __s)
544 : __tree_(__s.__tree_)
545 {
546 insert(__s.begin(), __s.end());
547 }
548
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000549 _LIBCPP_INLINE_VISIBILITY
550 set& operator=(const set& __s)
551 {
552 __tree_ = __s.__tree_;
553 return *this;
554 }
555
Eric Fiselier615961b2017-04-18 20:58:03 +0000556#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant192cf032010-09-23 16:27:36 +0000557 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000558 set(set&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000559 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000560 : __tree_(_VSTD::move(__s.__tree_)) {}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400561#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000562
Howard Hinnant192cf032010-09-23 16:27:36 +0000563 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000564 explicit set(const allocator_type& __a)
565 : __tree_(__a) {}
566
Howard Hinnant192cf032010-09-23 16:27:36 +0000567 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000568 set(const set& __s, const allocator_type& __a)
569 : __tree_(__s.__tree_.value_comp(), __a)
570 {
571 insert(__s.begin(), __s.end());
572 }
573
Eric Fiselier615961b2017-04-18 20:58:03 +0000574#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000575 set(set&& __s, const allocator_type& __a);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000576
Howard Hinnant192cf032010-09-23 16:27:36 +0000577 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000578 set(initializer_list<value_type> __il, const value_compare& __comp = value_compare())
579 : __tree_(__comp)
580 {
581 insert(__il.begin(), __il.end());
582 }
583
Howard Hinnant192cf032010-09-23 16:27:36 +0000584 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000585 set(initializer_list<value_type> __il, const value_compare& __comp,
586 const allocator_type& __a)
587 : __tree_(__comp, __a)
588 {
589 insert(__il.begin(), __il.end());
590 }
591
Marshall Clow631788a2013-09-11 00:06:45 +0000592#if _LIBCPP_STD_VER > 11
Louis Dionned2322c82018-11-01 14:41:37 +0000593 _LIBCPP_INLINE_VISIBILITY
Marshall Clow631788a2013-09-11 00:06:45 +0000594 set(initializer_list<value_type> __il, const allocator_type& __a)
595 : set(__il, key_compare(), __a) {}
596#endif
597
Howard Hinnant192cf032010-09-23 16:27:36 +0000598 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000599 set& operator=(initializer_list<value_type> __il)
600 {
601 __tree_.__assign_unique(__il.begin(), __il.end());
602 return *this;
603 }
604
Howard Hinnant192cf032010-09-23 16:27:36 +0000605 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000606 set& operator=(set&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000607 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000608 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000609 __tree_ = _VSTD::move(__s.__tree_);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000610 return *this;
611 }
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400612#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000613
Howard Hinnant192cf032010-09-23 16:27:36 +0000614 _LIBCPP_INLINE_VISIBILITY
Louis Dionne69c42c02019-04-11 16:14:56 +0000615 ~set() {
616 static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), "");
617 }
618
619 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000620 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000621 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000622 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000623 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000624 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000625 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000626 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000627
Howard Hinnant192cf032010-09-23 16:27:36 +0000628 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000629 reverse_iterator rbegin() _NOEXCEPT
630 {return reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +0000631 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000632 const_reverse_iterator rbegin() const _NOEXCEPT
633 {return const_reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +0000634 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000635 reverse_iterator rend() _NOEXCEPT
636 {return reverse_iterator(begin());}
Howard Hinnant192cf032010-09-23 16:27:36 +0000637 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000638 const_reverse_iterator rend() const _NOEXCEPT
639 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000640
Howard Hinnant192cf032010-09-23 16:27:36 +0000641 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000642 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000643 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000644 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000645 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000646 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000647 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000648 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000649
Marshall Clow425f5752017-11-15 05:51:26 +0000650 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000651 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant192cf032010-09-23 16:27:36 +0000652 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000653 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000654 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000655 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000656
657 // modifiers:
Eric Fiselier615961b2017-04-18 20:58:03 +0000658#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000659 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +0000660 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000661 pair<iterator, bool> emplace(_Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000662 {return __tree_.__emplace_unique(_VSTD::forward<_Args>(__args)...);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000663 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +0000664 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000665 iterator emplace_hint(const_iterator __p, _Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000666 {return __tree_.__emplace_hint_unique(__p, _VSTD::forward<_Args>(__args)...);}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400667#endif // _LIBCPP_CXX03_LANG
Eric Fiselier615961b2017-04-18 20:58:03 +0000668
Howard Hinnant192cf032010-09-23 16:27:36 +0000669 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000670 pair<iterator,bool> insert(const value_type& __v)
671 {return __tree_.__insert_unique(__v);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000672 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000673 iterator insert(const_iterator __p, const value_type& __v)
674 {return __tree_.__insert_unique(__p, __v);}
Eric Fiselier615961b2017-04-18 20:58:03 +0000675
Howard Hinnantc51e1022010-05-11 19:42:16 +0000676 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000677 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000678 void insert(_InputIterator __f, _InputIterator __l)
679 {
680 for (const_iterator __e = cend(); __f != __l; ++__f)
681 __tree_.__insert_unique(__e, *__f);
682 }
683
Eric Fiselier615961b2017-04-18 20:58:03 +0000684#ifndef _LIBCPP_CXX03_LANG
685 _LIBCPP_INLINE_VISIBILITY
686 pair<iterator,bool> insert(value_type&& __v)
687 {return __tree_.__insert_unique(_VSTD::move(__v));}
688
689 _LIBCPP_INLINE_VISIBILITY
690 iterator insert(const_iterator __p, value_type&& __v)
691 {return __tree_.__insert_unique(__p, _VSTD::move(__v));}
692
Howard Hinnant192cf032010-09-23 16:27:36 +0000693 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000694 void insert(initializer_list<value_type> __il)
695 {insert(__il.begin(), __il.end());}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400696#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000697
Howard Hinnant192cf032010-09-23 16:27:36 +0000698 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000699 iterator erase(const_iterator __p) {return __tree_.erase(__p);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000700 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000701 size_type erase(const key_type& __k)
702 {return __tree_.__erase_unique(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000703 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000704 iterator erase(const_iterator __f, const_iterator __l)
705 {return __tree_.erase(__f, __l);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000706 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000707 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000708
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000709#if _LIBCPP_STD_VER > 14
710 _LIBCPP_INLINE_VISIBILITY
711 insert_return_type insert(node_type&& __nh)
712 {
713 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
714 "node_type with incompatible allocator passed to set::insert()");
715 return __tree_.template __node_handle_insert_unique<
716 node_type, insert_return_type>(_VSTD::move(__nh));
717 }
718 _LIBCPP_INLINE_VISIBILITY
719 iterator insert(const_iterator __hint, node_type&& __nh)
720 {
721 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
722 "node_type with incompatible allocator passed to set::insert()");
723 return __tree_.template __node_handle_insert_unique<node_type>(
724 __hint, _VSTD::move(__nh));
725 }
726 _LIBCPP_INLINE_VISIBILITY
727 node_type extract(key_type const& __key)
728 {
729 return __tree_.template __node_handle_extract<node_type>(__key);
730 }
731 _LIBCPP_INLINE_VISIBILITY
732 node_type extract(const_iterator __it)
733 {
734 return __tree_.template __node_handle_extract<node_type>(__it);
735 }
Louis Dionned2322c82018-11-01 14:41:37 +0000736 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000737 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +0000738 void merge(set<key_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000739 {
740 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
741 "merging container with incompatible allocator");
742 __tree_.__node_handle_merge_unique(__source.__tree_);
743 }
Louis Dionned2322c82018-11-01 14:41:37 +0000744 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000745 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +0000746 void merge(set<key_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000747 {
748 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
749 "merging container with incompatible allocator");
750 __tree_.__node_handle_merge_unique(__source.__tree_);
751 }
Louis Dionned2322c82018-11-01 14:41:37 +0000752 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000753 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +0000754 void merge(multiset<key_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000755 {
756 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
757 "merging container with incompatible allocator");
758 __tree_.__node_handle_merge_unique(__source.__tree_);
759 }
Louis Dionned2322c82018-11-01 14:41:37 +0000760 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000761 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +0000762 void merge(multiset<key_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000763 {
764 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
765 "merging container with incompatible allocator");
766 __tree_.__node_handle_merge_unique(__source.__tree_);
767 }
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000768#endif
769
Howard Hinnant192cf032010-09-23 16:27:36 +0000770 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000771 void swap(set& __s) _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
772 {__tree_.swap(__s.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000773
Howard Hinnant192cf032010-09-23 16:27:36 +0000774 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000775 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000776 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000777 key_compare key_comp() const {return __tree_.value_comp();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000778 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000779 value_compare value_comp() const {return __tree_.value_comp();}
780
781 // set operations:
Howard Hinnant192cf032010-09-23 16:27:36 +0000782 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000783 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000784 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000785 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000786#if _LIBCPP_STD_VER > 11
787 template <typename _K2>
788 _LIBCPP_INLINE_VISIBILITY
789 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
790 find(const _K2& __k) {return __tree_.find(__k);}
791 template <typename _K2>
792 _LIBCPP_INLINE_VISIBILITY
793 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
794 find(const _K2& __k) const {return __tree_.find(__k);}
795#endif
796
Howard Hinnant192cf032010-09-23 16:27:36 +0000797 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000798 size_type count(const key_type& __k) const
799 {return __tree_.__count_unique(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +0000800#if _LIBCPP_STD_VER > 11
801 template <typename _K2>
802 _LIBCPP_INLINE_VISIBILITY
803 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +0000804 count(const _K2& __k) const {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +0000805#endif
Zoe Carver3ffbab12019-07-16 03:21:01 +0000806
807#if _LIBCPP_STD_VER > 17
808 _LIBCPP_INLINE_VISIBILITY
809 bool contains(const key_type& __k) const {return find(__k) != end();}
Marek Kurdejd7e019e2021-04-13 17:10:55 +0200810 template <typename _K2>
811 _LIBCPP_INLINE_VISIBILITY
812 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
813 contains(const _K2& __k) const { return find(__k) != end(); }
Zoe Carver3ffbab12019-07-16 03:21:01 +0000814#endif // _LIBCPP_STD_VER > 17
815
Howard Hinnant192cf032010-09-23 16:27:36 +0000816 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000817 iterator lower_bound(const key_type& __k)
818 {return __tree_.lower_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000819 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000820 const_iterator lower_bound(const key_type& __k) const
821 {return __tree_.lower_bound(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000822#if _LIBCPP_STD_VER > 11
823 template <typename _K2>
824 _LIBCPP_INLINE_VISIBILITY
825 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
826 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
827
828 template <typename _K2>
829 _LIBCPP_INLINE_VISIBILITY
830 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
831 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
832#endif
833
Howard Hinnant192cf032010-09-23 16:27:36 +0000834 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000835 iterator upper_bound(const key_type& __k)
836 {return __tree_.upper_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000837 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000838 const_iterator upper_bound(const key_type& __k) const
839 {return __tree_.upper_bound(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000840#if _LIBCPP_STD_VER > 11
841 template <typename _K2>
842 _LIBCPP_INLINE_VISIBILITY
843 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
844 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
845 template <typename _K2>
846 _LIBCPP_INLINE_VISIBILITY
847 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
848 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
849#endif
850
Howard Hinnant192cf032010-09-23 16:27:36 +0000851 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000852 pair<iterator,iterator> equal_range(const key_type& __k)
853 {return __tree_.__equal_range_unique(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000854 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000855 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
856 {return __tree_.__equal_range_unique(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000857#if _LIBCPP_STD_VER > 11
858 template <typename _K2>
859 _LIBCPP_INLINE_VISIBILITY
860 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +0000861 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000862 template <typename _K2>
863 _LIBCPP_INLINE_VISIBILITY
864 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +0000865 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000866#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000867};
868
Louis Dionne27ecc152019-06-11 18:21:08 +0000869#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
870template<class _InputIterator,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500871 class _Compare = less<__iter_value_type<_InputIterator>>,
872 class _Allocator = allocator<__iter_value_type<_InputIterator>>,
Louis Dionne6c7da9a2019-07-19 17:13:39 +0000873 class = _EnableIf<__is_allocator<_Allocator>::value, void>,
874 class = _EnableIf<!__is_allocator<_Compare>::value, void>>
Louis Dionne27ecc152019-06-11 18:21:08 +0000875set(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500876 -> set<__iter_value_type<_InputIterator>, _Compare, _Allocator>;
Louis Dionne27ecc152019-06-11 18:21:08 +0000877
878template<class _Key, class _Compare = less<_Key>,
879 class _Allocator = allocator<_Key>,
Louis Dionne6c7da9a2019-07-19 17:13:39 +0000880 class = _EnableIf<__is_allocator<_Allocator>::value, void>,
881 class = _EnableIf<!__is_allocator<_Compare>::value, void>>
Louis Dionne27ecc152019-06-11 18:21:08 +0000882set(initializer_list<_Key>, _Compare = _Compare(), _Allocator = _Allocator())
883 -> set<_Key, _Compare, _Allocator>;
884
885template<class _InputIterator, class _Allocator,
Louis Dionne6c7da9a2019-07-19 17:13:39 +0000886 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
Louis Dionne27ecc152019-06-11 18:21:08 +0000887set(_InputIterator, _InputIterator, _Allocator)
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500888 -> set<__iter_value_type<_InputIterator>,
889 less<__iter_value_type<_InputIterator>>, _Allocator>;
Louis Dionne27ecc152019-06-11 18:21:08 +0000890
891template<class _Key, class _Allocator,
Louis Dionne6c7da9a2019-07-19 17:13:39 +0000892 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
Louis Dionne27ecc152019-06-11 18:21:08 +0000893set(initializer_list<_Key>, _Allocator)
894 -> set<_Key, less<_Key>, _Allocator>;
895#endif
896
Eric Fiselier615961b2017-04-18 20:58:03 +0000897#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000898
899template <class _Key, class _Compare, class _Allocator>
900set<_Key, _Compare, _Allocator>::set(set&& __s, const allocator_type& __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000901 : __tree_(_VSTD::move(__s.__tree_), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000902{
903 if (__a != __s.get_allocator())
904 {
905 const_iterator __e = cend();
906 while (!__s.empty())
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000907 insert(__e, _VSTD::move(__s.__tree_.remove(__s.begin())->__value_));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000908 }
909}
910
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400911#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000912
913template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000914inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000915bool
916operator==(const set<_Key, _Compare, _Allocator>& __x,
917 const set<_Key, _Compare, _Allocator>& __y)
918{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000919 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000920}
921
922template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000923inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000924bool
925operator< (const set<_Key, _Compare, _Allocator>& __x,
926 const set<_Key, _Compare, _Allocator>& __y)
927{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000928 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000929}
930
931template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000932inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000933bool
934operator!=(const set<_Key, _Compare, _Allocator>& __x,
935 const set<_Key, _Compare, _Allocator>& __y)
936{
937 return !(__x == __y);
938}
939
940template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000941inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000942bool
943operator> (const set<_Key, _Compare, _Allocator>& __x,
944 const set<_Key, _Compare, _Allocator>& __y)
945{
946 return __y < __x;
947}
948
949template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000950inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000951bool
952operator>=(const set<_Key, _Compare, _Allocator>& __x,
953 const set<_Key, _Compare, _Allocator>& __y)
954{
955 return !(__x < __y);
956}
957
958template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000959inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000960bool
961operator<=(const set<_Key, _Compare, _Allocator>& __x,
962 const set<_Key, _Compare, _Allocator>& __y)
963{
964 return !(__y < __x);
965}
966
967// specialized algorithms:
968template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000969inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000970void
971swap(set<_Key, _Compare, _Allocator>& __x,
972 set<_Key, _Compare, _Allocator>& __y)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000973 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000974{
975 __x.swap(__y);
976}
977
Marshall Clow29b53f22018-12-14 18:49:35 +0000978#if _LIBCPP_STD_VER > 17
979template <class _Key, class _Compare, class _Allocator, class _Predicate>
980inline _LIBCPP_INLINE_VISIBILITY
Marek Kurdeja98b1412020-05-02 13:58:03 +0200981 typename set<_Key, _Compare, _Allocator>::size_type
982 erase_if(set<_Key, _Compare, _Allocator>& __c, _Predicate __pred) {
Arthur O'Dwyerb6738bd2021-03-21 16:53:09 -0400983 return _VSTD::__libcpp_erase_if_container(__c, __pred);
Marek Kurdeja98b1412020-05-02 13:58:03 +0200984}
Marshall Clow29b53f22018-12-14 18:49:35 +0000985#endif
986
Howard Hinnantc51e1022010-05-11 19:42:16 +0000987template <class _Key, class _Compare = less<_Key>,
988 class _Allocator = allocator<_Key> >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000989class _LIBCPP_TEMPLATE_VIS multiset
Howard Hinnantc51e1022010-05-11 19:42:16 +0000990{
991public:
992 // types:
Arthur O'Dwyer6a752e12021-03-03 11:10:49 -0500993 typedef _Key key_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000994 typedef key_type value_type;
Arthur O'Dwyer6a752e12021-03-03 11:10:49 -0500995 typedef _Compare key_compare;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000996 typedef key_compare value_compare;
Arthur O'Dwyer6a752e12021-03-03 11:10:49 -0500997 typedef __identity_t<_Allocator> allocator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000998 typedef value_type& reference;
999 typedef const value_type& const_reference;
1000
Marshall Clow5128cf32015-11-26 01:24:04 +00001001 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
1002 "Allocator::value_type must be same type as value_type");
1003
Howard Hinnantc51e1022010-05-11 19:42:16 +00001004private:
1005 typedef __tree<value_type, value_compare, allocator_type> __base;
1006 typedef allocator_traits<allocator_type> __alloc_traits;
1007 typedef typename __base::__node_holder __node_holder;
1008
1009 __base __tree_;
1010
1011public:
1012 typedef typename __base::pointer pointer;
1013 typedef typename __base::const_pointer const_pointer;
1014 typedef typename __base::size_type size_type;
1015 typedef typename __base::difference_type difference_type;
1016 typedef typename __base::const_iterator iterator;
1017 typedef typename __base::const_iterator const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001018 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1019 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001020
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001021#if _LIBCPP_STD_VER > 14
1022 typedef __set_node_handle<typename __base::__node, allocator_type> node_type;
1023#endif
1024
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001025 template <class _Key2, class _Compare2, class _Alloc2>
1026 friend class _LIBCPP_TEMPLATE_VIS set;
1027 template <class _Key2, class _Compare2, class _Alloc2>
1028 friend class _LIBCPP_TEMPLATE_VIS multiset;
1029
Howard Hinnantc51e1022010-05-11 19:42:16 +00001030 // construct/copy/destroy:
Howard Hinnant192cf032010-09-23 16:27:36 +00001031 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +00001032 multiset()
1033 _NOEXCEPT_(
1034 is_nothrow_default_constructible<allocator_type>::value &&
1035 is_nothrow_default_constructible<key_compare>::value &&
1036 is_nothrow_copy_constructible<key_compare>::value)
1037 : __tree_(value_compare()) {}
1038
1039 _LIBCPP_INLINE_VISIBILITY
1040 explicit multiset(const value_compare& __comp)
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001041 _NOEXCEPT_(
1042 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001043 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001044 : __tree_(__comp) {}
Marshall Clow7086a5a2014-03-10 04:50:10 +00001045
Howard Hinnant192cf032010-09-23 16:27:36 +00001046 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7ed23a72014-03-05 19:06:20 +00001047 explicit multiset(const value_compare& __comp, const allocator_type& __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001048 : __tree_(__comp, __a) {}
1049 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001050 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001051 multiset(_InputIterator __f, _InputIterator __l,
1052 const value_compare& __comp = value_compare())
1053 : __tree_(__comp)
1054 {
1055 insert(__f, __l);
1056 }
1057
Marshall Clow631788a2013-09-11 00:06:45 +00001058#if _LIBCPP_STD_VER > 11
1059 template <class _InputIterator>
Louis Dionned2322c82018-11-01 14:41:37 +00001060 _LIBCPP_INLINE_VISIBILITY
Marshall Clow631788a2013-09-11 00:06:45 +00001061 multiset(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
1062 : multiset(__f, __l, key_compare(), __a) {}
1063#endif
1064
Howard Hinnantc51e1022010-05-11 19:42:16 +00001065 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001066 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001067 multiset(_InputIterator __f, _InputIterator __l,
1068 const value_compare& __comp, const allocator_type& __a)
1069 : __tree_(__comp, __a)
1070 {
1071 insert(__f, __l);
1072 }
1073
Howard Hinnant192cf032010-09-23 16:27:36 +00001074 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001075 multiset(const multiset& __s)
1076 : __tree_(__s.__tree_.value_comp(),
1077 __alloc_traits::select_on_container_copy_construction(__s.__tree_.__alloc()))
1078 {
1079 insert(__s.begin(), __s.end());
1080 }
1081
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001082 _LIBCPP_INLINE_VISIBILITY
1083 multiset& operator=(const multiset& __s)
1084 {
1085 __tree_ = __s.__tree_;
1086 return *this;
1087 }
1088
Eric Fiselier615961b2017-04-18 20:58:03 +00001089#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant192cf032010-09-23 16:27:36 +00001090 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001091 multiset(multiset&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001092 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001093 : __tree_(_VSTD::move(__s.__tree_)) {}
Eric Fiselier615961b2017-04-18 20:58:03 +00001094
1095 multiset(multiset&& __s, const allocator_type& __a);
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001096#endif // _LIBCPP_CXX03_LANG
Howard Hinnant192cf032010-09-23 16:27:36 +00001097 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001098 explicit multiset(const allocator_type& __a)
1099 : __tree_(__a) {}
Howard Hinnant192cf032010-09-23 16:27:36 +00001100 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001101 multiset(const multiset& __s, const allocator_type& __a)
1102 : __tree_(__s.__tree_.value_comp(), __a)
1103 {
1104 insert(__s.begin(), __s.end());
1105 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001106
Eric Fiselier615961b2017-04-18 20:58:03 +00001107#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant192cf032010-09-23 16:27:36 +00001108 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001109 multiset(initializer_list<value_type> __il, const value_compare& __comp = value_compare())
1110 : __tree_(__comp)
1111 {
1112 insert(__il.begin(), __il.end());
1113 }
1114
Howard Hinnant192cf032010-09-23 16:27:36 +00001115 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001116 multiset(initializer_list<value_type> __il, const value_compare& __comp,
1117 const allocator_type& __a)
1118 : __tree_(__comp, __a)
1119 {
1120 insert(__il.begin(), __il.end());
1121 }
1122
Marshall Clow631788a2013-09-11 00:06:45 +00001123#if _LIBCPP_STD_VER > 11
Louis Dionned2322c82018-11-01 14:41:37 +00001124 _LIBCPP_INLINE_VISIBILITY
Marshall Clow631788a2013-09-11 00:06:45 +00001125 multiset(initializer_list<value_type> __il, const allocator_type& __a)
1126 : multiset(__il, key_compare(), __a) {}
1127#endif
1128
Howard Hinnant192cf032010-09-23 16:27:36 +00001129 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001130 multiset& operator=(initializer_list<value_type> __il)
1131 {
1132 __tree_.__assign_multi(__il.begin(), __il.end());
1133 return *this;
1134 }
1135
Howard Hinnant192cf032010-09-23 16:27:36 +00001136 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001137 multiset& operator=(multiset&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001138 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001139 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001140 __tree_ = _VSTD::move(__s.__tree_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001141 return *this;
1142 }
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001143#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001144
Howard Hinnant192cf032010-09-23 16:27:36 +00001145 _LIBCPP_INLINE_VISIBILITY
Louis Dionne69c42c02019-04-11 16:14:56 +00001146 ~multiset() {
1147 static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), "");
1148 }
1149
1150 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001151 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001152 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001153 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001154 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001155 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001156 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001157 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001158
Howard Hinnant192cf032010-09-23 16:27:36 +00001159 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001160 reverse_iterator rbegin() _NOEXCEPT
1161 {return reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +00001162 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001163 const_reverse_iterator rbegin() const _NOEXCEPT
1164 {return const_reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +00001165 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001166 reverse_iterator rend() _NOEXCEPT
1167 {return reverse_iterator(begin());}
Howard Hinnant192cf032010-09-23 16:27:36 +00001168 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001169 const_reverse_iterator rend() const _NOEXCEPT
1170 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001171
Howard Hinnant192cf032010-09-23 16:27:36 +00001172 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001173 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001174 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001175 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001176 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001177 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001178 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001179 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001180
Marshall Clow425f5752017-11-15 05:51:26 +00001181 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001182 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant192cf032010-09-23 16:27:36 +00001183 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001184 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001185 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001186 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001187
1188 // modifiers:
Eric Fiselier615961b2017-04-18 20:58:03 +00001189#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001190 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +00001191 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001192 iterator emplace(_Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001193 {return __tree_.__emplace_multi(_VSTD::forward<_Args>(__args)...);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001194 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +00001195 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001196 iterator emplace_hint(const_iterator __p, _Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001197 {return __tree_.__emplace_hint_multi(__p, _VSTD::forward<_Args>(__args)...);}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001198#endif // _LIBCPP_CXX03_LANG
Eric Fiselier615961b2017-04-18 20:58:03 +00001199
Howard Hinnant192cf032010-09-23 16:27:36 +00001200 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001201 iterator insert(const value_type& __v)
1202 {return __tree_.__insert_multi(__v);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001203 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001204 iterator insert(const_iterator __p, const value_type& __v)
1205 {return __tree_.__insert_multi(__p, __v);}
Eric Fiselier615961b2017-04-18 20:58:03 +00001206
Howard Hinnantc51e1022010-05-11 19:42:16 +00001207 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001208 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001209 void insert(_InputIterator __f, _InputIterator __l)
1210 {
1211 for (const_iterator __e = cend(); __f != __l; ++__f)
1212 __tree_.__insert_multi(__e, *__f);
1213 }
1214
Eric Fiselier615961b2017-04-18 20:58:03 +00001215#ifndef _LIBCPP_CXX03_LANG
1216 _LIBCPP_INLINE_VISIBILITY
1217 iterator insert(value_type&& __v)
1218 {return __tree_.__insert_multi(_VSTD::move(__v));}
1219
1220 _LIBCPP_INLINE_VISIBILITY
1221 iterator insert(const_iterator __p, value_type&& __v)
1222 {return __tree_.__insert_multi(__p, _VSTD::move(__v));}
1223
Howard Hinnant192cf032010-09-23 16:27:36 +00001224 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001225 void insert(initializer_list<value_type> __il)
1226 {insert(__il.begin(), __il.end());}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001227#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001228
Howard Hinnant192cf032010-09-23 16:27:36 +00001229 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001230 iterator erase(const_iterator __p) {return __tree_.erase(__p);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001231 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001232 size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001233 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001234 iterator erase(const_iterator __f, const_iterator __l)
1235 {return __tree_.erase(__f, __l);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001236 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001237 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001238
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001239#if _LIBCPP_STD_VER > 14
1240 _LIBCPP_INLINE_VISIBILITY
1241 iterator insert(node_type&& __nh)
1242 {
1243 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1244 "node_type with incompatible allocator passed to multiset::insert()");
1245 return __tree_.template __node_handle_insert_multi<node_type>(
1246 _VSTD::move(__nh));
1247 }
1248 _LIBCPP_INLINE_VISIBILITY
1249 iterator insert(const_iterator __hint, node_type&& __nh)
1250 {
1251 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1252 "node_type with incompatible allocator passed to multiset::insert()");
1253 return __tree_.template __node_handle_insert_multi<node_type>(
1254 __hint, _VSTD::move(__nh));
1255 }
1256 _LIBCPP_INLINE_VISIBILITY
1257 node_type extract(key_type const& __key)
1258 {
1259 return __tree_.template __node_handle_extract<node_type>(__key);
1260 }
1261 _LIBCPP_INLINE_VISIBILITY
1262 node_type extract(const_iterator __it)
1263 {
1264 return __tree_.template __node_handle_extract<node_type>(__it);
1265 }
Louis Dionned2322c82018-11-01 14:41:37 +00001266 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001267 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001268 void merge(multiset<key_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001269 {
1270 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1271 "merging container with incompatible allocator");
1272 __tree_.__node_handle_merge_multi(__source.__tree_);
1273 }
Louis Dionned2322c82018-11-01 14:41:37 +00001274 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001275 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001276 void merge(multiset<key_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001277 {
1278 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1279 "merging container with incompatible allocator");
1280 __tree_.__node_handle_merge_multi(__source.__tree_);
1281 }
Louis Dionned2322c82018-11-01 14:41:37 +00001282 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001283 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001284 void merge(set<key_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001285 {
1286 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1287 "merging container with incompatible allocator");
1288 __tree_.__node_handle_merge_multi(__source.__tree_);
1289 }
Louis Dionned2322c82018-11-01 14:41:37 +00001290 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001291 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001292 void merge(set<key_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001293 {
1294 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1295 "merging container with incompatible allocator");
1296 __tree_.__node_handle_merge_multi(__source.__tree_);
1297 }
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001298#endif
1299
Howard Hinnant192cf032010-09-23 16:27:36 +00001300 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001301 void swap(multiset& __s)
1302 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1303 {__tree_.swap(__s.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001304
Howard Hinnant192cf032010-09-23 16:27:36 +00001305 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001306 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001307 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001308 key_compare key_comp() const {return __tree_.value_comp();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001309 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001310 value_compare value_comp() const {return __tree_.value_comp();}
1311
1312 // set operations:
Howard Hinnant192cf032010-09-23 16:27:36 +00001313 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001314 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001315 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001316 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +00001317#if _LIBCPP_STD_VER > 11
1318 template <typename _K2>
1319 _LIBCPP_INLINE_VISIBILITY
Mark de Wever9d7aa7a2021-05-09 18:22:52 +02001320 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
Marshall Clowc0152142013-08-13 01:11:06 +00001321 find(const _K2& __k) {return __tree_.find(__k);}
1322 template <typename _K2>
1323 _LIBCPP_INLINE_VISIBILITY
Mark de Wever9d7aa7a2021-05-09 18:22:52 +02001324 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
Marshall Clowc0152142013-08-13 01:11:06 +00001325 find(const _K2& __k) const {return __tree_.find(__k);}
1326#endif
1327
Howard Hinnant192cf032010-09-23 16:27:36 +00001328 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001329 size_type count(const key_type& __k) const
1330 {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001331#if _LIBCPP_STD_VER > 11
1332 template <typename _K2>
1333 _LIBCPP_INLINE_VISIBILITY
1334 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
Marshall Clow5571bcd2018-01-07 17:39:57 +00001335 count(const _K2& __k) const {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001336#endif
Marshall Clowc0152142013-08-13 01:11:06 +00001337
Zoe Carver3ffbab12019-07-16 03:21:01 +00001338#if _LIBCPP_STD_VER > 17
1339 _LIBCPP_INLINE_VISIBILITY
1340 bool contains(const key_type& __k) const {return find(__k) != end();}
Marek Kurdejd7e019e2021-04-13 17:10:55 +02001341 template <typename _K2>
1342 _LIBCPP_INLINE_VISIBILITY
1343 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
1344 contains(const _K2& __k) const { return find(__k) != end(); }
Zoe Carver3ffbab12019-07-16 03:21:01 +00001345#endif // _LIBCPP_STD_VER > 17
1346
Howard Hinnant192cf032010-09-23 16:27:36 +00001347 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001348 iterator lower_bound(const key_type& __k)
1349 {return __tree_.lower_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001350 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001351 const_iterator lower_bound(const key_type& __k) const
1352 {return __tree_.lower_bound(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +00001353#if _LIBCPP_STD_VER > 11
1354 template <typename _K2>
1355 _LIBCPP_INLINE_VISIBILITY
Mark de Wever9d7aa7a2021-05-09 18:22:52 +02001356 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
Marshall Clowc0152142013-08-13 01:11:06 +00001357 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
1358
1359 template <typename _K2>
1360 _LIBCPP_INLINE_VISIBILITY
Mark de Wever9d7aa7a2021-05-09 18:22:52 +02001361 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
Marshall Clowc0152142013-08-13 01:11:06 +00001362 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
1363#endif
1364
Howard Hinnant192cf032010-09-23 16:27:36 +00001365 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001366 iterator upper_bound(const key_type& __k)
1367 {return __tree_.upper_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001368 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001369 const_iterator upper_bound(const key_type& __k) const
1370 {return __tree_.upper_bound(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +00001371#if _LIBCPP_STD_VER > 11
1372 template <typename _K2>
1373 _LIBCPP_INLINE_VISIBILITY
Mark de Wever9d7aa7a2021-05-09 18:22:52 +02001374 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
Marshall Clowc0152142013-08-13 01:11:06 +00001375 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
1376 template <typename _K2>
1377 _LIBCPP_INLINE_VISIBILITY
Mark de Wever9d7aa7a2021-05-09 18:22:52 +02001378 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
Marshall Clowc0152142013-08-13 01:11:06 +00001379 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
1380#endif
1381
Howard Hinnant192cf032010-09-23 16:27:36 +00001382 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001383 pair<iterator,iterator> equal_range(const key_type& __k)
1384 {return __tree_.__equal_range_multi(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001385 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001386 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
1387 {return __tree_.__equal_range_multi(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +00001388#if _LIBCPP_STD_VER > 11
1389 template <typename _K2>
1390 _LIBCPP_INLINE_VISIBILITY
Mark de Wever9d7aa7a2021-05-09 18:22:52 +02001391 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
Marshall Clowc0152142013-08-13 01:11:06 +00001392 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
1393 template <typename _K2>
1394 _LIBCPP_INLINE_VISIBILITY
Mark de Wever9d7aa7a2021-05-09 18:22:52 +02001395 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
Marshall Clowc0152142013-08-13 01:11:06 +00001396 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
1397#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001398};
1399
Louis Dionne27ecc152019-06-11 18:21:08 +00001400#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
1401template<class _InputIterator,
Arthur O'Dwyer56226762021-03-03 23:02:20 -05001402 class _Compare = less<__iter_value_type<_InputIterator>>,
1403 class _Allocator = allocator<__iter_value_type<_InputIterator>>,
Louis Dionne6c7da9a2019-07-19 17:13:39 +00001404 class = _EnableIf<__is_allocator<_Allocator>::value, void>,
1405 class = _EnableIf<!__is_allocator<_Compare>::value, void>>
Louis Dionne27ecc152019-06-11 18:21:08 +00001406multiset(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
Arthur O'Dwyer56226762021-03-03 23:02:20 -05001407 -> multiset<__iter_value_type<_InputIterator>, _Compare, _Allocator>;
Louis Dionne27ecc152019-06-11 18:21:08 +00001408
1409template<class _Key, class _Compare = less<_Key>,
1410 class _Allocator = allocator<_Key>,
Louis Dionne6c7da9a2019-07-19 17:13:39 +00001411 class = _EnableIf<__is_allocator<_Allocator>::value, void>,
1412 class = _EnableIf<!__is_allocator<_Compare>::value, void>>
Louis Dionne27ecc152019-06-11 18:21:08 +00001413multiset(initializer_list<_Key>, _Compare = _Compare(), _Allocator = _Allocator())
1414 -> multiset<_Key, _Compare, _Allocator>;
1415
1416template<class _InputIterator, class _Allocator,
Louis Dionne6c7da9a2019-07-19 17:13:39 +00001417 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
Louis Dionne27ecc152019-06-11 18:21:08 +00001418multiset(_InputIterator, _InputIterator, _Allocator)
Arthur O'Dwyer56226762021-03-03 23:02:20 -05001419 -> multiset<__iter_value_type<_InputIterator>,
1420 less<__iter_value_type<_InputIterator>>, _Allocator>;
Louis Dionne27ecc152019-06-11 18:21:08 +00001421
1422template<class _Key, class _Allocator,
Louis Dionne6c7da9a2019-07-19 17:13:39 +00001423 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
Louis Dionne27ecc152019-06-11 18:21:08 +00001424multiset(initializer_list<_Key>, _Allocator)
1425 -> multiset<_Key, less<_Key>, _Allocator>;
1426#endif
1427
Eric Fiselier615961b2017-04-18 20:58:03 +00001428#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001429
1430template <class _Key, class _Compare, class _Allocator>
1431multiset<_Key, _Compare, _Allocator>::multiset(multiset&& __s, const allocator_type& __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001432 : __tree_(_VSTD::move(__s.__tree_), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001433{
1434 if (__a != __s.get_allocator())
1435 {
1436 const_iterator __e = cend();
1437 while (!__s.empty())
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001438 insert(__e, _VSTD::move(__s.__tree_.remove(__s.begin())->__value_));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001439 }
1440}
1441
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001442#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001443
1444template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001445inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001446bool
1447operator==(const multiset<_Key, _Compare, _Allocator>& __x,
1448 const multiset<_Key, _Compare, _Allocator>& __y)
1449{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001450 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001451}
1452
1453template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001454inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001455bool
1456operator< (const multiset<_Key, _Compare, _Allocator>& __x,
1457 const multiset<_Key, _Compare, _Allocator>& __y)
1458{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001459 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001460}
1461
1462template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001463inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001464bool
1465operator!=(const multiset<_Key, _Compare, _Allocator>& __x,
1466 const multiset<_Key, _Compare, _Allocator>& __y)
1467{
1468 return !(__x == __y);
1469}
1470
1471template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001472inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001473bool
1474operator> (const multiset<_Key, _Compare, _Allocator>& __x,
1475 const multiset<_Key, _Compare, _Allocator>& __y)
1476{
1477 return __y < __x;
1478}
1479
1480template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001481inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001482bool
1483operator>=(const multiset<_Key, _Compare, _Allocator>& __x,
1484 const multiset<_Key, _Compare, _Allocator>& __y)
1485{
1486 return !(__x < __y);
1487}
1488
1489template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001490inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001491bool
1492operator<=(const multiset<_Key, _Compare, _Allocator>& __x,
1493 const multiset<_Key, _Compare, _Allocator>& __y)
1494{
1495 return !(__y < __x);
1496}
1497
1498template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001499inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001500void
1501swap(multiset<_Key, _Compare, _Allocator>& __x,
1502 multiset<_Key, _Compare, _Allocator>& __y)
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001503 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001504{
1505 __x.swap(__y);
1506}
1507
Marshall Clow29b53f22018-12-14 18:49:35 +00001508#if _LIBCPP_STD_VER > 17
1509template <class _Key, class _Compare, class _Allocator, class _Predicate>
1510inline _LIBCPP_INLINE_VISIBILITY
Marek Kurdeja98b1412020-05-02 13:58:03 +02001511 typename multiset<_Key, _Compare, _Allocator>::size_type
1512 erase_if(multiset<_Key, _Compare, _Allocator>& __c, _Predicate __pred) {
Arthur O'Dwyerb6738bd2021-03-21 16:53:09 -04001513 return _VSTD::__libcpp_erase_if_container(__c, __pred);
Marek Kurdeja98b1412020-05-02 13:58:03 +02001514}
Marshall Clow29b53f22018-12-14 18:49:35 +00001515#endif
1516
Howard Hinnantc51e1022010-05-11 19:42:16 +00001517_LIBCPP_END_NAMESPACE_STD
1518
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001519#endif // _LIBCPP_SET