blob: 0a1cc0618d9ca7935fe56f51ebd5b3822d83b90e [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>
437#include <__tree>
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000438#include <__node_handle>
Arthur O'Dwyer7deec122021-03-24 18:19:12 -0400439#include <compare>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000440#include <functional>
Arthur O'Dwyer7deec122021-03-24 18:19:12 -0400441#include <initializer_list>
Arthur O'Dwyerb6738bd2021-03-21 16:53:09 -0400442#include <iterator> // __libcpp_erase_if_container
Marshall Clow0a1e7502018-09-12 19:41:40 +0000443#include <version>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000444
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000445#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000446#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000447#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000448
449_LIBCPP_BEGIN_NAMESPACE_STD
450
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000451template <class _Key, class _Compare, class _Allocator>
452class multiset;
453
Howard Hinnantc51e1022010-05-11 19:42:16 +0000454template <class _Key, class _Compare = less<_Key>,
455 class _Allocator = allocator<_Key> >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000456class _LIBCPP_TEMPLATE_VIS set
Howard Hinnantc51e1022010-05-11 19:42:16 +0000457{
458public:
459 // types:
460 typedef _Key key_type;
461 typedef key_type value_type;
462 typedef _Compare key_compare;
463 typedef key_compare value_compare;
Arthur O'Dwyer6a752e12021-03-03 11:10:49 -0500464 typedef __identity_t<_Allocator> allocator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000465 typedef value_type& reference;
466 typedef const value_type& const_reference;
467
Marshall Clow5128cf32015-11-26 01:24:04 +0000468 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
469 "Allocator::value_type must be same type as value_type");
470
Howard Hinnantc51e1022010-05-11 19:42:16 +0000471private:
472 typedef __tree<value_type, value_compare, allocator_type> __base;
473 typedef allocator_traits<allocator_type> __alloc_traits;
474 typedef typename __base::__node_holder __node_holder;
475
476 __base __tree_;
477
478public:
479 typedef typename __base::pointer pointer;
480 typedef typename __base::const_pointer const_pointer;
481 typedef typename __base::size_type size_type;
482 typedef typename __base::difference_type difference_type;
483 typedef typename __base::const_iterator iterator;
484 typedef typename __base::const_iterator const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000485 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
486 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000487
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000488#if _LIBCPP_STD_VER > 14
489 typedef __set_node_handle<typename __base::__node, allocator_type> node_type;
490 typedef __insert_return_type<iterator, node_type> insert_return_type;
491#endif
492
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000493 template <class _Key2, class _Compare2, class _Alloc2>
494 friend class _LIBCPP_TEMPLATE_VIS set;
495 template <class _Key2, class _Compare2, class _Alloc2>
496 friend class _LIBCPP_TEMPLATE_VIS multiset;
497
Howard Hinnant192cf032010-09-23 16:27:36 +0000498 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +0000499 set()
500 _NOEXCEPT_(
501 is_nothrow_default_constructible<allocator_type>::value &&
502 is_nothrow_default_constructible<key_compare>::value &&
503 is_nothrow_copy_constructible<key_compare>::value)
504 : __tree_(value_compare()) {}
505
506 _LIBCPP_INLINE_VISIBILITY
507 explicit set(const value_compare& __comp)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000508 _NOEXCEPT_(
509 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000510 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000511 : __tree_(__comp) {}
Marshall Clow7086a5a2014-03-10 04:50:10 +0000512
Howard Hinnant192cf032010-09-23 16:27:36 +0000513 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7ed23a72014-03-05 19:06:20 +0000514 explicit set(const value_compare& __comp, const allocator_type& __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000515 : __tree_(__comp, __a) {}
516 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000517 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000518 set(_InputIterator __f, _InputIterator __l,
519 const value_compare& __comp = value_compare())
520 : __tree_(__comp)
521 {
522 insert(__f, __l);
523 }
524
525 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000526 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000527 set(_InputIterator __f, _InputIterator __l, const value_compare& __comp,
528 const allocator_type& __a)
529 : __tree_(__comp, __a)
530 {
531 insert(__f, __l);
532 }
533
Marshall Clow631788a2013-09-11 00:06:45 +0000534#if _LIBCPP_STD_VER > 11
535 template <class _InputIterator>
Louis Dionned2322c82018-11-01 14:41:37 +0000536 _LIBCPP_INLINE_VISIBILITY
Marshall Clow631788a2013-09-11 00:06:45 +0000537 set(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
538 : set(__f, __l, key_compare(), __a) {}
539#endif
540
Howard Hinnant192cf032010-09-23 16:27:36 +0000541 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000542 set(const set& __s)
543 : __tree_(__s.__tree_)
544 {
545 insert(__s.begin(), __s.end());
546 }
547
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000548 _LIBCPP_INLINE_VISIBILITY
549 set& operator=(const set& __s)
550 {
551 __tree_ = __s.__tree_;
552 return *this;
553 }
554
Eric Fiselier615961b2017-04-18 20:58:03 +0000555#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant192cf032010-09-23 16:27:36 +0000556 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000557 set(set&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000558 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000559 : __tree_(_VSTD::move(__s.__tree_)) {}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400560#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000561
Howard Hinnant192cf032010-09-23 16:27:36 +0000562 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000563 explicit set(const allocator_type& __a)
564 : __tree_(__a) {}
565
Howard Hinnant192cf032010-09-23 16:27:36 +0000566 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000567 set(const set& __s, const allocator_type& __a)
568 : __tree_(__s.__tree_.value_comp(), __a)
569 {
570 insert(__s.begin(), __s.end());
571 }
572
Eric Fiselier615961b2017-04-18 20:58:03 +0000573#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000574 set(set&& __s, const allocator_type& __a);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000575
Howard Hinnant192cf032010-09-23 16:27:36 +0000576 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000577 set(initializer_list<value_type> __il, const value_compare& __comp = value_compare())
578 : __tree_(__comp)
579 {
580 insert(__il.begin(), __il.end());
581 }
582
Howard Hinnant192cf032010-09-23 16:27:36 +0000583 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000584 set(initializer_list<value_type> __il, const value_compare& __comp,
585 const allocator_type& __a)
586 : __tree_(__comp, __a)
587 {
588 insert(__il.begin(), __il.end());
589 }
590
Marshall Clow631788a2013-09-11 00:06:45 +0000591#if _LIBCPP_STD_VER > 11
Louis Dionned2322c82018-11-01 14:41:37 +0000592 _LIBCPP_INLINE_VISIBILITY
Marshall Clow631788a2013-09-11 00:06:45 +0000593 set(initializer_list<value_type> __il, const allocator_type& __a)
594 : set(__il, key_compare(), __a) {}
595#endif
596
Howard Hinnant192cf032010-09-23 16:27:36 +0000597 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000598 set& operator=(initializer_list<value_type> __il)
599 {
600 __tree_.__assign_unique(__il.begin(), __il.end());
601 return *this;
602 }
603
Howard Hinnant192cf032010-09-23 16:27:36 +0000604 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000605 set& operator=(set&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000606 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000607 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000608 __tree_ = _VSTD::move(__s.__tree_);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000609 return *this;
610 }
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400611#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000612
Howard Hinnant192cf032010-09-23 16:27:36 +0000613 _LIBCPP_INLINE_VISIBILITY
Louis Dionne69c42c02019-04-11 16:14:56 +0000614 ~set() {
615 static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), "");
616 }
617
618 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000619 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000620 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000621 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000622 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000623 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000624 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000625 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000626
Howard Hinnant192cf032010-09-23 16:27:36 +0000627 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000628 reverse_iterator rbegin() _NOEXCEPT
629 {return reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +0000630 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000631 const_reverse_iterator rbegin() const _NOEXCEPT
632 {return const_reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +0000633 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000634 reverse_iterator rend() _NOEXCEPT
635 {return reverse_iterator(begin());}
Howard Hinnant192cf032010-09-23 16:27:36 +0000636 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000637 const_reverse_iterator rend() const _NOEXCEPT
638 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000639
Howard Hinnant192cf032010-09-23 16:27:36 +0000640 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000641 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000642 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000643 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000644 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000645 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000646 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000647 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000648
Marshall Clow425f5752017-11-15 05:51:26 +0000649 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000650 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant192cf032010-09-23 16:27:36 +0000651 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000652 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000653 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000654 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000655
656 // modifiers:
Eric Fiselier615961b2017-04-18 20:58:03 +0000657#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000658 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +0000659 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000660 pair<iterator, bool> emplace(_Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000661 {return __tree_.__emplace_unique(_VSTD::forward<_Args>(__args)...);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000662 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +0000663 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000664 iterator emplace_hint(const_iterator __p, _Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000665 {return __tree_.__emplace_hint_unique(__p, _VSTD::forward<_Args>(__args)...);}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400666#endif // _LIBCPP_CXX03_LANG
Eric Fiselier615961b2017-04-18 20:58:03 +0000667
Howard Hinnant192cf032010-09-23 16:27:36 +0000668 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000669 pair<iterator,bool> insert(const value_type& __v)
670 {return __tree_.__insert_unique(__v);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000671 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000672 iterator insert(const_iterator __p, const value_type& __v)
673 {return __tree_.__insert_unique(__p, __v);}
Eric Fiselier615961b2017-04-18 20:58:03 +0000674
Howard Hinnantc51e1022010-05-11 19:42:16 +0000675 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000676 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000677 void insert(_InputIterator __f, _InputIterator __l)
678 {
679 for (const_iterator __e = cend(); __f != __l; ++__f)
680 __tree_.__insert_unique(__e, *__f);
681 }
682
Eric Fiselier615961b2017-04-18 20:58:03 +0000683#ifndef _LIBCPP_CXX03_LANG
684 _LIBCPP_INLINE_VISIBILITY
685 pair<iterator,bool> insert(value_type&& __v)
686 {return __tree_.__insert_unique(_VSTD::move(__v));}
687
688 _LIBCPP_INLINE_VISIBILITY
689 iterator insert(const_iterator __p, value_type&& __v)
690 {return __tree_.__insert_unique(__p, _VSTD::move(__v));}
691
Howard Hinnant192cf032010-09-23 16:27:36 +0000692 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000693 void insert(initializer_list<value_type> __il)
694 {insert(__il.begin(), __il.end());}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400695#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000696
Howard Hinnant192cf032010-09-23 16:27:36 +0000697 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000698 iterator erase(const_iterator __p) {return __tree_.erase(__p);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000699 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000700 size_type erase(const key_type& __k)
701 {return __tree_.__erase_unique(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000702 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000703 iterator erase(const_iterator __f, const_iterator __l)
704 {return __tree_.erase(__f, __l);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000705 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000706 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000707
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000708#if _LIBCPP_STD_VER > 14
709 _LIBCPP_INLINE_VISIBILITY
710 insert_return_type insert(node_type&& __nh)
711 {
712 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
713 "node_type with incompatible allocator passed to set::insert()");
714 return __tree_.template __node_handle_insert_unique<
715 node_type, insert_return_type>(_VSTD::move(__nh));
716 }
717 _LIBCPP_INLINE_VISIBILITY
718 iterator insert(const_iterator __hint, node_type&& __nh)
719 {
720 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
721 "node_type with incompatible allocator passed to set::insert()");
722 return __tree_.template __node_handle_insert_unique<node_type>(
723 __hint, _VSTD::move(__nh));
724 }
725 _LIBCPP_INLINE_VISIBILITY
726 node_type extract(key_type const& __key)
727 {
728 return __tree_.template __node_handle_extract<node_type>(__key);
729 }
730 _LIBCPP_INLINE_VISIBILITY
731 node_type extract(const_iterator __it)
732 {
733 return __tree_.template __node_handle_extract<node_type>(__it);
734 }
Louis Dionned2322c82018-11-01 14:41:37 +0000735 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000736 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +0000737 void merge(set<key_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000738 {
739 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
740 "merging container with incompatible allocator");
741 __tree_.__node_handle_merge_unique(__source.__tree_);
742 }
Louis Dionned2322c82018-11-01 14:41:37 +0000743 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000744 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +0000745 void merge(set<key_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000746 {
747 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
748 "merging container with incompatible allocator");
749 __tree_.__node_handle_merge_unique(__source.__tree_);
750 }
Louis Dionned2322c82018-11-01 14:41:37 +0000751 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000752 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +0000753 void merge(multiset<key_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000754 {
755 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
756 "merging container with incompatible allocator");
757 __tree_.__node_handle_merge_unique(__source.__tree_);
758 }
Louis Dionned2322c82018-11-01 14:41:37 +0000759 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000760 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +0000761 void merge(multiset<key_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000762 {
763 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
764 "merging container with incompatible allocator");
765 __tree_.__node_handle_merge_unique(__source.__tree_);
766 }
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000767#endif
768
Howard Hinnant192cf032010-09-23 16:27:36 +0000769 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000770 void swap(set& __s) _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
771 {__tree_.swap(__s.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000772
Howard Hinnant192cf032010-09-23 16:27:36 +0000773 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000774 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000775 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000776 key_compare key_comp() const {return __tree_.value_comp();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000777 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000778 value_compare value_comp() const {return __tree_.value_comp();}
779
780 // set operations:
Howard Hinnant192cf032010-09-23 16:27:36 +0000781 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000782 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000783 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000784 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000785#if _LIBCPP_STD_VER > 11
786 template <typename _K2>
787 _LIBCPP_INLINE_VISIBILITY
788 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
789 find(const _K2& __k) {return __tree_.find(__k);}
790 template <typename _K2>
791 _LIBCPP_INLINE_VISIBILITY
792 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
793 find(const _K2& __k) const {return __tree_.find(__k);}
794#endif
795
Howard Hinnant192cf032010-09-23 16:27:36 +0000796 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000797 size_type count(const key_type& __k) const
798 {return __tree_.__count_unique(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +0000799#if _LIBCPP_STD_VER > 11
800 template <typename _K2>
801 _LIBCPP_INLINE_VISIBILITY
802 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +0000803 count(const _K2& __k) const {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +0000804#endif
Zoe Carver3ffbab12019-07-16 03:21:01 +0000805
806#if _LIBCPP_STD_VER > 17
807 _LIBCPP_INLINE_VISIBILITY
808 bool contains(const key_type& __k) const {return find(__k) != end();}
Marek Kurdejd7e019e2021-04-13 17:10:55 +0200809 template <typename _K2>
810 _LIBCPP_INLINE_VISIBILITY
811 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
812 contains(const _K2& __k) const { return find(__k) != end(); }
Zoe Carver3ffbab12019-07-16 03:21:01 +0000813#endif // _LIBCPP_STD_VER > 17
814
Howard Hinnant192cf032010-09-23 16:27:36 +0000815 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000816 iterator lower_bound(const key_type& __k)
817 {return __tree_.lower_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000818 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000819 const_iterator lower_bound(const key_type& __k) const
820 {return __tree_.lower_bound(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000821#if _LIBCPP_STD_VER > 11
822 template <typename _K2>
823 _LIBCPP_INLINE_VISIBILITY
824 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
825 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
826
827 template <typename _K2>
828 _LIBCPP_INLINE_VISIBILITY
829 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
830 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
831#endif
832
Howard Hinnant192cf032010-09-23 16:27:36 +0000833 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000834 iterator upper_bound(const key_type& __k)
835 {return __tree_.upper_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000836 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000837 const_iterator upper_bound(const key_type& __k) const
838 {return __tree_.upper_bound(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000839#if _LIBCPP_STD_VER > 11
840 template <typename _K2>
841 _LIBCPP_INLINE_VISIBILITY
842 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
843 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
844 template <typename _K2>
845 _LIBCPP_INLINE_VISIBILITY
846 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
847 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
848#endif
849
Howard Hinnant192cf032010-09-23 16:27:36 +0000850 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000851 pair<iterator,iterator> equal_range(const key_type& __k)
852 {return __tree_.__equal_range_unique(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000853 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000854 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
855 {return __tree_.__equal_range_unique(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000856#if _LIBCPP_STD_VER > 11
857 template <typename _K2>
858 _LIBCPP_INLINE_VISIBILITY
859 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +0000860 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000861 template <typename _K2>
862 _LIBCPP_INLINE_VISIBILITY
863 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +0000864 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000865#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000866};
867
Louis Dionne27ecc152019-06-11 18:21:08 +0000868#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
869template<class _InputIterator,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500870 class _Compare = less<__iter_value_type<_InputIterator>>,
871 class _Allocator = allocator<__iter_value_type<_InputIterator>>,
Louis Dionne6c7da9a2019-07-19 17:13:39 +0000872 class = _EnableIf<__is_allocator<_Allocator>::value, void>,
873 class = _EnableIf<!__is_allocator<_Compare>::value, void>>
Louis Dionne27ecc152019-06-11 18:21:08 +0000874set(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500875 -> set<__iter_value_type<_InputIterator>, _Compare, _Allocator>;
Louis Dionne27ecc152019-06-11 18:21:08 +0000876
877template<class _Key, class _Compare = less<_Key>,
878 class _Allocator = allocator<_Key>,
Louis Dionne6c7da9a2019-07-19 17:13:39 +0000879 class = _EnableIf<__is_allocator<_Allocator>::value, void>,
880 class = _EnableIf<!__is_allocator<_Compare>::value, void>>
Louis Dionne27ecc152019-06-11 18:21:08 +0000881set(initializer_list<_Key>, _Compare = _Compare(), _Allocator = _Allocator())
882 -> set<_Key, _Compare, _Allocator>;
883
884template<class _InputIterator, class _Allocator,
Louis Dionne6c7da9a2019-07-19 17:13:39 +0000885 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
Louis Dionne27ecc152019-06-11 18:21:08 +0000886set(_InputIterator, _InputIterator, _Allocator)
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500887 -> set<__iter_value_type<_InputIterator>,
888 less<__iter_value_type<_InputIterator>>, _Allocator>;
Louis Dionne27ecc152019-06-11 18:21:08 +0000889
890template<class _Key, class _Allocator,
Louis Dionne6c7da9a2019-07-19 17:13:39 +0000891 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
Louis Dionne27ecc152019-06-11 18:21:08 +0000892set(initializer_list<_Key>, _Allocator)
893 -> set<_Key, less<_Key>, _Allocator>;
894#endif
895
Eric Fiselier615961b2017-04-18 20:58:03 +0000896#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000897
898template <class _Key, class _Compare, class _Allocator>
899set<_Key, _Compare, _Allocator>::set(set&& __s, const allocator_type& __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000900 : __tree_(_VSTD::move(__s.__tree_), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000901{
902 if (__a != __s.get_allocator())
903 {
904 const_iterator __e = cend();
905 while (!__s.empty())
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000906 insert(__e, _VSTD::move(__s.__tree_.remove(__s.begin())->__value_));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000907 }
908}
909
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400910#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000911
912template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000913inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000914bool
915operator==(const set<_Key, _Compare, _Allocator>& __x,
916 const set<_Key, _Compare, _Allocator>& __y)
917{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000918 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000919}
920
921template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000922inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000923bool
924operator< (const set<_Key, _Compare, _Allocator>& __x,
925 const set<_Key, _Compare, _Allocator>& __y)
926{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000927 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000928}
929
930template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000931inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000932bool
933operator!=(const set<_Key, _Compare, _Allocator>& __x,
934 const set<_Key, _Compare, _Allocator>& __y)
935{
936 return !(__x == __y);
937}
938
939template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000940inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000941bool
942operator> (const set<_Key, _Compare, _Allocator>& __x,
943 const set<_Key, _Compare, _Allocator>& __y)
944{
945 return __y < __x;
946}
947
948template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000949inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000950bool
951operator>=(const set<_Key, _Compare, _Allocator>& __x,
952 const set<_Key, _Compare, _Allocator>& __y)
953{
954 return !(__x < __y);
955}
956
957template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000958inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000959bool
960operator<=(const set<_Key, _Compare, _Allocator>& __x,
961 const set<_Key, _Compare, _Allocator>& __y)
962{
963 return !(__y < __x);
964}
965
966// specialized algorithms:
967template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000968inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000969void
970swap(set<_Key, _Compare, _Allocator>& __x,
971 set<_Key, _Compare, _Allocator>& __y)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000972 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000973{
974 __x.swap(__y);
975}
976
Marshall Clow29b53f22018-12-14 18:49:35 +0000977#if _LIBCPP_STD_VER > 17
978template <class _Key, class _Compare, class _Allocator, class _Predicate>
979inline _LIBCPP_INLINE_VISIBILITY
Marek Kurdeja98b1412020-05-02 13:58:03 +0200980 typename set<_Key, _Compare, _Allocator>::size_type
981 erase_if(set<_Key, _Compare, _Allocator>& __c, _Predicate __pred) {
Arthur O'Dwyerb6738bd2021-03-21 16:53:09 -0400982 return _VSTD::__libcpp_erase_if_container(__c, __pred);
Marek Kurdeja98b1412020-05-02 13:58:03 +0200983}
Marshall Clow29b53f22018-12-14 18:49:35 +0000984#endif
985
Howard Hinnantc51e1022010-05-11 19:42:16 +0000986template <class _Key, class _Compare = less<_Key>,
987 class _Allocator = allocator<_Key> >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000988class _LIBCPP_TEMPLATE_VIS multiset
Howard Hinnantc51e1022010-05-11 19:42:16 +0000989{
990public:
991 // types:
Arthur O'Dwyer6a752e12021-03-03 11:10:49 -0500992 typedef _Key key_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000993 typedef key_type value_type;
Arthur O'Dwyer6a752e12021-03-03 11:10:49 -0500994 typedef _Compare key_compare;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000995 typedef key_compare value_compare;
Arthur O'Dwyer6a752e12021-03-03 11:10:49 -0500996 typedef __identity_t<_Allocator> allocator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000997 typedef value_type& reference;
998 typedef const value_type& const_reference;
999
Marshall Clow5128cf32015-11-26 01:24:04 +00001000 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
1001 "Allocator::value_type must be same type as value_type");
1002
Howard Hinnantc51e1022010-05-11 19:42:16 +00001003private:
1004 typedef __tree<value_type, value_compare, allocator_type> __base;
1005 typedef allocator_traits<allocator_type> __alloc_traits;
1006 typedef typename __base::__node_holder __node_holder;
1007
1008 __base __tree_;
1009
1010public:
1011 typedef typename __base::pointer pointer;
1012 typedef typename __base::const_pointer const_pointer;
1013 typedef typename __base::size_type size_type;
1014 typedef typename __base::difference_type difference_type;
1015 typedef typename __base::const_iterator iterator;
1016 typedef typename __base::const_iterator const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001017 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1018 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001019
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001020#if _LIBCPP_STD_VER > 14
1021 typedef __set_node_handle<typename __base::__node, allocator_type> node_type;
1022#endif
1023
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001024 template <class _Key2, class _Compare2, class _Alloc2>
1025 friend class _LIBCPP_TEMPLATE_VIS set;
1026 template <class _Key2, class _Compare2, class _Alloc2>
1027 friend class _LIBCPP_TEMPLATE_VIS multiset;
1028
Howard Hinnantc51e1022010-05-11 19:42:16 +00001029 // construct/copy/destroy:
Howard Hinnant192cf032010-09-23 16:27:36 +00001030 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +00001031 multiset()
1032 _NOEXCEPT_(
1033 is_nothrow_default_constructible<allocator_type>::value &&
1034 is_nothrow_default_constructible<key_compare>::value &&
1035 is_nothrow_copy_constructible<key_compare>::value)
1036 : __tree_(value_compare()) {}
1037
1038 _LIBCPP_INLINE_VISIBILITY
1039 explicit multiset(const value_compare& __comp)
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001040 _NOEXCEPT_(
1041 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001042 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001043 : __tree_(__comp) {}
Marshall Clow7086a5a2014-03-10 04:50:10 +00001044
Howard Hinnant192cf032010-09-23 16:27:36 +00001045 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7ed23a72014-03-05 19:06:20 +00001046 explicit multiset(const value_compare& __comp, const allocator_type& __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001047 : __tree_(__comp, __a) {}
1048 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001049 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001050 multiset(_InputIterator __f, _InputIterator __l,
1051 const value_compare& __comp = value_compare())
1052 : __tree_(__comp)
1053 {
1054 insert(__f, __l);
1055 }
1056
Marshall Clow631788a2013-09-11 00:06:45 +00001057#if _LIBCPP_STD_VER > 11
1058 template <class _InputIterator>
Louis Dionned2322c82018-11-01 14:41:37 +00001059 _LIBCPP_INLINE_VISIBILITY
Marshall Clow631788a2013-09-11 00:06:45 +00001060 multiset(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
1061 : multiset(__f, __l, key_compare(), __a) {}
1062#endif
1063
Howard Hinnantc51e1022010-05-11 19:42:16 +00001064 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001065 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001066 multiset(_InputIterator __f, _InputIterator __l,
1067 const value_compare& __comp, const allocator_type& __a)
1068 : __tree_(__comp, __a)
1069 {
1070 insert(__f, __l);
1071 }
1072
Howard Hinnant192cf032010-09-23 16:27:36 +00001073 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001074 multiset(const multiset& __s)
1075 : __tree_(__s.__tree_.value_comp(),
1076 __alloc_traits::select_on_container_copy_construction(__s.__tree_.__alloc()))
1077 {
1078 insert(__s.begin(), __s.end());
1079 }
1080
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001081 _LIBCPP_INLINE_VISIBILITY
1082 multiset& operator=(const multiset& __s)
1083 {
1084 __tree_ = __s.__tree_;
1085 return *this;
1086 }
1087
Eric Fiselier615961b2017-04-18 20:58:03 +00001088#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant192cf032010-09-23 16:27:36 +00001089 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001090 multiset(multiset&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001091 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001092 : __tree_(_VSTD::move(__s.__tree_)) {}
Eric Fiselier615961b2017-04-18 20:58:03 +00001093
1094 multiset(multiset&& __s, const allocator_type& __a);
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001095#endif // _LIBCPP_CXX03_LANG
Howard Hinnant192cf032010-09-23 16:27:36 +00001096 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001097 explicit multiset(const allocator_type& __a)
1098 : __tree_(__a) {}
Howard Hinnant192cf032010-09-23 16:27:36 +00001099 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001100 multiset(const multiset& __s, const allocator_type& __a)
1101 : __tree_(__s.__tree_.value_comp(), __a)
1102 {
1103 insert(__s.begin(), __s.end());
1104 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001105
Eric Fiselier615961b2017-04-18 20:58:03 +00001106#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant192cf032010-09-23 16:27:36 +00001107 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001108 multiset(initializer_list<value_type> __il, const value_compare& __comp = value_compare())
1109 : __tree_(__comp)
1110 {
1111 insert(__il.begin(), __il.end());
1112 }
1113
Howard Hinnant192cf032010-09-23 16:27:36 +00001114 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001115 multiset(initializer_list<value_type> __il, const value_compare& __comp,
1116 const allocator_type& __a)
1117 : __tree_(__comp, __a)
1118 {
1119 insert(__il.begin(), __il.end());
1120 }
1121
Marshall Clow631788a2013-09-11 00:06:45 +00001122#if _LIBCPP_STD_VER > 11
Louis Dionned2322c82018-11-01 14:41:37 +00001123 _LIBCPP_INLINE_VISIBILITY
Marshall Clow631788a2013-09-11 00:06:45 +00001124 multiset(initializer_list<value_type> __il, const allocator_type& __a)
1125 : multiset(__il, key_compare(), __a) {}
1126#endif
1127
Howard Hinnant192cf032010-09-23 16:27:36 +00001128 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001129 multiset& operator=(initializer_list<value_type> __il)
1130 {
1131 __tree_.__assign_multi(__il.begin(), __il.end());
1132 return *this;
1133 }
1134
Howard Hinnant192cf032010-09-23 16:27:36 +00001135 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001136 multiset& operator=(multiset&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001137 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001138 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001139 __tree_ = _VSTD::move(__s.__tree_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001140 return *this;
1141 }
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001142#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001143
Howard Hinnant192cf032010-09-23 16:27:36 +00001144 _LIBCPP_INLINE_VISIBILITY
Louis Dionne69c42c02019-04-11 16:14:56 +00001145 ~multiset() {
1146 static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), "");
1147 }
1148
1149 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001150 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001151 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001152 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001153 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001154 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001155 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001156 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001157
Howard Hinnant192cf032010-09-23 16:27:36 +00001158 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001159 reverse_iterator rbegin() _NOEXCEPT
1160 {return reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +00001161 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001162 const_reverse_iterator rbegin() const _NOEXCEPT
1163 {return const_reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +00001164 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001165 reverse_iterator rend() _NOEXCEPT
1166 {return reverse_iterator(begin());}
Howard Hinnant192cf032010-09-23 16:27:36 +00001167 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001168 const_reverse_iterator rend() const _NOEXCEPT
1169 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001170
Howard Hinnant192cf032010-09-23 16:27:36 +00001171 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001172 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001173 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001174 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001175 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001176 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001177 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001178 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001179
Marshall Clow425f5752017-11-15 05:51:26 +00001180 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001181 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant192cf032010-09-23 16:27:36 +00001182 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001183 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001184 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001185 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001186
1187 // modifiers:
Eric Fiselier615961b2017-04-18 20:58:03 +00001188#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001189 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +00001190 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001191 iterator emplace(_Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001192 {return __tree_.__emplace_multi(_VSTD::forward<_Args>(__args)...);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001193 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +00001194 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001195 iterator emplace_hint(const_iterator __p, _Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001196 {return __tree_.__emplace_hint_multi(__p, _VSTD::forward<_Args>(__args)...);}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001197#endif // _LIBCPP_CXX03_LANG
Eric Fiselier615961b2017-04-18 20:58:03 +00001198
Howard Hinnant192cf032010-09-23 16:27:36 +00001199 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001200 iterator insert(const value_type& __v)
1201 {return __tree_.__insert_multi(__v);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001202 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001203 iterator insert(const_iterator __p, const value_type& __v)
1204 {return __tree_.__insert_multi(__p, __v);}
Eric Fiselier615961b2017-04-18 20:58:03 +00001205
Howard Hinnantc51e1022010-05-11 19:42:16 +00001206 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001207 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001208 void insert(_InputIterator __f, _InputIterator __l)
1209 {
1210 for (const_iterator __e = cend(); __f != __l; ++__f)
1211 __tree_.__insert_multi(__e, *__f);
1212 }
1213
Eric Fiselier615961b2017-04-18 20:58:03 +00001214#ifndef _LIBCPP_CXX03_LANG
1215 _LIBCPP_INLINE_VISIBILITY
1216 iterator insert(value_type&& __v)
1217 {return __tree_.__insert_multi(_VSTD::move(__v));}
1218
1219 _LIBCPP_INLINE_VISIBILITY
1220 iterator insert(const_iterator __p, value_type&& __v)
1221 {return __tree_.__insert_multi(__p, _VSTD::move(__v));}
1222
Howard Hinnant192cf032010-09-23 16:27:36 +00001223 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001224 void insert(initializer_list<value_type> __il)
1225 {insert(__il.begin(), __il.end());}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001226#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001227
Howard Hinnant192cf032010-09-23 16:27:36 +00001228 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001229 iterator erase(const_iterator __p) {return __tree_.erase(__p);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001230 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001231 size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001232 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001233 iterator erase(const_iterator __f, const_iterator __l)
1234 {return __tree_.erase(__f, __l);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001235 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001236 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001237
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001238#if _LIBCPP_STD_VER > 14
1239 _LIBCPP_INLINE_VISIBILITY
1240 iterator insert(node_type&& __nh)
1241 {
1242 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1243 "node_type with incompatible allocator passed to multiset::insert()");
1244 return __tree_.template __node_handle_insert_multi<node_type>(
1245 _VSTD::move(__nh));
1246 }
1247 _LIBCPP_INLINE_VISIBILITY
1248 iterator insert(const_iterator __hint, node_type&& __nh)
1249 {
1250 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1251 "node_type with incompatible allocator passed to multiset::insert()");
1252 return __tree_.template __node_handle_insert_multi<node_type>(
1253 __hint, _VSTD::move(__nh));
1254 }
1255 _LIBCPP_INLINE_VISIBILITY
1256 node_type extract(key_type const& __key)
1257 {
1258 return __tree_.template __node_handle_extract<node_type>(__key);
1259 }
1260 _LIBCPP_INLINE_VISIBILITY
1261 node_type extract(const_iterator __it)
1262 {
1263 return __tree_.template __node_handle_extract<node_type>(__it);
1264 }
Louis Dionned2322c82018-11-01 14:41:37 +00001265 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001266 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001267 void merge(multiset<key_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001268 {
1269 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1270 "merging container with incompatible allocator");
1271 __tree_.__node_handle_merge_multi(__source.__tree_);
1272 }
Louis Dionned2322c82018-11-01 14:41:37 +00001273 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001274 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001275 void merge(multiset<key_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001276 {
1277 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1278 "merging container with incompatible allocator");
1279 __tree_.__node_handle_merge_multi(__source.__tree_);
1280 }
Louis Dionned2322c82018-11-01 14:41:37 +00001281 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001282 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001283 void merge(set<key_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001284 {
1285 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1286 "merging container with incompatible allocator");
1287 __tree_.__node_handle_merge_multi(__source.__tree_);
1288 }
Louis Dionned2322c82018-11-01 14:41:37 +00001289 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001290 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001291 void merge(set<key_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001292 {
1293 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1294 "merging container with incompatible allocator");
1295 __tree_.__node_handle_merge_multi(__source.__tree_);
1296 }
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001297#endif
1298
Howard Hinnant192cf032010-09-23 16:27:36 +00001299 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001300 void swap(multiset& __s)
1301 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1302 {__tree_.swap(__s.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001303
Howard Hinnant192cf032010-09-23 16:27:36 +00001304 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001305 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001306 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001307 key_compare key_comp() const {return __tree_.value_comp();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001308 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001309 value_compare value_comp() const {return __tree_.value_comp();}
1310
1311 // set operations:
Howard Hinnant192cf032010-09-23 16:27:36 +00001312 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001313 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001314 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001315 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +00001316#if _LIBCPP_STD_VER > 11
1317 template <typename _K2>
1318 _LIBCPP_INLINE_VISIBILITY
1319 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,iterator>::type
1320 find(const _K2& __k) {return __tree_.find(__k);}
1321 template <typename _K2>
1322 _LIBCPP_INLINE_VISIBILITY
1323 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,const_iterator>::type
1324 find(const _K2& __k) const {return __tree_.find(__k);}
1325#endif
1326
Howard Hinnant192cf032010-09-23 16:27:36 +00001327 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001328 size_type count(const key_type& __k) const
1329 {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001330#if _LIBCPP_STD_VER > 11
1331 template <typename _K2>
1332 _LIBCPP_INLINE_VISIBILITY
1333 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
Marshall Clow5571bcd2018-01-07 17:39:57 +00001334 count(const _K2& __k) const {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001335#endif
Marshall Clowc0152142013-08-13 01:11:06 +00001336
Zoe Carver3ffbab12019-07-16 03:21:01 +00001337#if _LIBCPP_STD_VER > 17
1338 _LIBCPP_INLINE_VISIBILITY
1339 bool contains(const key_type& __k) const {return find(__k) != end();}
Marek Kurdejd7e019e2021-04-13 17:10:55 +02001340 template <typename _K2>
1341 _LIBCPP_INLINE_VISIBILITY
1342 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
1343 contains(const _K2& __k) const { return find(__k) != end(); }
Zoe Carver3ffbab12019-07-16 03:21:01 +00001344#endif // _LIBCPP_STD_VER > 17
1345
Howard Hinnant192cf032010-09-23 16:27:36 +00001346 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001347 iterator lower_bound(const key_type& __k)
1348 {return __tree_.lower_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001349 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001350 const_iterator lower_bound(const key_type& __k) const
1351 {return __tree_.lower_bound(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +00001352#if _LIBCPP_STD_VER > 11
1353 template <typename _K2>
1354 _LIBCPP_INLINE_VISIBILITY
1355 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,iterator>::type
1356 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
1357
1358 template <typename _K2>
1359 _LIBCPP_INLINE_VISIBILITY
1360 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,const_iterator>::type
1361 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
1362#endif
1363
Howard Hinnant192cf032010-09-23 16:27:36 +00001364 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001365 iterator upper_bound(const key_type& __k)
1366 {return __tree_.upper_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001367 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001368 const_iterator upper_bound(const key_type& __k) const
1369 {return __tree_.upper_bound(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +00001370#if _LIBCPP_STD_VER > 11
1371 template <typename _K2>
1372 _LIBCPP_INLINE_VISIBILITY
1373 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,iterator>::type
1374 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
1375 template <typename _K2>
1376 _LIBCPP_INLINE_VISIBILITY
1377 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,const_iterator>::type
1378 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
1379#endif
1380
Howard Hinnant192cf032010-09-23 16:27:36 +00001381 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001382 pair<iterator,iterator> equal_range(const key_type& __k)
1383 {return __tree_.__equal_range_multi(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001384 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001385 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
1386 {return __tree_.__equal_range_multi(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +00001387#if _LIBCPP_STD_VER > 11
1388 template <typename _K2>
1389 _LIBCPP_INLINE_VISIBILITY
1390 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
1391 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
1392 template <typename _K2>
1393 _LIBCPP_INLINE_VISIBILITY
1394 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
1395 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
1396#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001397};
1398
Louis Dionne27ecc152019-06-11 18:21:08 +00001399#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
1400template<class _InputIterator,
Arthur O'Dwyer56226762021-03-03 23:02:20 -05001401 class _Compare = less<__iter_value_type<_InputIterator>>,
1402 class _Allocator = allocator<__iter_value_type<_InputIterator>>,
Louis Dionne6c7da9a2019-07-19 17:13:39 +00001403 class = _EnableIf<__is_allocator<_Allocator>::value, void>,
1404 class = _EnableIf<!__is_allocator<_Compare>::value, void>>
Louis Dionne27ecc152019-06-11 18:21:08 +00001405multiset(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
Arthur O'Dwyer56226762021-03-03 23:02:20 -05001406 -> multiset<__iter_value_type<_InputIterator>, _Compare, _Allocator>;
Louis Dionne27ecc152019-06-11 18:21:08 +00001407
1408template<class _Key, class _Compare = less<_Key>,
1409 class _Allocator = allocator<_Key>,
Louis Dionne6c7da9a2019-07-19 17:13:39 +00001410 class = _EnableIf<__is_allocator<_Allocator>::value, void>,
1411 class = _EnableIf<!__is_allocator<_Compare>::value, void>>
Louis Dionne27ecc152019-06-11 18:21:08 +00001412multiset(initializer_list<_Key>, _Compare = _Compare(), _Allocator = _Allocator())
1413 -> multiset<_Key, _Compare, _Allocator>;
1414
1415template<class _InputIterator, class _Allocator,
Louis Dionne6c7da9a2019-07-19 17:13:39 +00001416 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
Louis Dionne27ecc152019-06-11 18:21:08 +00001417multiset(_InputIterator, _InputIterator, _Allocator)
Arthur O'Dwyer56226762021-03-03 23:02:20 -05001418 -> multiset<__iter_value_type<_InputIterator>,
1419 less<__iter_value_type<_InputIterator>>, _Allocator>;
Louis Dionne27ecc152019-06-11 18:21:08 +00001420
1421template<class _Key, class _Allocator,
Louis Dionne6c7da9a2019-07-19 17:13:39 +00001422 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
Louis Dionne27ecc152019-06-11 18:21:08 +00001423multiset(initializer_list<_Key>, _Allocator)
1424 -> multiset<_Key, less<_Key>, _Allocator>;
1425#endif
1426
Eric Fiselier615961b2017-04-18 20:58:03 +00001427#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001428
1429template <class _Key, class _Compare, class _Allocator>
1430multiset<_Key, _Compare, _Allocator>::multiset(multiset&& __s, const allocator_type& __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001431 : __tree_(_VSTD::move(__s.__tree_), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001432{
1433 if (__a != __s.get_allocator())
1434 {
1435 const_iterator __e = cend();
1436 while (!__s.empty())
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001437 insert(__e, _VSTD::move(__s.__tree_.remove(__s.begin())->__value_));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001438 }
1439}
1440
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001441#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001442
1443template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001444inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001445bool
1446operator==(const multiset<_Key, _Compare, _Allocator>& __x,
1447 const multiset<_Key, _Compare, _Allocator>& __y)
1448{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001449 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001450}
1451
1452template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001453inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001454bool
1455operator< (const multiset<_Key, _Compare, _Allocator>& __x,
1456 const multiset<_Key, _Compare, _Allocator>& __y)
1457{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001458 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001459}
1460
1461template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001462inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001463bool
1464operator!=(const multiset<_Key, _Compare, _Allocator>& __x,
1465 const multiset<_Key, _Compare, _Allocator>& __y)
1466{
1467 return !(__x == __y);
1468}
1469
1470template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001471inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001472bool
1473operator> (const multiset<_Key, _Compare, _Allocator>& __x,
1474 const multiset<_Key, _Compare, _Allocator>& __y)
1475{
1476 return __y < __x;
1477}
1478
1479template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001480inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001481bool
1482operator>=(const multiset<_Key, _Compare, _Allocator>& __x,
1483 const multiset<_Key, _Compare, _Allocator>& __y)
1484{
1485 return !(__x < __y);
1486}
1487
1488template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001489inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001490bool
1491operator<=(const multiset<_Key, _Compare, _Allocator>& __x,
1492 const multiset<_Key, _Compare, _Allocator>& __y)
1493{
1494 return !(__y < __x);
1495}
1496
1497template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001498inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001499void
1500swap(multiset<_Key, _Compare, _Allocator>& __x,
1501 multiset<_Key, _Compare, _Allocator>& __y)
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001502 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001503{
1504 __x.swap(__y);
1505}
1506
Marshall Clow29b53f22018-12-14 18:49:35 +00001507#if _LIBCPP_STD_VER > 17
1508template <class _Key, class _Compare, class _Allocator, class _Predicate>
1509inline _LIBCPP_INLINE_VISIBILITY
Marek Kurdeja98b1412020-05-02 13:58:03 +02001510 typename multiset<_Key, _Compare, _Allocator>::size_type
1511 erase_if(multiset<_Key, _Compare, _Allocator>& __c, _Predicate __pred) {
Arthur O'Dwyerb6738bd2021-03-21 16:53:09 -04001512 return _VSTD::__libcpp_erase_if_container(__c, __pred);
Marek Kurdeja98b1412020-05-02 13:58:03 +02001513}
Marshall Clow29b53f22018-12-14 18:49:35 +00001514#endif
1515
Howard Hinnantc51e1022010-05-11 19:42:16 +00001516_LIBCPP_END_NAMESPACE_STD
1517
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001518#endif // _LIBCPP_SET