blob: a5cf39995f2dada35b0454f186ef25ab2516572a [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===---------------------------- set -------------------------------------===//
3//
Chandler Carruthd2012102019-01-19 10:56:40 +00004// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Howard Hinnantc51e1022010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_SET
11#define _LIBCPP_SET
12
13/*
14
15 set synopsis
16
17namespace std
18{
19
20template <class Key, class Compare = less<Key>,
21 class Allocator = allocator<Key>>
22class set
23{
24public:
25 // types:
26 typedef Key key_type;
27 typedef key_type value_type;
28 typedef Compare key_compare;
29 typedef key_compare value_compare;
30 typedef Allocator allocator_type;
31 typedef typename allocator_type::reference reference;
32 typedef typename allocator_type::const_reference const_reference;
33 typedef typename allocator_type::size_type size_type;
34 typedef typename allocator_type::difference_type difference_type;
35 typedef typename allocator_type::pointer pointer;
36 typedef typename allocator_type::const_pointer const_pointer;
37
38 typedef implementation-defined iterator;
39 typedef implementation-defined const_iterator;
40 typedef std::reverse_iterator<iterator> reverse_iterator;
41 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +000042 typedef unspecified node_type; // C++17
43 typedef INSERT_RETURN_TYPE<iterator, node_type> insert_return_type; // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +000044
45 // construct/copy/destroy:
Howard Hinnantf95f4f52011-06-04 15:22:34 +000046 set()
47 noexcept(
48 is_nothrow_default_constructible<allocator_type>::value &&
49 is_nothrow_default_constructible<key_compare>::value &&
50 is_nothrow_copy_constructible<key_compare>::value);
51 explicit set(const value_compare& comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +000052 set(const value_compare& comp, const allocator_type& a);
53 template <class InputIterator>
54 set(InputIterator first, InputIterator last,
55 const value_compare& comp = value_compare());
56 template <class InputIterator>
57 set(InputIterator first, InputIterator last, const value_compare& comp,
58 const allocator_type& a);
59 set(const set& s);
Howard Hinnantf95f4f52011-06-04 15:22:34 +000060 set(set&& s)
61 noexcept(
62 is_nothrow_move_constructible<allocator_type>::value &&
63 is_nothrow_move_constructible<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +000064 explicit set(const allocator_type& a);
65 set(const set& s, const allocator_type& a);
66 set(set&& s, const allocator_type& a);
67 set(initializer_list<value_type> il, const value_compare& comp = value_compare());
68 set(initializer_list<value_type> il, const value_compare& comp,
69 const allocator_type& a);
Marshall Clow631788a2013-09-11 00:06:45 +000070 template <class InputIterator>
71 set(InputIterator first, InputIterator last, const allocator_type& a)
72 : set(first, last, Compare(), a) {} // C++14
73 set(initializer_list<value_type> il, const allocator_type& a)
74 : set(il, Compare(), a) {} // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000075 ~set();
76
77 set& operator=(const set& s);
Howard Hinnantf95f4f52011-06-04 15:22:34 +000078 set& operator=(set&& s)
79 noexcept(
80 allocator_type::propagate_on_container_move_assignment::value &&
81 is_nothrow_move_assignable<allocator_type>::value &&
82 is_nothrow_move_assignable<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +000083 set& operator=(initializer_list<value_type> il);
84
85 // iterators:
Howard Hinnantf95f4f52011-06-04 15:22:34 +000086 iterator begin() noexcept;
87 const_iterator begin() const noexcept;
88 iterator end() noexcept;
89 const_iterator end() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000090
Howard Hinnantf95f4f52011-06-04 15:22:34 +000091 reverse_iterator rbegin() noexcept;
92 const_reverse_iterator rbegin() const noexcept;
93 reverse_iterator rend() noexcept;
94 const_reverse_iterator rend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000095
Howard Hinnantf95f4f52011-06-04 15:22:34 +000096 const_iterator cbegin() const noexcept;
97 const_iterator cend() const noexcept;
98 const_reverse_iterator crbegin() const noexcept;
99 const_reverse_iterator crend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000100
101 // capacity:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000102 bool empty() const noexcept;
103 size_type size() const noexcept;
104 size_type max_size() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000105
106 // modifiers:
107 template <class... Args>
108 pair<iterator, bool> emplace(Args&&... args);
109 template <class... Args>
110 iterator emplace_hint(const_iterator position, Args&&... args);
111 pair<iterator,bool> insert(const value_type& v);
112 pair<iterator,bool> insert(value_type&& v);
113 iterator insert(const_iterator position, const value_type& v);
114 iterator insert(const_iterator position, value_type&& v);
115 template <class InputIterator>
116 void insert(InputIterator first, InputIterator last);
117 void insert(initializer_list<value_type> il);
118
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000119 node_type extract(const_iterator position); // C++17
120 node_type extract(const key_type& x); // C++17
121 insert_return_type insert(node_type&& nh); // C++17
122 iterator insert(const_iterator hint, node_type&& nh); // C++17
123
Howard Hinnantc51e1022010-05-11 19:42:16 +0000124 iterator erase(const_iterator position);
Marshall Clow22ea5b82015-05-10 13:35:00 +0000125 iterator erase(iterator position); // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000126 size_type erase(const key_type& k);
127 iterator erase(const_iterator first, const_iterator last);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000128 void clear() noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000129
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000130 template<class C2>
131 void merge(set<Key, C2, Allocator>& source); // C++17
132 template<class C2>
133 void merge(set<Key, C2, Allocator>&& source); // C++17
134 template<class C2>
135 void merge(multiset<Key, C2, Allocator>& source); // C++17
136 template<class C2>
137 void merge(multiset<Key, C2, Allocator>&& source); // C++17
138
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000139 void swap(set& s)
140 noexcept(
141 __is_nothrow_swappable<key_compare>::value &&
142 (!allocator_type::propagate_on_container_swap::value ||
143 __is_nothrow_swappable<allocator_type>::value));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000144
145 // observers:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000146 allocator_type get_allocator() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000147 key_compare key_comp() const;
148 value_compare value_comp() const;
149
150 // set operations:
151 iterator find(const key_type& k);
152 const_iterator find(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000153 template<typename K>
154 iterator find(const K& x);
155 template<typename K>
156 const_iterator find(const K& x) const; // C++14
157 template<typename K>
Zoe Carver3ffbab12019-07-16 03:21:01 +0000158 size_type count(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000159 size_type count(const key_type& k) const;
Zoe Carver3ffbab12019-07-16 03:21:01 +0000160 bool contains(const key_type& x) const; // C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000161 iterator lower_bound(const key_type& k);
162 const_iterator lower_bound(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000163 template<typename K>
164 iterator lower_bound(const K& x); // C++14
165 template<typename K>
166 const_iterator lower_bound(const K& x) const; // C++14
167
Howard Hinnantc51e1022010-05-11 19:42:16 +0000168 iterator upper_bound(const key_type& k);
169 const_iterator upper_bound(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000170 template<typename K>
171 iterator upper_bound(const K& x); // C++14
172 template<typename K>
173 const_iterator upper_bound(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000174 pair<iterator,iterator> equal_range(const key_type& k);
175 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000176 template<typename K>
177 pair<iterator,iterator> equal_range(const K& x); // C++14
178 template<typename K>
179 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000180};
181
182template <class Key, class Compare, class Allocator>
183bool
184operator==(const set<Key, Compare, Allocator>& x,
185 const set<Key, Compare, Allocator>& y);
186
187template <class Key, class Compare, class Allocator>
188bool
189operator< (const set<Key, Compare, Allocator>& x,
190 const set<Key, Compare, Allocator>& y);
191
192template <class Key, class Compare, class Allocator>
193bool
194operator!=(const set<Key, Compare, Allocator>& x,
195 const set<Key, Compare, Allocator>& y);
196
197template <class Key, class Compare, class Allocator>
198bool
199operator> (const set<Key, Compare, Allocator>& x,
200 const set<Key, Compare, Allocator>& y);
201
202template <class Key, class Compare, class Allocator>
203bool
204operator>=(const set<Key, Compare, Allocator>& x,
205 const set<Key, Compare, Allocator>& y);
206
207template <class Key, class Compare, class Allocator>
208bool
209operator<=(const set<Key, Compare, Allocator>& x,
210 const set<Key, Compare, Allocator>& y);
211
212// specialized algorithms:
213template <class Key, class Compare, class Allocator>
214void
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000215swap(set<Key, Compare, Allocator>& x, set<Key, Compare, Allocator>& y)
216 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000217
Marshall Clow29b53f22018-12-14 18:49:35 +0000218template <class Key, class Compare, class Allocator, class Predicate>
Marek Kurdeja98b1412020-05-02 13:58:03 +0200219typename set<Key, Compare, Allocator>::size_type
220erase_if(set<Key, Compare, Allocator>& c, Predicate pred); // C++20
Marshall Clow29b53f22018-12-14 18:49:35 +0000221
Howard Hinnantc51e1022010-05-11 19:42:16 +0000222template <class Key, class Compare = less<Key>,
223 class Allocator = allocator<Key>>
224class multiset
225{
226public:
227 // types:
228 typedef Key key_type;
229 typedef key_type value_type;
230 typedef Compare key_compare;
231 typedef key_compare value_compare;
232 typedef Allocator allocator_type;
233 typedef typename allocator_type::reference reference;
234 typedef typename allocator_type::const_reference const_reference;
235 typedef typename allocator_type::size_type size_type;
236 typedef typename allocator_type::difference_type difference_type;
237 typedef typename allocator_type::pointer pointer;
238 typedef typename allocator_type::const_pointer const_pointer;
239
240 typedef implementation-defined iterator;
241 typedef implementation-defined const_iterator;
242 typedef std::reverse_iterator<iterator> reverse_iterator;
243 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000244 typedef unspecified node_type; // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000245
246 // construct/copy/destroy:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000247 multiset()
248 noexcept(
249 is_nothrow_default_constructible<allocator_type>::value &&
250 is_nothrow_default_constructible<key_compare>::value &&
251 is_nothrow_copy_constructible<key_compare>::value);
252 explicit multiset(const value_compare& comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000253 multiset(const value_compare& comp, const allocator_type& a);
254 template <class InputIterator>
255 multiset(InputIterator first, InputIterator last,
256 const value_compare& comp = value_compare());
257 template <class InputIterator>
258 multiset(InputIterator first, InputIterator last,
259 const value_compare& comp, const allocator_type& a);
260 multiset(const multiset& s);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000261 multiset(multiset&& s)
262 noexcept(
263 is_nothrow_move_constructible<allocator_type>::value &&
264 is_nothrow_move_constructible<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000265 explicit multiset(const allocator_type& a);
266 multiset(const multiset& s, const allocator_type& a);
267 multiset(multiset&& s, const allocator_type& a);
268 multiset(initializer_list<value_type> il, const value_compare& comp = value_compare());
269 multiset(initializer_list<value_type> il, const value_compare& comp,
270 const allocator_type& a);
Marshall Clow631788a2013-09-11 00:06:45 +0000271 template <class InputIterator>
272 multiset(InputIterator first, InputIterator last, const allocator_type& a)
273 : set(first, last, Compare(), a) {} // C++14
274 multiset(initializer_list<value_type> il, const allocator_type& a)
275 : set(il, Compare(), a) {} // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000276 ~multiset();
277
278 multiset& operator=(const multiset& s);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000279 multiset& operator=(multiset&& s)
280 noexcept(
281 allocator_type::propagate_on_container_move_assignment::value &&
282 is_nothrow_move_assignable<allocator_type>::value &&
283 is_nothrow_move_assignable<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000284 multiset& operator=(initializer_list<value_type> il);
285
286 // iterators:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000287 iterator begin() noexcept;
288 const_iterator begin() const noexcept;
289 iterator end() noexcept;
290 const_iterator end() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000291
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000292 reverse_iterator rbegin() noexcept;
293 const_reverse_iterator rbegin() const noexcept;
294 reverse_iterator rend() noexcept;
295 const_reverse_iterator rend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000296
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000297 const_iterator cbegin() const noexcept;
298 const_iterator cend() const noexcept;
299 const_reverse_iterator crbegin() const noexcept;
300 const_reverse_iterator crend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000301
302 // capacity:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000303 bool empty() const noexcept;
304 size_type size() const noexcept;
305 size_type max_size() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000306
307 // modifiers:
308 template <class... Args>
309 iterator emplace(Args&&... args);
310 template <class... Args>
311 iterator emplace_hint(const_iterator position, Args&&... args);
312 iterator insert(const value_type& v);
313 iterator insert(value_type&& v);
314 iterator insert(const_iterator position, const value_type& v);
315 iterator insert(const_iterator position, value_type&& v);
316 template <class InputIterator>
317 void insert(InputIterator first, InputIterator last);
318 void insert(initializer_list<value_type> il);
319
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000320 node_type extract(const_iterator position); // C++17
321 node_type extract(const key_type& x); // C++17
322 iterator insert(node_type&& nh); // C++17
323 iterator insert(const_iterator hint, node_type&& nh); // C++17
324
Howard Hinnantc51e1022010-05-11 19:42:16 +0000325 iterator erase(const_iterator position);
Marshall Clow22ea5b82015-05-10 13:35:00 +0000326 iterator erase(iterator position); // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000327 size_type erase(const key_type& k);
328 iterator erase(const_iterator first, const_iterator last);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000329 void clear() noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000330
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000331 template<class C2>
332 void merge(multiset<Key, C2, Allocator>& source); // C++17
333 template<class C2>
334 void merge(multiset<Key, C2, Allocator>&& source); // C++17
335 template<class C2>
336 void merge(set<Key, C2, Allocator>& source); // C++17
337 template<class C2>
338 void merge(set<Key, C2, Allocator>&& source); // C++17
339
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000340 void swap(multiset& s)
341 noexcept(
342 __is_nothrow_swappable<key_compare>::value &&
343 (!allocator_type::propagate_on_container_swap::value ||
344 __is_nothrow_swappable<allocator_type>::value));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000345
346 // observers:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000347 allocator_type get_allocator() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000348 key_compare key_comp() const;
349 value_compare value_comp() const;
350
351 // set operations:
352 iterator find(const key_type& k);
353 const_iterator find(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000354 template<typename K>
355 iterator find(const K& x);
356 template<typename K>
357 const_iterator find(const K& x) const; // C++14
Zoe Carver3ffbab12019-07-16 03:21:01 +0000358 template<typename K>
359 size_type count(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000360 size_type count(const key_type& k) const;
Zoe Carver3ffbab12019-07-16 03:21:01 +0000361 bool contains(const key_type& x) const; // C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000362 iterator lower_bound(const key_type& k);
363 const_iterator lower_bound(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000364 template<typename K>
365 iterator lower_bound(const K& x); // C++14
366 template<typename K>
367 const_iterator lower_bound(const K& x) const; // C++14
368
Howard Hinnantc51e1022010-05-11 19:42:16 +0000369 iterator upper_bound(const key_type& k);
370 const_iterator upper_bound(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000371 template<typename K>
372 iterator upper_bound(const K& x); // C++14
373 template<typename K>
374 const_iterator upper_bound(const K& x) const; // C++14
375
Howard Hinnantc51e1022010-05-11 19:42:16 +0000376 pair<iterator,iterator> equal_range(const key_type& k);
377 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000378 template<typename K>
379 pair<iterator,iterator> equal_range(const K& x); // C++14
380 template<typename K>
381 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000382};
383
384template <class Key, class Compare, class Allocator>
385bool
386operator==(const multiset<Key, Compare, Allocator>& x,
387 const multiset<Key, Compare, Allocator>& y);
388
389template <class Key, class Compare, class Allocator>
390bool
391operator< (const multiset<Key, Compare, Allocator>& x,
392 const multiset<Key, Compare, Allocator>& y);
393
394template <class Key, class Compare, class Allocator>
395bool
396operator!=(const multiset<Key, Compare, Allocator>& x,
397 const multiset<Key, Compare, Allocator>& y);
398
399template <class Key, class Compare, class Allocator>
400bool
401operator> (const multiset<Key, Compare, Allocator>& x,
402 const multiset<Key, Compare, Allocator>& y);
403
404template <class Key, class Compare, class Allocator>
405bool
406operator>=(const multiset<Key, Compare, Allocator>& x,
407 const multiset<Key, Compare, Allocator>& y);
408
409template <class Key, class Compare, class Allocator>
410bool
411operator<=(const multiset<Key, Compare, Allocator>& x,
412 const multiset<Key, Compare, Allocator>& y);
413
414// specialized algorithms:
415template <class Key, class Compare, class Allocator>
416void
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000417swap(multiset<Key, Compare, Allocator>& x, multiset<Key, Compare, Allocator>& y)
418 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000419
Marshall Clow29b53f22018-12-14 18:49:35 +0000420template <class Key, class Compare, class Allocator, class Predicate>
Marek Kurdeja98b1412020-05-02 13:58:03 +0200421typename multiset<Key, Compare, Allocator>::size_type
422erase_if(multiset<Key, Compare, Allocator>& c, Predicate pred); // C++20
Marshall Clow29b53f22018-12-14 18:49:35 +0000423
Howard Hinnantc51e1022010-05-11 19:42:16 +0000424} // std
425
426*/
427
428#include <__config>
429#include <__tree>
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000430#include <__node_handle>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000431#include <functional>
Arthur O'Dwyerb6738bd2021-03-21 16:53:09 -0400432#include <iterator> // __libcpp_erase_if_container
Marshall Clow0a1e7502018-09-12 19:41:40 +0000433#include <version>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000434
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000435#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000436#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000437#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000438
439_LIBCPP_BEGIN_NAMESPACE_STD
440
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000441template <class _Key, class _Compare, class _Allocator>
442class multiset;
443
Howard Hinnantc51e1022010-05-11 19:42:16 +0000444template <class _Key, class _Compare = less<_Key>,
445 class _Allocator = allocator<_Key> >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000446class _LIBCPP_TEMPLATE_VIS set
Howard Hinnantc51e1022010-05-11 19:42:16 +0000447{
448public:
449 // types:
450 typedef _Key key_type;
451 typedef key_type value_type;
452 typedef _Compare key_compare;
453 typedef key_compare value_compare;
Arthur O'Dwyer6a752e12021-03-03 11:10:49 -0500454 typedef __identity_t<_Allocator> allocator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000455 typedef value_type& reference;
456 typedef const value_type& const_reference;
457
Marshall Clow5128cf32015-11-26 01:24:04 +0000458 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
459 "Allocator::value_type must be same type as value_type");
460
Howard Hinnantc51e1022010-05-11 19:42:16 +0000461private:
462 typedef __tree<value_type, value_compare, allocator_type> __base;
463 typedef allocator_traits<allocator_type> __alloc_traits;
464 typedef typename __base::__node_holder __node_holder;
465
466 __base __tree_;
467
468public:
469 typedef typename __base::pointer pointer;
470 typedef typename __base::const_pointer const_pointer;
471 typedef typename __base::size_type size_type;
472 typedef typename __base::difference_type difference_type;
473 typedef typename __base::const_iterator iterator;
474 typedef typename __base::const_iterator const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000475 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
476 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000477
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000478#if _LIBCPP_STD_VER > 14
479 typedef __set_node_handle<typename __base::__node, allocator_type> node_type;
480 typedef __insert_return_type<iterator, node_type> insert_return_type;
481#endif
482
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000483 template <class _Key2, class _Compare2, class _Alloc2>
484 friend class _LIBCPP_TEMPLATE_VIS set;
485 template <class _Key2, class _Compare2, class _Alloc2>
486 friend class _LIBCPP_TEMPLATE_VIS multiset;
487
Howard Hinnant192cf032010-09-23 16:27:36 +0000488 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +0000489 set()
490 _NOEXCEPT_(
491 is_nothrow_default_constructible<allocator_type>::value &&
492 is_nothrow_default_constructible<key_compare>::value &&
493 is_nothrow_copy_constructible<key_compare>::value)
494 : __tree_(value_compare()) {}
495
496 _LIBCPP_INLINE_VISIBILITY
497 explicit set(const value_compare& __comp)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000498 _NOEXCEPT_(
499 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000500 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000501 : __tree_(__comp) {}
Marshall Clow7086a5a2014-03-10 04:50:10 +0000502
Howard Hinnant192cf032010-09-23 16:27:36 +0000503 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7ed23a72014-03-05 19:06:20 +0000504 explicit set(const value_compare& __comp, const allocator_type& __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000505 : __tree_(__comp, __a) {}
506 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000507 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000508 set(_InputIterator __f, _InputIterator __l,
509 const value_compare& __comp = value_compare())
510 : __tree_(__comp)
511 {
512 insert(__f, __l);
513 }
514
515 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000516 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000517 set(_InputIterator __f, _InputIterator __l, const value_compare& __comp,
518 const allocator_type& __a)
519 : __tree_(__comp, __a)
520 {
521 insert(__f, __l);
522 }
523
Marshall Clow631788a2013-09-11 00:06:45 +0000524#if _LIBCPP_STD_VER > 11
525 template <class _InputIterator>
Louis Dionned2322c82018-11-01 14:41:37 +0000526 _LIBCPP_INLINE_VISIBILITY
Marshall Clow631788a2013-09-11 00:06:45 +0000527 set(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
528 : set(__f, __l, key_compare(), __a) {}
529#endif
530
Howard Hinnant192cf032010-09-23 16:27:36 +0000531 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000532 set(const set& __s)
533 : __tree_(__s.__tree_)
534 {
535 insert(__s.begin(), __s.end());
536 }
537
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000538 _LIBCPP_INLINE_VISIBILITY
539 set& operator=(const set& __s)
540 {
541 __tree_ = __s.__tree_;
542 return *this;
543 }
544
Eric Fiselier615961b2017-04-18 20:58:03 +0000545#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant192cf032010-09-23 16:27:36 +0000546 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000547 set(set&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000548 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000549 : __tree_(_VSTD::move(__s.__tree_)) {}
Eric Fiselier615961b2017-04-18 20:58:03 +0000550#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000551
Howard Hinnant192cf032010-09-23 16:27:36 +0000552 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000553 explicit set(const allocator_type& __a)
554 : __tree_(__a) {}
555
Howard Hinnant192cf032010-09-23 16:27:36 +0000556 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000557 set(const set& __s, const allocator_type& __a)
558 : __tree_(__s.__tree_.value_comp(), __a)
559 {
560 insert(__s.begin(), __s.end());
561 }
562
Eric Fiselier615961b2017-04-18 20:58:03 +0000563#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000564 set(set&& __s, const allocator_type& __a);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000565
Howard Hinnant192cf032010-09-23 16:27:36 +0000566 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000567 set(initializer_list<value_type> __il, const value_compare& __comp = value_compare())
568 : __tree_(__comp)
569 {
570 insert(__il.begin(), __il.end());
571 }
572
Howard Hinnant192cf032010-09-23 16:27:36 +0000573 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000574 set(initializer_list<value_type> __il, const value_compare& __comp,
575 const allocator_type& __a)
576 : __tree_(__comp, __a)
577 {
578 insert(__il.begin(), __il.end());
579 }
580
Marshall Clow631788a2013-09-11 00:06:45 +0000581#if _LIBCPP_STD_VER > 11
Louis Dionned2322c82018-11-01 14:41:37 +0000582 _LIBCPP_INLINE_VISIBILITY
Marshall Clow631788a2013-09-11 00:06:45 +0000583 set(initializer_list<value_type> __il, const allocator_type& __a)
584 : set(__il, key_compare(), __a) {}
585#endif
586
Howard Hinnant192cf032010-09-23 16:27:36 +0000587 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000588 set& operator=(initializer_list<value_type> __il)
589 {
590 __tree_.__assign_unique(__il.begin(), __il.end());
591 return *this;
592 }
593
Howard Hinnant192cf032010-09-23 16:27:36 +0000594 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000595 set& operator=(set&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000596 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000597 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000598 __tree_ = _VSTD::move(__s.__tree_);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000599 return *this;
600 }
Eric Fiselier615961b2017-04-18 20:58:03 +0000601#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000602
Howard Hinnant192cf032010-09-23 16:27:36 +0000603 _LIBCPP_INLINE_VISIBILITY
Louis Dionne69c42c02019-04-11 16:14:56 +0000604 ~set() {
605 static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), "");
606 }
607
608 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000609 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000610 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000611 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000612 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000613 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000614 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000615 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000616
Howard Hinnant192cf032010-09-23 16:27:36 +0000617 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000618 reverse_iterator rbegin() _NOEXCEPT
619 {return reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +0000620 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000621 const_reverse_iterator rbegin() const _NOEXCEPT
622 {return const_reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +0000623 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000624 reverse_iterator rend() _NOEXCEPT
625 {return reverse_iterator(begin());}
Howard Hinnant192cf032010-09-23 16:27:36 +0000626 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000627 const_reverse_iterator rend() const _NOEXCEPT
628 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000629
Howard Hinnant192cf032010-09-23 16:27:36 +0000630 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000631 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000632 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000633 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000634 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000635 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000636 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000637 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000638
Marshall Clow425f5752017-11-15 05:51:26 +0000639 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000640 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant192cf032010-09-23 16:27:36 +0000641 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000642 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000643 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000644 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000645
646 // modifiers:
Eric Fiselier615961b2017-04-18 20:58:03 +0000647#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000648 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +0000649 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000650 pair<iterator, bool> emplace(_Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000651 {return __tree_.__emplace_unique(_VSTD::forward<_Args>(__args)...);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000652 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +0000653 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000654 iterator emplace_hint(const_iterator __p, _Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000655 {return __tree_.__emplace_hint_unique(__p, _VSTD::forward<_Args>(__args)...);}
Eric Fiselier615961b2017-04-18 20:58:03 +0000656#endif // _LIBCPP_CXX03_LANG
657
Howard Hinnant192cf032010-09-23 16:27:36 +0000658 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000659 pair<iterator,bool> insert(const value_type& __v)
660 {return __tree_.__insert_unique(__v);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000661 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000662 iterator insert(const_iterator __p, const value_type& __v)
663 {return __tree_.__insert_unique(__p, __v);}
Eric Fiselier615961b2017-04-18 20:58:03 +0000664
Howard Hinnantc51e1022010-05-11 19:42:16 +0000665 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000666 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000667 void insert(_InputIterator __f, _InputIterator __l)
668 {
669 for (const_iterator __e = cend(); __f != __l; ++__f)
670 __tree_.__insert_unique(__e, *__f);
671 }
672
Eric Fiselier615961b2017-04-18 20:58:03 +0000673#ifndef _LIBCPP_CXX03_LANG
674 _LIBCPP_INLINE_VISIBILITY
675 pair<iterator,bool> insert(value_type&& __v)
676 {return __tree_.__insert_unique(_VSTD::move(__v));}
677
678 _LIBCPP_INLINE_VISIBILITY
679 iterator insert(const_iterator __p, value_type&& __v)
680 {return __tree_.__insert_unique(__p, _VSTD::move(__v));}
681
Howard Hinnant192cf032010-09-23 16:27:36 +0000682 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000683 void insert(initializer_list<value_type> __il)
684 {insert(__il.begin(), __il.end());}
Eric Fiselier615961b2017-04-18 20:58:03 +0000685#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000686
Howard Hinnant192cf032010-09-23 16:27:36 +0000687 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000688 iterator erase(const_iterator __p) {return __tree_.erase(__p);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000689 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000690 size_type erase(const key_type& __k)
691 {return __tree_.__erase_unique(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000692 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000693 iterator erase(const_iterator __f, const_iterator __l)
694 {return __tree_.erase(__f, __l);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000695 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000696 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000697
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000698#if _LIBCPP_STD_VER > 14
699 _LIBCPP_INLINE_VISIBILITY
700 insert_return_type insert(node_type&& __nh)
701 {
702 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
703 "node_type with incompatible allocator passed to set::insert()");
704 return __tree_.template __node_handle_insert_unique<
705 node_type, insert_return_type>(_VSTD::move(__nh));
706 }
707 _LIBCPP_INLINE_VISIBILITY
708 iterator insert(const_iterator __hint, node_type&& __nh)
709 {
710 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
711 "node_type with incompatible allocator passed to set::insert()");
712 return __tree_.template __node_handle_insert_unique<node_type>(
713 __hint, _VSTD::move(__nh));
714 }
715 _LIBCPP_INLINE_VISIBILITY
716 node_type extract(key_type const& __key)
717 {
718 return __tree_.template __node_handle_extract<node_type>(__key);
719 }
720 _LIBCPP_INLINE_VISIBILITY
721 node_type extract(const_iterator __it)
722 {
723 return __tree_.template __node_handle_extract<node_type>(__it);
724 }
Louis Dionned2322c82018-11-01 14:41:37 +0000725 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000726 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +0000727 void merge(set<key_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000728 {
729 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
730 "merging container with incompatible allocator");
731 __tree_.__node_handle_merge_unique(__source.__tree_);
732 }
Louis Dionned2322c82018-11-01 14:41:37 +0000733 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000734 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +0000735 void merge(set<key_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000736 {
737 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
738 "merging container with incompatible allocator");
739 __tree_.__node_handle_merge_unique(__source.__tree_);
740 }
Louis Dionned2322c82018-11-01 14:41:37 +0000741 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000742 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +0000743 void merge(multiset<key_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000744 {
745 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
746 "merging container with incompatible allocator");
747 __tree_.__node_handle_merge_unique(__source.__tree_);
748 }
Louis Dionned2322c82018-11-01 14:41:37 +0000749 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000750 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +0000751 void merge(multiset<key_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000752 {
753 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
754 "merging container with incompatible allocator");
755 __tree_.__node_handle_merge_unique(__source.__tree_);
756 }
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000757#endif
758
Howard Hinnant192cf032010-09-23 16:27:36 +0000759 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000760 void swap(set& __s) _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
761 {__tree_.swap(__s.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000762
Howard Hinnant192cf032010-09-23 16:27:36 +0000763 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000764 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000765 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000766 key_compare key_comp() const {return __tree_.value_comp();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000767 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000768 value_compare value_comp() const {return __tree_.value_comp();}
769
770 // set operations:
Howard Hinnant192cf032010-09-23 16:27:36 +0000771 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000772 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000773 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000774 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000775#if _LIBCPP_STD_VER > 11
776 template <typename _K2>
777 _LIBCPP_INLINE_VISIBILITY
778 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
779 find(const _K2& __k) {return __tree_.find(__k);}
780 template <typename _K2>
781 _LIBCPP_INLINE_VISIBILITY
782 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
783 find(const _K2& __k) const {return __tree_.find(__k);}
784#endif
785
Howard Hinnant192cf032010-09-23 16:27:36 +0000786 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000787 size_type count(const key_type& __k) const
788 {return __tree_.__count_unique(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +0000789#if _LIBCPP_STD_VER > 11
790 template <typename _K2>
791 _LIBCPP_INLINE_VISIBILITY
792 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +0000793 count(const _K2& __k) const {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +0000794#endif
Zoe Carver3ffbab12019-07-16 03:21:01 +0000795
796#if _LIBCPP_STD_VER > 17
797 _LIBCPP_INLINE_VISIBILITY
798 bool contains(const key_type& __k) const {return find(__k) != end();}
799#endif // _LIBCPP_STD_VER > 17
800
Howard Hinnant192cf032010-09-23 16:27:36 +0000801 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000802 iterator lower_bound(const key_type& __k)
803 {return __tree_.lower_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000804 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000805 const_iterator lower_bound(const key_type& __k) const
806 {return __tree_.lower_bound(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000807#if _LIBCPP_STD_VER > 11
808 template <typename _K2>
809 _LIBCPP_INLINE_VISIBILITY
810 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
811 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
812
813 template <typename _K2>
814 _LIBCPP_INLINE_VISIBILITY
815 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
816 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
817#endif
818
Howard Hinnant192cf032010-09-23 16:27:36 +0000819 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000820 iterator upper_bound(const key_type& __k)
821 {return __tree_.upper_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000822 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000823 const_iterator upper_bound(const key_type& __k) const
824 {return __tree_.upper_bound(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000825#if _LIBCPP_STD_VER > 11
826 template <typename _K2>
827 _LIBCPP_INLINE_VISIBILITY
828 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
829 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
830 template <typename _K2>
831 _LIBCPP_INLINE_VISIBILITY
832 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
833 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
834#endif
835
Howard Hinnant192cf032010-09-23 16:27:36 +0000836 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000837 pair<iterator,iterator> equal_range(const key_type& __k)
838 {return __tree_.__equal_range_unique(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000839 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000840 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
841 {return __tree_.__equal_range_unique(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000842#if _LIBCPP_STD_VER > 11
843 template <typename _K2>
844 _LIBCPP_INLINE_VISIBILITY
845 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +0000846 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000847 template <typename _K2>
848 _LIBCPP_INLINE_VISIBILITY
849 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +0000850 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000851#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000852};
853
Louis Dionne27ecc152019-06-11 18:21:08 +0000854#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
855template<class _InputIterator,
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500856 class _Compare = less<__iter_value_type<_InputIterator>>,
857 class _Allocator = allocator<__iter_value_type<_InputIterator>>,
Louis Dionne6c7da9a2019-07-19 17:13:39 +0000858 class = _EnableIf<__is_allocator<_Allocator>::value, void>,
859 class = _EnableIf<!__is_allocator<_Compare>::value, void>>
Louis Dionne27ecc152019-06-11 18:21:08 +0000860set(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500861 -> set<__iter_value_type<_InputIterator>, _Compare, _Allocator>;
Louis Dionne27ecc152019-06-11 18:21:08 +0000862
863template<class _Key, class _Compare = less<_Key>,
864 class _Allocator = allocator<_Key>,
Louis Dionne6c7da9a2019-07-19 17:13:39 +0000865 class = _EnableIf<__is_allocator<_Allocator>::value, void>,
866 class = _EnableIf<!__is_allocator<_Compare>::value, void>>
Louis Dionne27ecc152019-06-11 18:21:08 +0000867set(initializer_list<_Key>, _Compare = _Compare(), _Allocator = _Allocator())
868 -> set<_Key, _Compare, _Allocator>;
869
870template<class _InputIterator, class _Allocator,
Louis Dionne6c7da9a2019-07-19 17:13:39 +0000871 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
Louis Dionne27ecc152019-06-11 18:21:08 +0000872set(_InputIterator, _InputIterator, _Allocator)
Arthur O'Dwyer56226762021-03-03 23:02:20 -0500873 -> set<__iter_value_type<_InputIterator>,
874 less<__iter_value_type<_InputIterator>>, _Allocator>;
Louis Dionne27ecc152019-06-11 18:21:08 +0000875
876template<class _Key, class _Allocator,
Louis Dionne6c7da9a2019-07-19 17:13:39 +0000877 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
Louis Dionne27ecc152019-06-11 18:21:08 +0000878set(initializer_list<_Key>, _Allocator)
879 -> set<_Key, less<_Key>, _Allocator>;
880#endif
881
Eric Fiselier615961b2017-04-18 20:58:03 +0000882#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000883
884template <class _Key, class _Compare, class _Allocator>
885set<_Key, _Compare, _Allocator>::set(set&& __s, const allocator_type& __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000886 : __tree_(_VSTD::move(__s.__tree_), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000887{
888 if (__a != __s.get_allocator())
889 {
890 const_iterator __e = cend();
891 while (!__s.empty())
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000892 insert(__e, _VSTD::move(__s.__tree_.remove(__s.begin())->__value_));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000893 }
894}
895
Eric Fiselier615961b2017-04-18 20:58:03 +0000896#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000897
898template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000899inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000900bool
901operator==(const set<_Key, _Compare, _Allocator>& __x,
902 const set<_Key, _Compare, _Allocator>& __y)
903{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000904 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000905}
906
907template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000908inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000909bool
910operator< (const set<_Key, _Compare, _Allocator>& __x,
911 const set<_Key, _Compare, _Allocator>& __y)
912{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000913 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000914}
915
916template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000917inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000918bool
919operator!=(const set<_Key, _Compare, _Allocator>& __x,
920 const set<_Key, _Compare, _Allocator>& __y)
921{
922 return !(__x == __y);
923}
924
925template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000926inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000927bool
928operator> (const set<_Key, _Compare, _Allocator>& __x,
929 const set<_Key, _Compare, _Allocator>& __y)
930{
931 return __y < __x;
932}
933
934template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000935inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000936bool
937operator>=(const set<_Key, _Compare, _Allocator>& __x,
938 const set<_Key, _Compare, _Allocator>& __y)
939{
940 return !(__x < __y);
941}
942
943template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000944inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000945bool
946operator<=(const set<_Key, _Compare, _Allocator>& __x,
947 const set<_Key, _Compare, _Allocator>& __y)
948{
949 return !(__y < __x);
950}
951
952// specialized algorithms:
953template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000954inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000955void
956swap(set<_Key, _Compare, _Allocator>& __x,
957 set<_Key, _Compare, _Allocator>& __y)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000958 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000959{
960 __x.swap(__y);
961}
962
Marshall Clow29b53f22018-12-14 18:49:35 +0000963#if _LIBCPP_STD_VER > 17
964template <class _Key, class _Compare, class _Allocator, class _Predicate>
965inline _LIBCPP_INLINE_VISIBILITY
Marek Kurdeja98b1412020-05-02 13:58:03 +0200966 typename set<_Key, _Compare, _Allocator>::size_type
967 erase_if(set<_Key, _Compare, _Allocator>& __c, _Predicate __pred) {
Arthur O'Dwyerb6738bd2021-03-21 16:53:09 -0400968 return _VSTD::__libcpp_erase_if_container(__c, __pred);
Marek Kurdeja98b1412020-05-02 13:58:03 +0200969}
Marshall Clow29b53f22018-12-14 18:49:35 +0000970#endif
971
Howard Hinnantc51e1022010-05-11 19:42:16 +0000972template <class _Key, class _Compare = less<_Key>,
973 class _Allocator = allocator<_Key> >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000974class _LIBCPP_TEMPLATE_VIS multiset
Howard Hinnantc51e1022010-05-11 19:42:16 +0000975{
976public:
977 // types:
Arthur O'Dwyer6a752e12021-03-03 11:10:49 -0500978 typedef _Key key_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000979 typedef key_type value_type;
Arthur O'Dwyer6a752e12021-03-03 11:10:49 -0500980 typedef _Compare key_compare;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000981 typedef key_compare value_compare;
Arthur O'Dwyer6a752e12021-03-03 11:10:49 -0500982 typedef __identity_t<_Allocator> allocator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000983 typedef value_type& reference;
984 typedef const value_type& const_reference;
985
Marshall Clow5128cf32015-11-26 01:24:04 +0000986 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
987 "Allocator::value_type must be same type as value_type");
988
Howard Hinnantc51e1022010-05-11 19:42:16 +0000989private:
990 typedef __tree<value_type, value_compare, allocator_type> __base;
991 typedef allocator_traits<allocator_type> __alloc_traits;
992 typedef typename __base::__node_holder __node_holder;
993
994 __base __tree_;
995
996public:
997 typedef typename __base::pointer pointer;
998 typedef typename __base::const_pointer const_pointer;
999 typedef typename __base::size_type size_type;
1000 typedef typename __base::difference_type difference_type;
1001 typedef typename __base::const_iterator iterator;
1002 typedef typename __base::const_iterator const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001003 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1004 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001005
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001006#if _LIBCPP_STD_VER > 14
1007 typedef __set_node_handle<typename __base::__node, allocator_type> node_type;
1008#endif
1009
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001010 template <class _Key2, class _Compare2, class _Alloc2>
1011 friend class _LIBCPP_TEMPLATE_VIS set;
1012 template <class _Key2, class _Compare2, class _Alloc2>
1013 friend class _LIBCPP_TEMPLATE_VIS multiset;
1014
Howard Hinnantc51e1022010-05-11 19:42:16 +00001015 // construct/copy/destroy:
Howard Hinnant192cf032010-09-23 16:27:36 +00001016 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +00001017 multiset()
1018 _NOEXCEPT_(
1019 is_nothrow_default_constructible<allocator_type>::value &&
1020 is_nothrow_default_constructible<key_compare>::value &&
1021 is_nothrow_copy_constructible<key_compare>::value)
1022 : __tree_(value_compare()) {}
1023
1024 _LIBCPP_INLINE_VISIBILITY
1025 explicit multiset(const value_compare& __comp)
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001026 _NOEXCEPT_(
1027 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001028 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001029 : __tree_(__comp) {}
Marshall Clow7086a5a2014-03-10 04:50:10 +00001030
Howard Hinnant192cf032010-09-23 16:27:36 +00001031 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7ed23a72014-03-05 19:06:20 +00001032 explicit multiset(const value_compare& __comp, const allocator_type& __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001033 : __tree_(__comp, __a) {}
1034 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001035 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001036 multiset(_InputIterator __f, _InputIterator __l,
1037 const value_compare& __comp = value_compare())
1038 : __tree_(__comp)
1039 {
1040 insert(__f, __l);
1041 }
1042
Marshall Clow631788a2013-09-11 00:06:45 +00001043#if _LIBCPP_STD_VER > 11
1044 template <class _InputIterator>
Louis Dionned2322c82018-11-01 14:41:37 +00001045 _LIBCPP_INLINE_VISIBILITY
Marshall Clow631788a2013-09-11 00:06:45 +00001046 multiset(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
1047 : multiset(__f, __l, key_compare(), __a) {}
1048#endif
1049
Howard Hinnantc51e1022010-05-11 19:42:16 +00001050 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001051 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001052 multiset(_InputIterator __f, _InputIterator __l,
1053 const value_compare& __comp, const allocator_type& __a)
1054 : __tree_(__comp, __a)
1055 {
1056 insert(__f, __l);
1057 }
1058
Howard Hinnant192cf032010-09-23 16:27:36 +00001059 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001060 multiset(const multiset& __s)
1061 : __tree_(__s.__tree_.value_comp(),
1062 __alloc_traits::select_on_container_copy_construction(__s.__tree_.__alloc()))
1063 {
1064 insert(__s.begin(), __s.end());
1065 }
1066
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001067 _LIBCPP_INLINE_VISIBILITY
1068 multiset& operator=(const multiset& __s)
1069 {
1070 __tree_ = __s.__tree_;
1071 return *this;
1072 }
1073
Eric Fiselier615961b2017-04-18 20:58:03 +00001074#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant192cf032010-09-23 16:27:36 +00001075 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001076 multiset(multiset&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001077 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001078 : __tree_(_VSTD::move(__s.__tree_)) {}
Eric Fiselier615961b2017-04-18 20:58:03 +00001079
1080 multiset(multiset&& __s, const allocator_type& __a);
1081#endif // _LIBCPP_CXX03_LANG
Howard Hinnant192cf032010-09-23 16:27:36 +00001082 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001083 explicit multiset(const allocator_type& __a)
1084 : __tree_(__a) {}
Howard Hinnant192cf032010-09-23 16:27:36 +00001085 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001086 multiset(const multiset& __s, const allocator_type& __a)
1087 : __tree_(__s.__tree_.value_comp(), __a)
1088 {
1089 insert(__s.begin(), __s.end());
1090 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001091
Eric Fiselier615961b2017-04-18 20:58:03 +00001092#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant192cf032010-09-23 16:27:36 +00001093 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001094 multiset(initializer_list<value_type> __il, const value_compare& __comp = value_compare())
1095 : __tree_(__comp)
1096 {
1097 insert(__il.begin(), __il.end());
1098 }
1099
Howard Hinnant192cf032010-09-23 16:27:36 +00001100 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001101 multiset(initializer_list<value_type> __il, const value_compare& __comp,
1102 const allocator_type& __a)
1103 : __tree_(__comp, __a)
1104 {
1105 insert(__il.begin(), __il.end());
1106 }
1107
Marshall Clow631788a2013-09-11 00:06:45 +00001108#if _LIBCPP_STD_VER > 11
Louis Dionned2322c82018-11-01 14:41:37 +00001109 _LIBCPP_INLINE_VISIBILITY
Marshall Clow631788a2013-09-11 00:06:45 +00001110 multiset(initializer_list<value_type> __il, const allocator_type& __a)
1111 : multiset(__il, key_compare(), __a) {}
1112#endif
1113
Howard Hinnant192cf032010-09-23 16:27:36 +00001114 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001115 multiset& operator=(initializer_list<value_type> __il)
1116 {
1117 __tree_.__assign_multi(__il.begin(), __il.end());
1118 return *this;
1119 }
1120
Howard Hinnant192cf032010-09-23 16:27:36 +00001121 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001122 multiset& operator=(multiset&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001123 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001124 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001125 __tree_ = _VSTD::move(__s.__tree_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001126 return *this;
1127 }
Eric Fiselier615961b2017-04-18 20:58:03 +00001128#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001129
Howard Hinnant192cf032010-09-23 16:27:36 +00001130 _LIBCPP_INLINE_VISIBILITY
Louis Dionne69c42c02019-04-11 16:14:56 +00001131 ~multiset() {
1132 static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), "");
1133 }
1134
1135 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001136 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001137 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001138 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001139 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001140 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001141 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001142 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001143
Howard Hinnant192cf032010-09-23 16:27:36 +00001144 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001145 reverse_iterator rbegin() _NOEXCEPT
1146 {return reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +00001147 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001148 const_reverse_iterator rbegin() const _NOEXCEPT
1149 {return const_reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +00001150 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001151 reverse_iterator rend() _NOEXCEPT
1152 {return reverse_iterator(begin());}
Howard Hinnant192cf032010-09-23 16:27:36 +00001153 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001154 const_reverse_iterator rend() const _NOEXCEPT
1155 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001156
Howard Hinnant192cf032010-09-23 16:27:36 +00001157 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001158 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001159 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001160 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001161 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001162 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001163 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001164 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001165
Marshall Clow425f5752017-11-15 05:51:26 +00001166 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001167 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant192cf032010-09-23 16:27:36 +00001168 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001169 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001170 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001171 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001172
1173 // modifiers:
Eric Fiselier615961b2017-04-18 20:58:03 +00001174#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001175 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +00001176 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001177 iterator emplace(_Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001178 {return __tree_.__emplace_multi(_VSTD::forward<_Args>(__args)...);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001179 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +00001180 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001181 iterator emplace_hint(const_iterator __p, _Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001182 {return __tree_.__emplace_hint_multi(__p, _VSTD::forward<_Args>(__args)...);}
Eric Fiselier615961b2017-04-18 20:58:03 +00001183#endif // _LIBCPP_CXX03_LANG
1184
Howard Hinnant192cf032010-09-23 16:27:36 +00001185 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001186 iterator insert(const value_type& __v)
1187 {return __tree_.__insert_multi(__v);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001188 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001189 iterator insert(const_iterator __p, const value_type& __v)
1190 {return __tree_.__insert_multi(__p, __v);}
Eric Fiselier615961b2017-04-18 20:58:03 +00001191
Howard Hinnantc51e1022010-05-11 19:42:16 +00001192 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001193 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001194 void insert(_InputIterator __f, _InputIterator __l)
1195 {
1196 for (const_iterator __e = cend(); __f != __l; ++__f)
1197 __tree_.__insert_multi(__e, *__f);
1198 }
1199
Eric Fiselier615961b2017-04-18 20:58:03 +00001200#ifndef _LIBCPP_CXX03_LANG
1201 _LIBCPP_INLINE_VISIBILITY
1202 iterator insert(value_type&& __v)
1203 {return __tree_.__insert_multi(_VSTD::move(__v));}
1204
1205 _LIBCPP_INLINE_VISIBILITY
1206 iterator insert(const_iterator __p, value_type&& __v)
1207 {return __tree_.__insert_multi(__p, _VSTD::move(__v));}
1208
Howard Hinnant192cf032010-09-23 16:27:36 +00001209 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001210 void insert(initializer_list<value_type> __il)
1211 {insert(__il.begin(), __il.end());}
Eric Fiselier615961b2017-04-18 20:58:03 +00001212#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001213
Howard Hinnant192cf032010-09-23 16:27:36 +00001214 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001215 iterator erase(const_iterator __p) {return __tree_.erase(__p);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001216 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001217 size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001218 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001219 iterator erase(const_iterator __f, const_iterator __l)
1220 {return __tree_.erase(__f, __l);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001221 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001222 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001223
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001224#if _LIBCPP_STD_VER > 14
1225 _LIBCPP_INLINE_VISIBILITY
1226 iterator insert(node_type&& __nh)
1227 {
1228 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1229 "node_type with incompatible allocator passed to multiset::insert()");
1230 return __tree_.template __node_handle_insert_multi<node_type>(
1231 _VSTD::move(__nh));
1232 }
1233 _LIBCPP_INLINE_VISIBILITY
1234 iterator insert(const_iterator __hint, node_type&& __nh)
1235 {
1236 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1237 "node_type with incompatible allocator passed to multiset::insert()");
1238 return __tree_.template __node_handle_insert_multi<node_type>(
1239 __hint, _VSTD::move(__nh));
1240 }
1241 _LIBCPP_INLINE_VISIBILITY
1242 node_type extract(key_type const& __key)
1243 {
1244 return __tree_.template __node_handle_extract<node_type>(__key);
1245 }
1246 _LIBCPP_INLINE_VISIBILITY
1247 node_type extract(const_iterator __it)
1248 {
1249 return __tree_.template __node_handle_extract<node_type>(__it);
1250 }
Louis Dionned2322c82018-11-01 14:41:37 +00001251 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001252 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001253 void merge(multiset<key_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001254 {
1255 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1256 "merging container with incompatible allocator");
1257 __tree_.__node_handle_merge_multi(__source.__tree_);
1258 }
Louis Dionned2322c82018-11-01 14:41:37 +00001259 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001260 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001261 void merge(multiset<key_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001262 {
1263 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1264 "merging container with incompatible allocator");
1265 __tree_.__node_handle_merge_multi(__source.__tree_);
1266 }
Louis Dionned2322c82018-11-01 14:41:37 +00001267 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001268 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001269 void merge(set<key_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001270 {
1271 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1272 "merging container with incompatible allocator");
1273 __tree_.__node_handle_merge_multi(__source.__tree_);
1274 }
Louis Dionned2322c82018-11-01 14:41:37 +00001275 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001276 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001277 void merge(set<key_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001278 {
1279 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1280 "merging container with incompatible allocator");
1281 __tree_.__node_handle_merge_multi(__source.__tree_);
1282 }
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001283#endif
1284
Howard Hinnant192cf032010-09-23 16:27:36 +00001285 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001286 void swap(multiset& __s)
1287 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1288 {__tree_.swap(__s.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001289
Howard Hinnant192cf032010-09-23 16:27:36 +00001290 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001291 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001292 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001293 key_compare key_comp() const {return __tree_.value_comp();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001294 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001295 value_compare value_comp() const {return __tree_.value_comp();}
1296
1297 // set operations:
Howard Hinnant192cf032010-09-23 16:27:36 +00001298 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001299 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001300 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001301 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +00001302#if _LIBCPP_STD_VER > 11
1303 template <typename _K2>
1304 _LIBCPP_INLINE_VISIBILITY
1305 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,iterator>::type
1306 find(const _K2& __k) {return __tree_.find(__k);}
1307 template <typename _K2>
1308 _LIBCPP_INLINE_VISIBILITY
1309 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,const_iterator>::type
1310 find(const _K2& __k) const {return __tree_.find(__k);}
1311#endif
1312
Howard Hinnant192cf032010-09-23 16:27:36 +00001313 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001314 size_type count(const key_type& __k) const
1315 {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001316#if _LIBCPP_STD_VER > 11
1317 template <typename _K2>
1318 _LIBCPP_INLINE_VISIBILITY
1319 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
Marshall Clow5571bcd2018-01-07 17:39:57 +00001320 count(const _K2& __k) const {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001321#endif
Marshall Clowc0152142013-08-13 01:11:06 +00001322
Zoe Carver3ffbab12019-07-16 03:21:01 +00001323#if _LIBCPP_STD_VER > 17
1324 _LIBCPP_INLINE_VISIBILITY
1325 bool contains(const key_type& __k) const {return find(__k) != end();}
1326#endif // _LIBCPP_STD_VER > 17
1327
Howard Hinnant192cf032010-09-23 16:27:36 +00001328 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001329 iterator lower_bound(const key_type& __k)
1330 {return __tree_.lower_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001331 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001332 const_iterator lower_bound(const key_type& __k) const
1333 {return __tree_.lower_bound(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +00001334#if _LIBCPP_STD_VER > 11
1335 template <typename _K2>
1336 _LIBCPP_INLINE_VISIBILITY
1337 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,iterator>::type
1338 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
1339
1340 template <typename _K2>
1341 _LIBCPP_INLINE_VISIBILITY
1342 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,const_iterator>::type
1343 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
1344#endif
1345
Howard Hinnant192cf032010-09-23 16:27:36 +00001346 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001347 iterator upper_bound(const key_type& __k)
1348 {return __tree_.upper_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001349 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001350 const_iterator upper_bound(const key_type& __k) const
1351 {return __tree_.upper_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 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
1357 template <typename _K2>
1358 _LIBCPP_INLINE_VISIBILITY
1359 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,const_iterator>::type
1360 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
1361#endif
1362
Howard Hinnant192cf032010-09-23 16:27:36 +00001363 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001364 pair<iterator,iterator> equal_range(const key_type& __k)
1365 {return __tree_.__equal_range_multi(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001366 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001367 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
1368 {return __tree_.__equal_range_multi(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +00001369#if _LIBCPP_STD_VER > 11
1370 template <typename _K2>
1371 _LIBCPP_INLINE_VISIBILITY
1372 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
1373 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
1374 template <typename _K2>
1375 _LIBCPP_INLINE_VISIBILITY
1376 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
1377 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
1378#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001379};
1380
Louis Dionne27ecc152019-06-11 18:21:08 +00001381#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
1382template<class _InputIterator,
Arthur O'Dwyer56226762021-03-03 23:02:20 -05001383 class _Compare = less<__iter_value_type<_InputIterator>>,
1384 class _Allocator = allocator<__iter_value_type<_InputIterator>>,
Louis Dionne6c7da9a2019-07-19 17:13:39 +00001385 class = _EnableIf<__is_allocator<_Allocator>::value, void>,
1386 class = _EnableIf<!__is_allocator<_Compare>::value, void>>
Louis Dionne27ecc152019-06-11 18:21:08 +00001387multiset(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
Arthur O'Dwyer56226762021-03-03 23:02:20 -05001388 -> multiset<__iter_value_type<_InputIterator>, _Compare, _Allocator>;
Louis Dionne27ecc152019-06-11 18:21:08 +00001389
1390template<class _Key, class _Compare = less<_Key>,
1391 class _Allocator = allocator<_Key>,
Louis Dionne6c7da9a2019-07-19 17:13:39 +00001392 class = _EnableIf<__is_allocator<_Allocator>::value, void>,
1393 class = _EnableIf<!__is_allocator<_Compare>::value, void>>
Louis Dionne27ecc152019-06-11 18:21:08 +00001394multiset(initializer_list<_Key>, _Compare = _Compare(), _Allocator = _Allocator())
1395 -> multiset<_Key, _Compare, _Allocator>;
1396
1397template<class _InputIterator, class _Allocator,
Louis Dionne6c7da9a2019-07-19 17:13:39 +00001398 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
Louis Dionne27ecc152019-06-11 18:21:08 +00001399multiset(_InputIterator, _InputIterator, _Allocator)
Arthur O'Dwyer56226762021-03-03 23:02:20 -05001400 -> multiset<__iter_value_type<_InputIterator>,
1401 less<__iter_value_type<_InputIterator>>, _Allocator>;
Louis Dionne27ecc152019-06-11 18:21:08 +00001402
1403template<class _Key, class _Allocator,
Louis Dionne6c7da9a2019-07-19 17:13:39 +00001404 class = _EnableIf<__is_allocator<_Allocator>::value, void>>
Louis Dionne27ecc152019-06-11 18:21:08 +00001405multiset(initializer_list<_Key>, _Allocator)
1406 -> multiset<_Key, less<_Key>, _Allocator>;
1407#endif
1408
Eric Fiselier615961b2017-04-18 20:58:03 +00001409#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001410
1411template <class _Key, class _Compare, class _Allocator>
1412multiset<_Key, _Compare, _Allocator>::multiset(multiset&& __s, const allocator_type& __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001413 : __tree_(_VSTD::move(__s.__tree_), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001414{
1415 if (__a != __s.get_allocator())
1416 {
1417 const_iterator __e = cend();
1418 while (!__s.empty())
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001419 insert(__e, _VSTD::move(__s.__tree_.remove(__s.begin())->__value_));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001420 }
1421}
1422
Eric Fiselier615961b2017-04-18 20:58:03 +00001423#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001424
1425template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001426inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001427bool
1428operator==(const multiset<_Key, _Compare, _Allocator>& __x,
1429 const multiset<_Key, _Compare, _Allocator>& __y)
1430{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001431 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001432}
1433
1434template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001435inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001436bool
1437operator< (const multiset<_Key, _Compare, _Allocator>& __x,
1438 const multiset<_Key, _Compare, _Allocator>& __y)
1439{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001440 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001441}
1442
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{
1449 return !(__x == __y);
1450}
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{
1458 return __y < __x;
1459}
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 +00001481void
1482swap(multiset<_Key, _Compare, _Allocator>& __x,
1483 multiset<_Key, _Compare, _Allocator>& __y)
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001484 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001485{
1486 __x.swap(__y);
1487}
1488
Marshall Clow29b53f22018-12-14 18:49:35 +00001489#if _LIBCPP_STD_VER > 17
1490template <class _Key, class _Compare, class _Allocator, class _Predicate>
1491inline _LIBCPP_INLINE_VISIBILITY
Marek Kurdeja98b1412020-05-02 13:58:03 +02001492 typename multiset<_Key, _Compare, _Allocator>::size_type
1493 erase_if(multiset<_Key, _Compare, _Allocator>& __c, _Predicate __pred) {
Arthur O'Dwyerb6738bd2021-03-21 16:53:09 -04001494 return _VSTD::__libcpp_erase_if_container(__c, __pred);
Marek Kurdeja98b1412020-05-02 13:58:03 +02001495}
Marshall Clow29b53f22018-12-14 18:49:35 +00001496#endif
1497
Howard Hinnantc51e1022010-05-11 19:42:16 +00001498_LIBCPP_END_NAMESPACE_STD
1499
1500#endif // _LIBCPP_SET