blob: 79e8f29f0b9437730663ff349d1d287572f13e9d [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>
158 size_type count(const K& x) const; // C++14
159
Howard Hinnantc51e1022010-05-11 19:42:16 +0000160 size_type count(const key_type& k) const;
161 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>
219 void erase_if(set<Key, Compare, Allocator>& c, Predicate pred); // C++20
220
Howard Hinnantc51e1022010-05-11 19:42:16 +0000221template <class Key, class Compare = less<Key>,
222 class Allocator = allocator<Key>>
223class multiset
224{
225public:
226 // types:
227 typedef Key key_type;
228 typedef key_type value_type;
229 typedef Compare key_compare;
230 typedef key_compare value_compare;
231 typedef Allocator allocator_type;
232 typedef typename allocator_type::reference reference;
233 typedef typename allocator_type::const_reference const_reference;
234 typedef typename allocator_type::size_type size_type;
235 typedef typename allocator_type::difference_type difference_type;
236 typedef typename allocator_type::pointer pointer;
237 typedef typename allocator_type::const_pointer const_pointer;
238
239 typedef implementation-defined iterator;
240 typedef implementation-defined const_iterator;
241 typedef std::reverse_iterator<iterator> reverse_iterator;
242 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000243 typedef unspecified node_type; // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000244
245 // construct/copy/destroy:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000246 multiset()
247 noexcept(
248 is_nothrow_default_constructible<allocator_type>::value &&
249 is_nothrow_default_constructible<key_compare>::value &&
250 is_nothrow_copy_constructible<key_compare>::value);
251 explicit multiset(const value_compare& comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000252 multiset(const value_compare& comp, const allocator_type& a);
253 template <class InputIterator>
254 multiset(InputIterator first, InputIterator last,
255 const value_compare& comp = value_compare());
256 template <class InputIterator>
257 multiset(InputIterator first, InputIterator last,
258 const value_compare& comp, const allocator_type& a);
259 multiset(const multiset& s);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000260 multiset(multiset&& s)
261 noexcept(
262 is_nothrow_move_constructible<allocator_type>::value &&
263 is_nothrow_move_constructible<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000264 explicit multiset(const allocator_type& a);
265 multiset(const multiset& s, const allocator_type& a);
266 multiset(multiset&& s, const allocator_type& a);
267 multiset(initializer_list<value_type> il, const value_compare& comp = value_compare());
268 multiset(initializer_list<value_type> il, const value_compare& comp,
269 const allocator_type& a);
Marshall Clow631788a2013-09-11 00:06:45 +0000270 template <class InputIterator>
271 multiset(InputIterator first, InputIterator last, const allocator_type& a)
272 : set(first, last, Compare(), a) {} // C++14
273 multiset(initializer_list<value_type> il, const allocator_type& a)
274 : set(il, Compare(), a) {} // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000275 ~multiset();
276
277 multiset& operator=(const multiset& s);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000278 multiset& operator=(multiset&& s)
279 noexcept(
280 allocator_type::propagate_on_container_move_assignment::value &&
281 is_nothrow_move_assignable<allocator_type>::value &&
282 is_nothrow_move_assignable<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000283 multiset& operator=(initializer_list<value_type> il);
284
285 // iterators:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000286 iterator begin() noexcept;
287 const_iterator begin() const noexcept;
288 iterator end() noexcept;
289 const_iterator end() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000290
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000291 reverse_iterator rbegin() noexcept;
292 const_reverse_iterator rbegin() const noexcept;
293 reverse_iterator rend() noexcept;
294 const_reverse_iterator rend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000295
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000296 const_iterator cbegin() const noexcept;
297 const_iterator cend() const noexcept;
298 const_reverse_iterator crbegin() const noexcept;
299 const_reverse_iterator crend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000300
301 // capacity:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000302 bool empty() const noexcept;
303 size_type size() const noexcept;
304 size_type max_size() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000305
306 // modifiers:
307 template <class... Args>
308 iterator emplace(Args&&... args);
309 template <class... Args>
310 iterator emplace_hint(const_iterator position, Args&&... args);
311 iterator insert(const value_type& v);
312 iterator insert(value_type&& v);
313 iterator insert(const_iterator position, const value_type& v);
314 iterator insert(const_iterator position, value_type&& v);
315 template <class InputIterator>
316 void insert(InputIterator first, InputIterator last);
317 void insert(initializer_list<value_type> il);
318
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000319 node_type extract(const_iterator position); // C++17
320 node_type extract(const key_type& x); // C++17
321 iterator insert(node_type&& nh); // C++17
322 iterator insert(const_iterator hint, node_type&& nh); // C++17
323
Howard Hinnantc51e1022010-05-11 19:42:16 +0000324 iterator erase(const_iterator position);
Marshall Clow22ea5b82015-05-10 13:35:00 +0000325 iterator erase(iterator position); // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000326 size_type erase(const key_type& k);
327 iterator erase(const_iterator first, const_iterator last);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000328 void clear() noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000329
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000330 template<class C2>
331 void merge(multiset<Key, C2, Allocator>& source); // C++17
332 template<class C2>
333 void merge(multiset<Key, C2, Allocator>&& source); // C++17
334 template<class C2>
335 void merge(set<Key, C2, Allocator>& source); // C++17
336 template<class C2>
337 void merge(set<Key, C2, Allocator>&& source); // C++17
338
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000339 void swap(multiset& s)
340 noexcept(
341 __is_nothrow_swappable<key_compare>::value &&
342 (!allocator_type::propagate_on_container_swap::value ||
343 __is_nothrow_swappable<allocator_type>::value));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000344
345 // observers:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000346 allocator_type get_allocator() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000347 key_compare key_comp() const;
348 value_compare value_comp() const;
349
350 // set operations:
351 iterator find(const key_type& k);
352 const_iterator find(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000353 template<typename K>
354 iterator find(const K& x);
355 template<typename K>
356 const_iterator find(const K& x) const; // C++14
357
Howard Hinnantc51e1022010-05-11 19:42:16 +0000358 size_type count(const key_type& k) const;
359 iterator lower_bound(const key_type& k);
360 const_iterator lower_bound(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000361 template<typename K>
362 iterator lower_bound(const K& x); // C++14
363 template<typename K>
364 const_iterator lower_bound(const K& x) const; // C++14
365
Howard Hinnantc51e1022010-05-11 19:42:16 +0000366 iterator upper_bound(const key_type& k);
367 const_iterator upper_bound(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000368 template<typename K>
369 iterator upper_bound(const K& x); // C++14
370 template<typename K>
371 const_iterator upper_bound(const K& x) const; // C++14
372
Howard Hinnantc51e1022010-05-11 19:42:16 +0000373 pair<iterator,iterator> equal_range(const key_type& k);
374 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000375 template<typename K>
376 pair<iterator,iterator> equal_range(const K& x); // C++14
377 template<typename K>
378 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000379};
380
381template <class Key, class Compare, class Allocator>
382bool
383operator==(const multiset<Key, Compare, Allocator>& x,
384 const multiset<Key, Compare, Allocator>& y);
385
386template <class Key, class Compare, class Allocator>
387bool
388operator< (const multiset<Key, Compare, Allocator>& x,
389 const multiset<Key, Compare, Allocator>& y);
390
391template <class Key, class Compare, class Allocator>
392bool
393operator!=(const multiset<Key, Compare, Allocator>& x,
394 const multiset<Key, Compare, Allocator>& y);
395
396template <class Key, class Compare, class Allocator>
397bool
398operator> (const multiset<Key, Compare, Allocator>& x,
399 const multiset<Key, Compare, Allocator>& y);
400
401template <class Key, class Compare, class Allocator>
402bool
403operator>=(const multiset<Key, Compare, Allocator>& x,
404 const multiset<Key, Compare, Allocator>& y);
405
406template <class Key, class Compare, class Allocator>
407bool
408operator<=(const multiset<Key, Compare, Allocator>& x,
409 const multiset<Key, Compare, Allocator>& y);
410
411// specialized algorithms:
412template <class Key, class Compare, class Allocator>
413void
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000414swap(multiset<Key, Compare, Allocator>& x, multiset<Key, Compare, Allocator>& y)
415 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000416
Marshall Clow29b53f22018-12-14 18:49:35 +0000417template <class Key, class Compare, class Allocator, class Predicate>
418 void erase_if(multiset<Key, Compare, Allocator>& c, Predicate pred); // C++20
419
Howard Hinnantc51e1022010-05-11 19:42:16 +0000420} // std
421
422*/
423
424#include <__config>
425#include <__tree>
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000426#include <__node_handle>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000427#include <functional>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000428#include <version>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000429
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000430#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000431#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000432#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000433
434_LIBCPP_BEGIN_NAMESPACE_STD
435
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000436template <class _Key, class _Compare, class _Allocator>
437class multiset;
438
Howard Hinnantc51e1022010-05-11 19:42:16 +0000439template <class _Key, class _Compare = less<_Key>,
440 class _Allocator = allocator<_Key> >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000441class _LIBCPP_TEMPLATE_VIS set
Howard Hinnantc51e1022010-05-11 19:42:16 +0000442{
443public:
444 // types:
445 typedef _Key key_type;
446 typedef key_type value_type;
447 typedef _Compare key_compare;
448 typedef key_compare value_compare;
Louis Dionne27ecc152019-06-11 18:21:08 +0000449 typedef typename __identity<_Allocator>::type allocator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000450 typedef value_type& reference;
451 typedef const value_type& const_reference;
452
Marshall Clow5128cf32015-11-26 01:24:04 +0000453 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
454 "Allocator::value_type must be same type as value_type");
455
Howard Hinnantc51e1022010-05-11 19:42:16 +0000456private:
457 typedef __tree<value_type, value_compare, allocator_type> __base;
458 typedef allocator_traits<allocator_type> __alloc_traits;
459 typedef typename __base::__node_holder __node_holder;
460
461 __base __tree_;
462
463public:
464 typedef typename __base::pointer pointer;
465 typedef typename __base::const_pointer const_pointer;
466 typedef typename __base::size_type size_type;
467 typedef typename __base::difference_type difference_type;
468 typedef typename __base::const_iterator iterator;
469 typedef typename __base::const_iterator const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000470 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
471 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000472
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000473#if _LIBCPP_STD_VER > 14
474 typedef __set_node_handle<typename __base::__node, allocator_type> node_type;
475 typedef __insert_return_type<iterator, node_type> insert_return_type;
476#endif
477
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000478 template <class _Key2, class _Compare2, class _Alloc2>
479 friend class _LIBCPP_TEMPLATE_VIS set;
480 template <class _Key2, class _Compare2, class _Alloc2>
481 friend class _LIBCPP_TEMPLATE_VIS multiset;
482
Howard Hinnant192cf032010-09-23 16:27:36 +0000483 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +0000484 set()
485 _NOEXCEPT_(
486 is_nothrow_default_constructible<allocator_type>::value &&
487 is_nothrow_default_constructible<key_compare>::value &&
488 is_nothrow_copy_constructible<key_compare>::value)
489 : __tree_(value_compare()) {}
490
491 _LIBCPP_INLINE_VISIBILITY
492 explicit set(const value_compare& __comp)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000493 _NOEXCEPT_(
494 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000495 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000496 : __tree_(__comp) {}
Marshall Clow7086a5a2014-03-10 04:50:10 +0000497
Howard Hinnant192cf032010-09-23 16:27:36 +0000498 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7ed23a72014-03-05 19:06:20 +0000499 explicit set(const value_compare& __comp, const allocator_type& __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000500 : __tree_(__comp, __a) {}
501 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000502 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000503 set(_InputIterator __f, _InputIterator __l,
504 const value_compare& __comp = value_compare())
505 : __tree_(__comp)
506 {
507 insert(__f, __l);
508 }
509
510 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000511 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000512 set(_InputIterator __f, _InputIterator __l, const value_compare& __comp,
513 const allocator_type& __a)
514 : __tree_(__comp, __a)
515 {
516 insert(__f, __l);
517 }
518
Marshall Clow631788a2013-09-11 00:06:45 +0000519#if _LIBCPP_STD_VER > 11
520 template <class _InputIterator>
Louis Dionned2322c82018-11-01 14:41:37 +0000521 _LIBCPP_INLINE_VISIBILITY
Marshall Clow631788a2013-09-11 00:06:45 +0000522 set(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
523 : set(__f, __l, key_compare(), __a) {}
524#endif
525
Howard Hinnant192cf032010-09-23 16:27:36 +0000526 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000527 set(const set& __s)
528 : __tree_(__s.__tree_)
529 {
530 insert(__s.begin(), __s.end());
531 }
532
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000533 _LIBCPP_INLINE_VISIBILITY
534 set& operator=(const set& __s)
535 {
536 __tree_ = __s.__tree_;
537 return *this;
538 }
539
Eric Fiselier615961b2017-04-18 20:58:03 +0000540#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant192cf032010-09-23 16:27:36 +0000541 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000542 set(set&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000543 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000544 : __tree_(_VSTD::move(__s.__tree_)) {}
Eric Fiselier615961b2017-04-18 20:58:03 +0000545#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000546
Howard Hinnant192cf032010-09-23 16:27:36 +0000547 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000548 explicit set(const allocator_type& __a)
549 : __tree_(__a) {}
550
Howard Hinnant192cf032010-09-23 16:27:36 +0000551 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000552 set(const set& __s, const allocator_type& __a)
553 : __tree_(__s.__tree_.value_comp(), __a)
554 {
555 insert(__s.begin(), __s.end());
556 }
557
Eric Fiselier615961b2017-04-18 20:58:03 +0000558#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000559 set(set&& __s, const allocator_type& __a);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000560
Howard Hinnant192cf032010-09-23 16:27:36 +0000561 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000562 set(initializer_list<value_type> __il, const value_compare& __comp = value_compare())
563 : __tree_(__comp)
564 {
565 insert(__il.begin(), __il.end());
566 }
567
Howard Hinnant192cf032010-09-23 16:27:36 +0000568 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000569 set(initializer_list<value_type> __il, const value_compare& __comp,
570 const allocator_type& __a)
571 : __tree_(__comp, __a)
572 {
573 insert(__il.begin(), __il.end());
574 }
575
Marshall Clow631788a2013-09-11 00:06:45 +0000576#if _LIBCPP_STD_VER > 11
Louis Dionned2322c82018-11-01 14:41:37 +0000577 _LIBCPP_INLINE_VISIBILITY
Marshall Clow631788a2013-09-11 00:06:45 +0000578 set(initializer_list<value_type> __il, const allocator_type& __a)
579 : set(__il, key_compare(), __a) {}
580#endif
581
Howard Hinnant192cf032010-09-23 16:27:36 +0000582 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000583 set& operator=(initializer_list<value_type> __il)
584 {
585 __tree_.__assign_unique(__il.begin(), __il.end());
586 return *this;
587 }
588
Howard Hinnant192cf032010-09-23 16:27:36 +0000589 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000590 set& operator=(set&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000591 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000592 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000593 __tree_ = _VSTD::move(__s.__tree_);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000594 return *this;
595 }
Eric Fiselier615961b2017-04-18 20:58:03 +0000596#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000597
Howard Hinnant192cf032010-09-23 16:27:36 +0000598 _LIBCPP_INLINE_VISIBILITY
Louis Dionne69c42c02019-04-11 16:14:56 +0000599 ~set() {
600 static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), "");
601 }
602
603 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000604 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000605 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000606 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000607 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000608 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000609 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000610 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000611
Howard Hinnant192cf032010-09-23 16:27:36 +0000612 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000613 reverse_iterator rbegin() _NOEXCEPT
614 {return reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +0000615 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000616 const_reverse_iterator rbegin() const _NOEXCEPT
617 {return const_reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +0000618 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000619 reverse_iterator rend() _NOEXCEPT
620 {return reverse_iterator(begin());}
Howard Hinnant192cf032010-09-23 16:27:36 +0000621 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000622 const_reverse_iterator rend() const _NOEXCEPT
623 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000624
Howard Hinnant192cf032010-09-23 16:27:36 +0000625 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000626 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000627 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000628 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000629 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000630 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000631 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000632 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000633
Marshall Clow425f5752017-11-15 05:51:26 +0000634 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000635 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant192cf032010-09-23 16:27:36 +0000636 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000637 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000638 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000639 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000640
641 // modifiers:
Eric Fiselier615961b2017-04-18 20:58:03 +0000642#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000643 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +0000644 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000645 pair<iterator, bool> emplace(_Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000646 {return __tree_.__emplace_unique(_VSTD::forward<_Args>(__args)...);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000647 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +0000648 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000649 iterator emplace_hint(const_iterator __p, _Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000650 {return __tree_.__emplace_hint_unique(__p, _VSTD::forward<_Args>(__args)...);}
Eric Fiselier615961b2017-04-18 20:58:03 +0000651#endif // _LIBCPP_CXX03_LANG
652
Howard Hinnant192cf032010-09-23 16:27:36 +0000653 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000654 pair<iterator,bool> insert(const value_type& __v)
655 {return __tree_.__insert_unique(__v);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000656 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000657 iterator insert(const_iterator __p, const value_type& __v)
658 {return __tree_.__insert_unique(__p, __v);}
Eric Fiselier615961b2017-04-18 20:58:03 +0000659
Howard Hinnantc51e1022010-05-11 19:42:16 +0000660 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000661 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000662 void insert(_InputIterator __f, _InputIterator __l)
663 {
664 for (const_iterator __e = cend(); __f != __l; ++__f)
665 __tree_.__insert_unique(__e, *__f);
666 }
667
Eric Fiselier615961b2017-04-18 20:58:03 +0000668#ifndef _LIBCPP_CXX03_LANG
669 _LIBCPP_INLINE_VISIBILITY
670 pair<iterator,bool> insert(value_type&& __v)
671 {return __tree_.__insert_unique(_VSTD::move(__v));}
672
673 _LIBCPP_INLINE_VISIBILITY
674 iterator insert(const_iterator __p, value_type&& __v)
675 {return __tree_.__insert_unique(__p, _VSTD::move(__v));}
676
Howard Hinnant192cf032010-09-23 16:27:36 +0000677 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000678 void insert(initializer_list<value_type> __il)
679 {insert(__il.begin(), __il.end());}
Eric Fiselier615961b2017-04-18 20:58:03 +0000680#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000681
Howard Hinnant192cf032010-09-23 16:27:36 +0000682 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000683 iterator erase(const_iterator __p) {return __tree_.erase(__p);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000684 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000685 size_type erase(const key_type& __k)
686 {return __tree_.__erase_unique(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000687 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000688 iterator erase(const_iterator __f, const_iterator __l)
689 {return __tree_.erase(__f, __l);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000690 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000691 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000692
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000693#if _LIBCPP_STD_VER > 14
694 _LIBCPP_INLINE_VISIBILITY
695 insert_return_type insert(node_type&& __nh)
696 {
697 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
698 "node_type with incompatible allocator passed to set::insert()");
699 return __tree_.template __node_handle_insert_unique<
700 node_type, insert_return_type>(_VSTD::move(__nh));
701 }
702 _LIBCPP_INLINE_VISIBILITY
703 iterator insert(const_iterator __hint, node_type&& __nh)
704 {
705 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
706 "node_type with incompatible allocator passed to set::insert()");
707 return __tree_.template __node_handle_insert_unique<node_type>(
708 __hint, _VSTD::move(__nh));
709 }
710 _LIBCPP_INLINE_VISIBILITY
711 node_type extract(key_type const& __key)
712 {
713 return __tree_.template __node_handle_extract<node_type>(__key);
714 }
715 _LIBCPP_INLINE_VISIBILITY
716 node_type extract(const_iterator __it)
717 {
718 return __tree_.template __node_handle_extract<node_type>(__it);
719 }
Louis Dionned2322c82018-11-01 14:41:37 +0000720 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000721 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +0000722 void merge(set<key_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000723 {
724 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
725 "merging container with incompatible allocator");
726 __tree_.__node_handle_merge_unique(__source.__tree_);
727 }
Louis Dionned2322c82018-11-01 14:41:37 +0000728 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000729 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +0000730 void merge(set<key_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000731 {
732 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
733 "merging container with incompatible allocator");
734 __tree_.__node_handle_merge_unique(__source.__tree_);
735 }
Louis Dionned2322c82018-11-01 14:41:37 +0000736 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000737 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +0000738 void merge(multiset<key_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000739 {
740 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
741 "merging container with incompatible allocator");
742 __tree_.__node_handle_merge_unique(__source.__tree_);
743 }
Louis Dionned2322c82018-11-01 14:41:37 +0000744 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000745 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +0000746 void merge(multiset<key_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000747 {
748 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
749 "merging container with incompatible allocator");
750 __tree_.__node_handle_merge_unique(__source.__tree_);
751 }
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000752#endif
753
Howard Hinnant192cf032010-09-23 16:27:36 +0000754 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000755 void swap(set& __s) _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
756 {__tree_.swap(__s.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000757
Howard Hinnant192cf032010-09-23 16:27:36 +0000758 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000759 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000760 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000761 key_compare key_comp() const {return __tree_.value_comp();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000762 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000763 value_compare value_comp() const {return __tree_.value_comp();}
764
765 // set operations:
Howard Hinnant192cf032010-09-23 16:27:36 +0000766 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000767 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000768 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000769 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000770#if _LIBCPP_STD_VER > 11
771 template <typename _K2>
772 _LIBCPP_INLINE_VISIBILITY
773 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
774 find(const _K2& __k) {return __tree_.find(__k);}
775 template <typename _K2>
776 _LIBCPP_INLINE_VISIBILITY
777 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
778 find(const _K2& __k) const {return __tree_.find(__k);}
779#endif
780
Howard Hinnant192cf032010-09-23 16:27:36 +0000781 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000782 size_type count(const key_type& __k) const
783 {return __tree_.__count_unique(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +0000784#if _LIBCPP_STD_VER > 11
785 template <typename _K2>
786 _LIBCPP_INLINE_VISIBILITY
787 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +0000788 count(const _K2& __k) const {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +0000789#endif
Howard Hinnant192cf032010-09-23 16:27:36 +0000790 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000791 iterator lower_bound(const key_type& __k)
792 {return __tree_.lower_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000793 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000794 const_iterator lower_bound(const key_type& __k) const
795 {return __tree_.lower_bound(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000796#if _LIBCPP_STD_VER > 11
797 template <typename _K2>
798 _LIBCPP_INLINE_VISIBILITY
799 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
800 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
801
802 template <typename _K2>
803 _LIBCPP_INLINE_VISIBILITY
804 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
805 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
806#endif
807
Howard Hinnant192cf032010-09-23 16:27:36 +0000808 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000809 iterator upper_bound(const key_type& __k)
810 {return __tree_.upper_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000811 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000812 const_iterator upper_bound(const key_type& __k) const
813 {return __tree_.upper_bound(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000814#if _LIBCPP_STD_VER > 11
815 template <typename _K2>
816 _LIBCPP_INLINE_VISIBILITY
817 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
818 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
819 template <typename _K2>
820 _LIBCPP_INLINE_VISIBILITY
821 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
822 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
823#endif
824
Howard Hinnant192cf032010-09-23 16:27:36 +0000825 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000826 pair<iterator,iterator> equal_range(const key_type& __k)
827 {return __tree_.__equal_range_unique(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000828 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000829 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
830 {return __tree_.__equal_range_unique(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000831#if _LIBCPP_STD_VER > 11
832 template <typename _K2>
833 _LIBCPP_INLINE_VISIBILITY
834 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +0000835 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000836 template <typename _K2>
837 _LIBCPP_INLINE_VISIBILITY
838 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +0000839 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000840#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000841};
842
Louis Dionne27ecc152019-06-11 18:21:08 +0000843#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
844template<class _InputIterator,
845 class _Compare = less<typename iterator_traits<_InputIterator>::value_type>,
846 class _Allocator = allocator<typename iterator_traits<_InputIterator>::value_type>,
847 class = typename enable_if<__is_allocator<_Allocator>::value, void>::type,
848 class = typename enable_if<!__is_allocator<_Compare>::value, void>::type>
849set(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
850 -> set<typename iterator_traits<_InputIterator>::value_type, _Compare, _Allocator>;
851
852template<class _Key, class _Compare = less<_Key>,
853 class _Allocator = allocator<_Key>,
854 class = typename enable_if<__is_allocator<_Allocator>::value, void>::type,
855 class = typename enable_if<!__is_allocator<_Compare>::value, void>::type>
856set(initializer_list<_Key>, _Compare = _Compare(), _Allocator = _Allocator())
857 -> set<_Key, _Compare, _Allocator>;
858
859template<class _InputIterator, class _Allocator,
860 class = typename enable_if<__is_allocator<_Allocator>::value, void>::type>
861set(_InputIterator, _InputIterator, _Allocator)
862 -> set<typename iterator_traits<_InputIterator>::value_type,
863 less<typename iterator_traits<_InputIterator>::value_type>, _Allocator>;
864
865template<class _Key, class _Allocator,
866 class = typename enable_if<__is_allocator<_Allocator>::value, void>::type>
867set(initializer_list<_Key>, _Allocator)
868 -> set<_Key, less<_Key>, _Allocator>;
869#endif
870
Eric Fiselier615961b2017-04-18 20:58:03 +0000871#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000872
873template <class _Key, class _Compare, class _Allocator>
874set<_Key, _Compare, _Allocator>::set(set&& __s, const allocator_type& __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000875 : __tree_(_VSTD::move(__s.__tree_), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000876{
877 if (__a != __s.get_allocator())
878 {
879 const_iterator __e = cend();
880 while (!__s.empty())
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000881 insert(__e, _VSTD::move(__s.__tree_.remove(__s.begin())->__value_));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000882 }
883}
884
Eric Fiselier615961b2017-04-18 20:58:03 +0000885#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000886
887template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000888inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000889bool
890operator==(const set<_Key, _Compare, _Allocator>& __x,
891 const set<_Key, _Compare, _Allocator>& __y)
892{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000893 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000894}
895
896template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000897inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000898bool
899operator< (const set<_Key, _Compare, _Allocator>& __x,
900 const set<_Key, _Compare, _Allocator>& __y)
901{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000902 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000903}
904
905template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000906inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000907bool
908operator!=(const set<_Key, _Compare, _Allocator>& __x,
909 const set<_Key, _Compare, _Allocator>& __y)
910{
911 return !(__x == __y);
912}
913
914template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000915inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000916bool
917operator> (const set<_Key, _Compare, _Allocator>& __x,
918 const set<_Key, _Compare, _Allocator>& __y)
919{
920 return __y < __x;
921}
922
923template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000924inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000925bool
926operator>=(const set<_Key, _Compare, _Allocator>& __x,
927 const set<_Key, _Compare, _Allocator>& __y)
928{
929 return !(__x < __y);
930}
931
932template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000933inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000934bool
935operator<=(const set<_Key, _Compare, _Allocator>& __x,
936 const set<_Key, _Compare, _Allocator>& __y)
937{
938 return !(__y < __x);
939}
940
941// specialized algorithms:
942template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000943inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000944void
945swap(set<_Key, _Compare, _Allocator>& __x,
946 set<_Key, _Compare, _Allocator>& __y)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000947 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000948{
949 __x.swap(__y);
950}
951
Marshall Clow29b53f22018-12-14 18:49:35 +0000952#if _LIBCPP_STD_VER > 17
953template <class _Key, class _Compare, class _Allocator, class _Predicate>
954inline _LIBCPP_INLINE_VISIBILITY
955void erase_if(set<_Key, _Compare, _Allocator>& __c, _Predicate __pred)
956{ __libcpp_erase_if_container(__c, __pred); }
957#endif
958
Howard Hinnantc51e1022010-05-11 19:42:16 +0000959template <class _Key, class _Compare = less<_Key>,
960 class _Allocator = allocator<_Key> >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000961class _LIBCPP_TEMPLATE_VIS multiset
Howard Hinnantc51e1022010-05-11 19:42:16 +0000962{
963public:
964 // types:
965 typedef _Key key_type;
966 typedef key_type value_type;
967 typedef _Compare key_compare;
968 typedef key_compare value_compare;
Louis Dionne27ecc152019-06-11 18:21:08 +0000969 typedef typename __identity<_Allocator>::type allocator_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000970 typedef value_type& reference;
971 typedef const value_type& const_reference;
972
Marshall Clow5128cf32015-11-26 01:24:04 +0000973 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
974 "Allocator::value_type must be same type as value_type");
975
Howard Hinnantc51e1022010-05-11 19:42:16 +0000976private:
977 typedef __tree<value_type, value_compare, allocator_type> __base;
978 typedef allocator_traits<allocator_type> __alloc_traits;
979 typedef typename __base::__node_holder __node_holder;
980
981 __base __tree_;
982
983public:
984 typedef typename __base::pointer pointer;
985 typedef typename __base::const_pointer const_pointer;
986 typedef typename __base::size_type size_type;
987 typedef typename __base::difference_type difference_type;
988 typedef typename __base::const_iterator iterator;
989 typedef typename __base::const_iterator const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000990 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
991 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000992
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000993#if _LIBCPP_STD_VER > 14
994 typedef __set_node_handle<typename __base::__node, allocator_type> node_type;
995#endif
996
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000997 template <class _Key2, class _Compare2, class _Alloc2>
998 friend class _LIBCPP_TEMPLATE_VIS set;
999 template <class _Key2, class _Compare2, class _Alloc2>
1000 friend class _LIBCPP_TEMPLATE_VIS multiset;
1001
Howard Hinnantc51e1022010-05-11 19:42:16 +00001002 // construct/copy/destroy:
Howard Hinnant192cf032010-09-23 16:27:36 +00001003 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +00001004 multiset()
1005 _NOEXCEPT_(
1006 is_nothrow_default_constructible<allocator_type>::value &&
1007 is_nothrow_default_constructible<key_compare>::value &&
1008 is_nothrow_copy_constructible<key_compare>::value)
1009 : __tree_(value_compare()) {}
1010
1011 _LIBCPP_INLINE_VISIBILITY
1012 explicit multiset(const value_compare& __comp)
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001013 _NOEXCEPT_(
1014 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001015 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001016 : __tree_(__comp) {}
Marshall Clow7086a5a2014-03-10 04:50:10 +00001017
Howard Hinnant192cf032010-09-23 16:27:36 +00001018 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7ed23a72014-03-05 19:06:20 +00001019 explicit multiset(const value_compare& __comp, const allocator_type& __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001020 : __tree_(__comp, __a) {}
1021 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001022 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001023 multiset(_InputIterator __f, _InputIterator __l,
1024 const value_compare& __comp = value_compare())
1025 : __tree_(__comp)
1026 {
1027 insert(__f, __l);
1028 }
1029
Marshall Clow631788a2013-09-11 00:06:45 +00001030#if _LIBCPP_STD_VER > 11
1031 template <class _InputIterator>
Louis Dionned2322c82018-11-01 14:41:37 +00001032 _LIBCPP_INLINE_VISIBILITY
Marshall Clow631788a2013-09-11 00:06:45 +00001033 multiset(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
1034 : multiset(__f, __l, key_compare(), __a) {}
1035#endif
1036
Howard Hinnantc51e1022010-05-11 19:42:16 +00001037 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001038 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001039 multiset(_InputIterator __f, _InputIterator __l,
1040 const value_compare& __comp, const allocator_type& __a)
1041 : __tree_(__comp, __a)
1042 {
1043 insert(__f, __l);
1044 }
1045
Howard Hinnant192cf032010-09-23 16:27:36 +00001046 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001047 multiset(const multiset& __s)
1048 : __tree_(__s.__tree_.value_comp(),
1049 __alloc_traits::select_on_container_copy_construction(__s.__tree_.__alloc()))
1050 {
1051 insert(__s.begin(), __s.end());
1052 }
1053
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001054 _LIBCPP_INLINE_VISIBILITY
1055 multiset& operator=(const multiset& __s)
1056 {
1057 __tree_ = __s.__tree_;
1058 return *this;
1059 }
1060
Eric Fiselier615961b2017-04-18 20:58:03 +00001061#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant192cf032010-09-23 16:27:36 +00001062 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001063 multiset(multiset&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001064 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001065 : __tree_(_VSTD::move(__s.__tree_)) {}
Eric Fiselier615961b2017-04-18 20:58:03 +00001066
1067 multiset(multiset&& __s, const allocator_type& __a);
1068#endif // _LIBCPP_CXX03_LANG
Howard Hinnant192cf032010-09-23 16:27:36 +00001069 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001070 explicit multiset(const allocator_type& __a)
1071 : __tree_(__a) {}
Howard Hinnant192cf032010-09-23 16:27:36 +00001072 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001073 multiset(const multiset& __s, const allocator_type& __a)
1074 : __tree_(__s.__tree_.value_comp(), __a)
1075 {
1076 insert(__s.begin(), __s.end());
1077 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001078
Eric Fiselier615961b2017-04-18 20:58:03 +00001079#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant192cf032010-09-23 16:27:36 +00001080 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001081 multiset(initializer_list<value_type> __il, const value_compare& __comp = value_compare())
1082 : __tree_(__comp)
1083 {
1084 insert(__il.begin(), __il.end());
1085 }
1086
Howard Hinnant192cf032010-09-23 16:27:36 +00001087 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001088 multiset(initializer_list<value_type> __il, const value_compare& __comp,
1089 const allocator_type& __a)
1090 : __tree_(__comp, __a)
1091 {
1092 insert(__il.begin(), __il.end());
1093 }
1094
Marshall Clow631788a2013-09-11 00:06:45 +00001095#if _LIBCPP_STD_VER > 11
Louis Dionned2322c82018-11-01 14:41:37 +00001096 _LIBCPP_INLINE_VISIBILITY
Marshall Clow631788a2013-09-11 00:06:45 +00001097 multiset(initializer_list<value_type> __il, const allocator_type& __a)
1098 : multiset(__il, key_compare(), __a) {}
1099#endif
1100
Howard Hinnant192cf032010-09-23 16:27:36 +00001101 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001102 multiset& operator=(initializer_list<value_type> __il)
1103 {
1104 __tree_.__assign_multi(__il.begin(), __il.end());
1105 return *this;
1106 }
1107
Howard Hinnant192cf032010-09-23 16:27:36 +00001108 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001109 multiset& operator=(multiset&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001110 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001111 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001112 __tree_ = _VSTD::move(__s.__tree_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001113 return *this;
1114 }
Eric Fiselier615961b2017-04-18 20:58:03 +00001115#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001116
Howard Hinnant192cf032010-09-23 16:27:36 +00001117 _LIBCPP_INLINE_VISIBILITY
Louis Dionne69c42c02019-04-11 16:14:56 +00001118 ~multiset() {
1119 static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), "");
1120 }
1121
1122 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001123 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001124 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001125 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001126 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001127 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001128 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001129 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001130
Howard Hinnant192cf032010-09-23 16:27:36 +00001131 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001132 reverse_iterator rbegin() _NOEXCEPT
1133 {return reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +00001134 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001135 const_reverse_iterator rbegin() const _NOEXCEPT
1136 {return const_reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +00001137 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001138 reverse_iterator rend() _NOEXCEPT
1139 {return reverse_iterator(begin());}
Howard Hinnant192cf032010-09-23 16:27:36 +00001140 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001141 const_reverse_iterator rend() const _NOEXCEPT
1142 {return const_reverse_iterator(begin());}
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 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001146 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001147 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001148 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001149 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001150 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001151 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001152
Marshall Clow425f5752017-11-15 05:51:26 +00001153 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001154 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant192cf032010-09-23 16:27:36 +00001155 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001156 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001157 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001158 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001159
1160 // modifiers:
Eric Fiselier615961b2017-04-18 20:58:03 +00001161#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001162 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +00001163 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001164 iterator emplace(_Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001165 {return __tree_.__emplace_multi(_VSTD::forward<_Args>(__args)...);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001166 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +00001167 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001168 iterator emplace_hint(const_iterator __p, _Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001169 {return __tree_.__emplace_hint_multi(__p, _VSTD::forward<_Args>(__args)...);}
Eric Fiselier615961b2017-04-18 20:58:03 +00001170#endif // _LIBCPP_CXX03_LANG
1171
Howard Hinnant192cf032010-09-23 16:27:36 +00001172 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001173 iterator insert(const value_type& __v)
1174 {return __tree_.__insert_multi(__v);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001175 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001176 iterator insert(const_iterator __p, const value_type& __v)
1177 {return __tree_.__insert_multi(__p, __v);}
Eric Fiselier615961b2017-04-18 20:58:03 +00001178
Howard Hinnantc51e1022010-05-11 19:42:16 +00001179 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001180 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001181 void insert(_InputIterator __f, _InputIterator __l)
1182 {
1183 for (const_iterator __e = cend(); __f != __l; ++__f)
1184 __tree_.__insert_multi(__e, *__f);
1185 }
1186
Eric Fiselier615961b2017-04-18 20:58:03 +00001187#ifndef _LIBCPP_CXX03_LANG
1188 _LIBCPP_INLINE_VISIBILITY
1189 iterator insert(value_type&& __v)
1190 {return __tree_.__insert_multi(_VSTD::move(__v));}
1191
1192 _LIBCPP_INLINE_VISIBILITY
1193 iterator insert(const_iterator __p, value_type&& __v)
1194 {return __tree_.__insert_multi(__p, _VSTD::move(__v));}
1195
Howard Hinnant192cf032010-09-23 16:27:36 +00001196 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001197 void insert(initializer_list<value_type> __il)
1198 {insert(__il.begin(), __il.end());}
Eric Fiselier615961b2017-04-18 20:58:03 +00001199#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001200
Howard Hinnant192cf032010-09-23 16:27:36 +00001201 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001202 iterator erase(const_iterator __p) {return __tree_.erase(__p);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001203 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001204 size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001205 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001206 iterator erase(const_iterator __f, const_iterator __l)
1207 {return __tree_.erase(__f, __l);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001208 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001209 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001210
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001211#if _LIBCPP_STD_VER > 14
1212 _LIBCPP_INLINE_VISIBILITY
1213 iterator insert(node_type&& __nh)
1214 {
1215 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1216 "node_type with incompatible allocator passed to multiset::insert()");
1217 return __tree_.template __node_handle_insert_multi<node_type>(
1218 _VSTD::move(__nh));
1219 }
1220 _LIBCPP_INLINE_VISIBILITY
1221 iterator insert(const_iterator __hint, node_type&& __nh)
1222 {
1223 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1224 "node_type with incompatible allocator passed to multiset::insert()");
1225 return __tree_.template __node_handle_insert_multi<node_type>(
1226 __hint, _VSTD::move(__nh));
1227 }
1228 _LIBCPP_INLINE_VISIBILITY
1229 node_type extract(key_type const& __key)
1230 {
1231 return __tree_.template __node_handle_extract<node_type>(__key);
1232 }
1233 _LIBCPP_INLINE_VISIBILITY
1234 node_type extract(const_iterator __it)
1235 {
1236 return __tree_.template __node_handle_extract<node_type>(__it);
1237 }
Louis Dionned2322c82018-11-01 14:41:37 +00001238 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001239 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001240 void merge(multiset<key_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001241 {
1242 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1243 "merging container with incompatible allocator");
1244 __tree_.__node_handle_merge_multi(__source.__tree_);
1245 }
Louis Dionned2322c82018-11-01 14:41:37 +00001246 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001247 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001248 void merge(multiset<key_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001249 {
1250 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1251 "merging container with incompatible allocator");
1252 __tree_.__node_handle_merge_multi(__source.__tree_);
1253 }
Louis Dionned2322c82018-11-01 14:41:37 +00001254 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001255 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001256 void merge(set<key_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001257 {
1258 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1259 "merging container with incompatible allocator");
1260 __tree_.__node_handle_merge_multi(__source.__tree_);
1261 }
Louis Dionned2322c82018-11-01 14:41:37 +00001262 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001263 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001264 void merge(set<key_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001265 {
1266 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1267 "merging container with incompatible allocator");
1268 __tree_.__node_handle_merge_multi(__source.__tree_);
1269 }
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001270#endif
1271
Howard Hinnant192cf032010-09-23 16:27:36 +00001272 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001273 void swap(multiset& __s)
1274 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1275 {__tree_.swap(__s.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001276
Howard Hinnant192cf032010-09-23 16:27:36 +00001277 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001278 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001279 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001280 key_compare key_comp() const {return __tree_.value_comp();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001281 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001282 value_compare value_comp() const {return __tree_.value_comp();}
1283
1284 // set operations:
Howard Hinnant192cf032010-09-23 16:27:36 +00001285 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001286 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001287 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001288 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +00001289#if _LIBCPP_STD_VER > 11
1290 template <typename _K2>
1291 _LIBCPP_INLINE_VISIBILITY
1292 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,iterator>::type
1293 find(const _K2& __k) {return __tree_.find(__k);}
1294 template <typename _K2>
1295 _LIBCPP_INLINE_VISIBILITY
1296 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,const_iterator>::type
1297 find(const _K2& __k) const {return __tree_.find(__k);}
1298#endif
1299
Howard Hinnant192cf032010-09-23 16:27:36 +00001300 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001301 size_type count(const key_type& __k) const
1302 {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001303#if _LIBCPP_STD_VER > 11
1304 template <typename _K2>
1305 _LIBCPP_INLINE_VISIBILITY
1306 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
Marshall Clow5571bcd2018-01-07 17:39:57 +00001307 count(const _K2& __k) const {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001308#endif
Marshall Clowc0152142013-08-13 01:11:06 +00001309
Howard Hinnant192cf032010-09-23 16:27:36 +00001310 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001311 iterator lower_bound(const key_type& __k)
1312 {return __tree_.lower_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001313 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001314 const_iterator lower_bound(const key_type& __k) const
1315 {return __tree_.lower_bound(__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 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
1321
1322 template <typename _K2>
1323 _LIBCPP_INLINE_VISIBILITY
1324 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,const_iterator>::type
1325 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
1326#endif
1327
Howard Hinnant192cf032010-09-23 16:27:36 +00001328 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001329 iterator upper_bound(const key_type& __k)
1330 {return __tree_.upper_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001331 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001332 const_iterator upper_bound(const key_type& __k) const
1333 {return __tree_.upper_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 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
1339 template <typename _K2>
1340 _LIBCPP_INLINE_VISIBILITY
1341 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,const_iterator>::type
1342 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
1343#endif
1344
Howard Hinnant192cf032010-09-23 16:27:36 +00001345 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001346 pair<iterator,iterator> equal_range(const key_type& __k)
1347 {return __tree_.__equal_range_multi(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001348 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001349 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
1350 {return __tree_.__equal_range_multi(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +00001351#if _LIBCPP_STD_VER > 11
1352 template <typename _K2>
1353 _LIBCPP_INLINE_VISIBILITY
1354 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
1355 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
1356 template <typename _K2>
1357 _LIBCPP_INLINE_VISIBILITY
1358 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
1359 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
1360#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001361};
1362
Louis Dionne27ecc152019-06-11 18:21:08 +00001363#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
1364template<class _InputIterator,
1365 class _Compare = less<typename iterator_traits<_InputIterator>::value_type>,
1366 class _Allocator = allocator<typename iterator_traits<_InputIterator>::value_type>,
1367 class = typename enable_if<__is_allocator<_Allocator>::value, void>::type,
1368 class = typename enable_if<!__is_allocator<_Compare>::value, void>::type>
1369multiset(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
1370 -> multiset<typename iterator_traits<_InputIterator>::value_type, _Compare, _Allocator>;
1371
1372template<class _Key, class _Compare = less<_Key>,
1373 class _Allocator = allocator<_Key>,
1374 class = typename enable_if<__is_allocator<_Allocator>::value, void>::type,
1375 class = typename enable_if<!__is_allocator<_Compare>::value, void>::type>
1376multiset(initializer_list<_Key>, _Compare = _Compare(), _Allocator = _Allocator())
1377 -> multiset<_Key, _Compare, _Allocator>;
1378
1379template<class _InputIterator, class _Allocator,
1380 class = typename enable_if<__is_allocator<_Allocator>::value, void>::type>
1381multiset(_InputIterator, _InputIterator, _Allocator)
1382 -> multiset<typename iterator_traits<_InputIterator>::value_type,
1383 less<typename iterator_traits<_InputIterator>::value_type>, _Allocator>;
1384
1385template<class _Key, class _Allocator,
1386 class = typename enable_if<__is_allocator<_Allocator>::value, void>::type>
1387multiset(initializer_list<_Key>, _Allocator)
1388 -> multiset<_Key, less<_Key>, _Allocator>;
1389#endif
1390
Eric Fiselier615961b2017-04-18 20:58:03 +00001391#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001392
1393template <class _Key, class _Compare, class _Allocator>
1394multiset<_Key, _Compare, _Allocator>::multiset(multiset&& __s, const allocator_type& __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001395 : __tree_(_VSTD::move(__s.__tree_), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001396{
1397 if (__a != __s.get_allocator())
1398 {
1399 const_iterator __e = cend();
1400 while (!__s.empty())
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001401 insert(__e, _VSTD::move(__s.__tree_.remove(__s.begin())->__value_));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001402 }
1403}
1404
Eric Fiselier615961b2017-04-18 20:58:03 +00001405#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001406
1407template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001408inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001409bool
1410operator==(const multiset<_Key, _Compare, _Allocator>& __x,
1411 const multiset<_Key, _Compare, _Allocator>& __y)
1412{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001413 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001414}
1415
1416template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001417inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001418bool
1419operator< (const multiset<_Key, _Compare, _Allocator>& __x,
1420 const multiset<_Key, _Compare, _Allocator>& __y)
1421{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001422 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001423}
1424
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{
1431 return !(__x == __y);
1432}
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{
1440 return __y < __x;
1441}
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 +00001463void
1464swap(multiset<_Key, _Compare, _Allocator>& __x,
1465 multiset<_Key, _Compare, _Allocator>& __y)
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001466 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001467{
1468 __x.swap(__y);
1469}
1470
Marshall Clow29b53f22018-12-14 18:49:35 +00001471#if _LIBCPP_STD_VER > 17
1472template <class _Key, class _Compare, class _Allocator, class _Predicate>
1473inline _LIBCPP_INLINE_VISIBILITY
1474void erase_if(multiset<_Key, _Compare, _Allocator>& __c, _Predicate __pred)
1475{ __libcpp_erase_if_container(__c, __pred); }
1476#endif
1477
Howard Hinnantc51e1022010-05-11 19:42:16 +00001478_LIBCPP_END_NAMESPACE_STD
1479
1480#endif // _LIBCPP_SET