blob: 17837228f266da24fe616fe1877284ad03444ba3 [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;
449 typedef _Allocator allocator_type;
450 typedef value_type& reference;
451 typedef const value_type& const_reference;
452
Louis Dionne878a3a82018-12-06 21:46:17 +0000453 static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), "");
Marshall Clow5128cf32015-11-26 01:24:04 +0000454 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
455 "Allocator::value_type must be same type as value_type");
456
Howard Hinnantc51e1022010-05-11 19:42:16 +0000457private:
458 typedef __tree<value_type, value_compare, allocator_type> __base;
459 typedef allocator_traits<allocator_type> __alloc_traits;
460 typedef typename __base::__node_holder __node_holder;
461
462 __base __tree_;
463
464public:
465 typedef typename __base::pointer pointer;
466 typedef typename __base::const_pointer const_pointer;
467 typedef typename __base::size_type size_type;
468 typedef typename __base::difference_type difference_type;
469 typedef typename __base::const_iterator iterator;
470 typedef typename __base::const_iterator const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000471 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
472 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000473
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000474#if _LIBCPP_STD_VER > 14
475 typedef __set_node_handle<typename __base::__node, allocator_type> node_type;
476 typedef __insert_return_type<iterator, node_type> insert_return_type;
477#endif
478
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000479 template <class _Key2, class _Compare2, class _Alloc2>
480 friend class _LIBCPP_TEMPLATE_VIS set;
481 template <class _Key2, class _Compare2, class _Alloc2>
482 friend class _LIBCPP_TEMPLATE_VIS multiset;
483
Howard Hinnant192cf032010-09-23 16:27:36 +0000484 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +0000485 set()
486 _NOEXCEPT_(
487 is_nothrow_default_constructible<allocator_type>::value &&
488 is_nothrow_default_constructible<key_compare>::value &&
489 is_nothrow_copy_constructible<key_compare>::value)
490 : __tree_(value_compare()) {}
491
492 _LIBCPP_INLINE_VISIBILITY
493 explicit set(const value_compare& __comp)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000494 _NOEXCEPT_(
495 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000496 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000497 : __tree_(__comp) {}
Marshall Clow7086a5a2014-03-10 04:50:10 +0000498
Howard Hinnant192cf032010-09-23 16:27:36 +0000499 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7ed23a72014-03-05 19:06:20 +0000500 explicit set(const value_compare& __comp, const allocator_type& __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000501 : __tree_(__comp, __a) {}
502 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000503 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000504 set(_InputIterator __f, _InputIterator __l,
505 const value_compare& __comp = value_compare())
506 : __tree_(__comp)
507 {
508 insert(__f, __l);
509 }
510
511 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000512 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000513 set(_InputIterator __f, _InputIterator __l, const value_compare& __comp,
514 const allocator_type& __a)
515 : __tree_(__comp, __a)
516 {
517 insert(__f, __l);
518 }
519
Marshall Clow631788a2013-09-11 00:06:45 +0000520#if _LIBCPP_STD_VER > 11
521 template <class _InputIterator>
Louis Dionned2322c82018-11-01 14:41:37 +0000522 _LIBCPP_INLINE_VISIBILITY
Marshall Clow631788a2013-09-11 00:06:45 +0000523 set(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
524 : set(__f, __l, key_compare(), __a) {}
525#endif
526
Howard Hinnant192cf032010-09-23 16:27:36 +0000527 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000528 set(const set& __s)
529 : __tree_(__s.__tree_)
530 {
531 insert(__s.begin(), __s.end());
532 }
533
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000534 _LIBCPP_INLINE_VISIBILITY
535 set& operator=(const set& __s)
536 {
537 __tree_ = __s.__tree_;
538 return *this;
539 }
540
Eric Fiselier615961b2017-04-18 20:58:03 +0000541#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant192cf032010-09-23 16:27:36 +0000542 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000543 set(set&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000544 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000545 : __tree_(_VSTD::move(__s.__tree_)) {}
Eric Fiselier615961b2017-04-18 20:58:03 +0000546#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000547
Howard Hinnant192cf032010-09-23 16:27:36 +0000548 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000549 explicit set(const allocator_type& __a)
550 : __tree_(__a) {}
551
Howard Hinnant192cf032010-09-23 16:27:36 +0000552 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000553 set(const set& __s, const allocator_type& __a)
554 : __tree_(__s.__tree_.value_comp(), __a)
555 {
556 insert(__s.begin(), __s.end());
557 }
558
Eric Fiselier615961b2017-04-18 20:58:03 +0000559#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000560 set(set&& __s, const allocator_type& __a);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000561
Howard Hinnant192cf032010-09-23 16:27:36 +0000562 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000563 set(initializer_list<value_type> __il, const value_compare& __comp = value_compare())
564 : __tree_(__comp)
565 {
566 insert(__il.begin(), __il.end());
567 }
568
Howard Hinnant192cf032010-09-23 16:27:36 +0000569 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000570 set(initializer_list<value_type> __il, const value_compare& __comp,
571 const allocator_type& __a)
572 : __tree_(__comp, __a)
573 {
574 insert(__il.begin(), __il.end());
575 }
576
Marshall Clow631788a2013-09-11 00:06:45 +0000577#if _LIBCPP_STD_VER > 11
Louis Dionned2322c82018-11-01 14:41:37 +0000578 _LIBCPP_INLINE_VISIBILITY
Marshall Clow631788a2013-09-11 00:06:45 +0000579 set(initializer_list<value_type> __il, const allocator_type& __a)
580 : set(__il, key_compare(), __a) {}
581#endif
582
Howard Hinnant192cf032010-09-23 16:27:36 +0000583 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000584 set& operator=(initializer_list<value_type> __il)
585 {
586 __tree_.__assign_unique(__il.begin(), __il.end());
587 return *this;
588 }
589
Howard Hinnant192cf032010-09-23 16:27:36 +0000590 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000591 set& operator=(set&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000592 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000593 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000594 __tree_ = _VSTD::move(__s.__tree_);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000595 return *this;
596 }
Eric Fiselier615961b2017-04-18 20:58:03 +0000597#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000598
Howard Hinnant192cf032010-09-23 16:27:36 +0000599 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000600 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000601 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000602 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000603 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000604 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000605 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000606 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000607
Howard Hinnant192cf032010-09-23 16:27:36 +0000608 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000609 reverse_iterator rbegin() _NOEXCEPT
610 {return reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +0000611 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000612 const_reverse_iterator rbegin() const _NOEXCEPT
613 {return const_reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +0000614 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000615 reverse_iterator rend() _NOEXCEPT
616 {return reverse_iterator(begin());}
Howard Hinnant192cf032010-09-23 16:27:36 +0000617 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000618 const_reverse_iterator rend() const _NOEXCEPT
619 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000620
Howard Hinnant192cf032010-09-23 16:27:36 +0000621 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000622 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000623 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000624 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000625 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000626 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000627 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000628 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000629
Marshall Clow425f5752017-11-15 05:51:26 +0000630 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000631 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant192cf032010-09-23 16:27:36 +0000632 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000633 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000634 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000635 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000636
637 // modifiers:
Eric Fiselier615961b2017-04-18 20:58:03 +0000638#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000639 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +0000640 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000641 pair<iterator, bool> emplace(_Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000642 {return __tree_.__emplace_unique(_VSTD::forward<_Args>(__args)...);}
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 iterator emplace_hint(const_iterator __p, _Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000646 {return __tree_.__emplace_hint_unique(__p, _VSTD::forward<_Args>(__args)...);}
Eric Fiselier615961b2017-04-18 20:58:03 +0000647#endif // _LIBCPP_CXX03_LANG
648
Howard Hinnant192cf032010-09-23 16:27:36 +0000649 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000650 pair<iterator,bool> insert(const value_type& __v)
651 {return __tree_.__insert_unique(__v);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000652 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000653 iterator insert(const_iterator __p, const value_type& __v)
654 {return __tree_.__insert_unique(__p, __v);}
Eric Fiselier615961b2017-04-18 20:58:03 +0000655
Howard Hinnantc51e1022010-05-11 19:42:16 +0000656 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000657 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000658 void insert(_InputIterator __f, _InputIterator __l)
659 {
660 for (const_iterator __e = cend(); __f != __l; ++__f)
661 __tree_.__insert_unique(__e, *__f);
662 }
663
Eric Fiselier615961b2017-04-18 20:58:03 +0000664#ifndef _LIBCPP_CXX03_LANG
665 _LIBCPP_INLINE_VISIBILITY
666 pair<iterator,bool> insert(value_type&& __v)
667 {return __tree_.__insert_unique(_VSTD::move(__v));}
668
669 _LIBCPP_INLINE_VISIBILITY
670 iterator insert(const_iterator __p, value_type&& __v)
671 {return __tree_.__insert_unique(__p, _VSTD::move(__v));}
672
Howard Hinnant192cf032010-09-23 16:27:36 +0000673 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000674 void insert(initializer_list<value_type> __il)
675 {insert(__il.begin(), __il.end());}
Eric Fiselier615961b2017-04-18 20:58:03 +0000676#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000677
Howard Hinnant192cf032010-09-23 16:27:36 +0000678 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000679 iterator erase(const_iterator __p) {return __tree_.erase(__p);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000680 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000681 size_type erase(const key_type& __k)
682 {return __tree_.__erase_unique(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000683 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000684 iterator erase(const_iterator __f, const_iterator __l)
685 {return __tree_.erase(__f, __l);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000686 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000687 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000688
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000689#if _LIBCPP_STD_VER > 14
690 _LIBCPP_INLINE_VISIBILITY
691 insert_return_type insert(node_type&& __nh)
692 {
693 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
694 "node_type with incompatible allocator passed to set::insert()");
695 return __tree_.template __node_handle_insert_unique<
696 node_type, insert_return_type>(_VSTD::move(__nh));
697 }
698 _LIBCPP_INLINE_VISIBILITY
699 iterator insert(const_iterator __hint, node_type&& __nh)
700 {
701 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
702 "node_type with incompatible allocator passed to set::insert()");
703 return __tree_.template __node_handle_insert_unique<node_type>(
704 __hint, _VSTD::move(__nh));
705 }
706 _LIBCPP_INLINE_VISIBILITY
707 node_type extract(key_type const& __key)
708 {
709 return __tree_.template __node_handle_extract<node_type>(__key);
710 }
711 _LIBCPP_INLINE_VISIBILITY
712 node_type extract(const_iterator __it)
713 {
714 return __tree_.template __node_handle_extract<node_type>(__it);
715 }
Louis Dionned2322c82018-11-01 14:41:37 +0000716 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000717 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +0000718 void merge(set<key_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000719 {
720 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
721 "merging container with incompatible allocator");
722 __tree_.__node_handle_merge_unique(__source.__tree_);
723 }
Louis Dionned2322c82018-11-01 14:41:37 +0000724 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000725 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +0000726 void merge(set<key_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000727 {
728 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
729 "merging container with incompatible allocator");
730 __tree_.__node_handle_merge_unique(__source.__tree_);
731 }
Louis Dionned2322c82018-11-01 14:41:37 +0000732 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000733 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +0000734 void merge(multiset<key_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000735 {
736 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
737 "merging container with incompatible allocator");
738 __tree_.__node_handle_merge_unique(__source.__tree_);
739 }
Louis Dionned2322c82018-11-01 14:41:37 +0000740 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000741 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +0000742 void merge(multiset<key_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000743 {
744 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
745 "merging container with incompatible allocator");
746 __tree_.__node_handle_merge_unique(__source.__tree_);
747 }
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000748#endif
749
Howard Hinnant192cf032010-09-23 16:27:36 +0000750 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000751 void swap(set& __s) _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
752 {__tree_.swap(__s.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000753
Howard Hinnant192cf032010-09-23 16:27:36 +0000754 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000755 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000756 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000757 key_compare key_comp() const {return __tree_.value_comp();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000758 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000759 value_compare value_comp() const {return __tree_.value_comp();}
760
761 // set operations:
Howard Hinnant192cf032010-09-23 16:27:36 +0000762 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000763 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000764 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000765 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000766#if _LIBCPP_STD_VER > 11
767 template <typename _K2>
768 _LIBCPP_INLINE_VISIBILITY
769 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
770 find(const _K2& __k) {return __tree_.find(__k);}
771 template <typename _K2>
772 _LIBCPP_INLINE_VISIBILITY
773 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
774 find(const _K2& __k) const {return __tree_.find(__k);}
775#endif
776
Howard Hinnant192cf032010-09-23 16:27:36 +0000777 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000778 size_type count(const key_type& __k) const
779 {return __tree_.__count_unique(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +0000780#if _LIBCPP_STD_VER > 11
781 template <typename _K2>
782 _LIBCPP_INLINE_VISIBILITY
783 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +0000784 count(const _K2& __k) const {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +0000785#endif
Howard Hinnant192cf032010-09-23 16:27:36 +0000786 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000787 iterator lower_bound(const key_type& __k)
788 {return __tree_.lower_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000789 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000790 const_iterator lower_bound(const key_type& __k) const
791 {return __tree_.lower_bound(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000792#if _LIBCPP_STD_VER > 11
793 template <typename _K2>
794 _LIBCPP_INLINE_VISIBILITY
795 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
796 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
797
798 template <typename _K2>
799 _LIBCPP_INLINE_VISIBILITY
800 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
801 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
802#endif
803
Howard Hinnant192cf032010-09-23 16:27:36 +0000804 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000805 iterator upper_bound(const key_type& __k)
806 {return __tree_.upper_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000807 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000808 const_iterator upper_bound(const key_type& __k) const
809 {return __tree_.upper_bound(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000810#if _LIBCPP_STD_VER > 11
811 template <typename _K2>
812 _LIBCPP_INLINE_VISIBILITY
813 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
814 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
815 template <typename _K2>
816 _LIBCPP_INLINE_VISIBILITY
817 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
818 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
819#endif
820
Howard Hinnant192cf032010-09-23 16:27:36 +0000821 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000822 pair<iterator,iterator> equal_range(const key_type& __k)
823 {return __tree_.__equal_range_unique(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000824 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000825 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
826 {return __tree_.__equal_range_unique(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000827#if _LIBCPP_STD_VER > 11
828 template <typename _K2>
829 _LIBCPP_INLINE_VISIBILITY
830 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +0000831 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000832 template <typename _K2>
833 _LIBCPP_INLINE_VISIBILITY
834 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +0000835 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000836#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000837};
838
Eric Fiselier615961b2017-04-18 20:58:03 +0000839#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000840
841template <class _Key, class _Compare, class _Allocator>
842set<_Key, _Compare, _Allocator>::set(set&& __s, const allocator_type& __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000843 : __tree_(_VSTD::move(__s.__tree_), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000844{
845 if (__a != __s.get_allocator())
846 {
847 const_iterator __e = cend();
848 while (!__s.empty())
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000849 insert(__e, _VSTD::move(__s.__tree_.remove(__s.begin())->__value_));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000850 }
851}
852
Eric Fiselier615961b2017-04-18 20:58:03 +0000853#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000854
855template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000856inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000857bool
858operator==(const set<_Key, _Compare, _Allocator>& __x,
859 const set<_Key, _Compare, _Allocator>& __y)
860{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000861 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000862}
863
864template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000865inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000866bool
867operator< (const set<_Key, _Compare, _Allocator>& __x,
868 const set<_Key, _Compare, _Allocator>& __y)
869{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000870 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000871}
872
873template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000874inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000875bool
876operator!=(const set<_Key, _Compare, _Allocator>& __x,
877 const set<_Key, _Compare, _Allocator>& __y)
878{
879 return !(__x == __y);
880}
881
882template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000883inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000884bool
885operator> (const set<_Key, _Compare, _Allocator>& __x,
886 const set<_Key, _Compare, _Allocator>& __y)
887{
888 return __y < __x;
889}
890
891template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000892inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000893bool
894operator>=(const set<_Key, _Compare, _Allocator>& __x,
895 const set<_Key, _Compare, _Allocator>& __y)
896{
897 return !(__x < __y);
898}
899
900template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000901inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000902bool
903operator<=(const set<_Key, _Compare, _Allocator>& __x,
904 const set<_Key, _Compare, _Allocator>& __y)
905{
906 return !(__y < __x);
907}
908
909// specialized algorithms:
910template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000911inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000912void
913swap(set<_Key, _Compare, _Allocator>& __x,
914 set<_Key, _Compare, _Allocator>& __y)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000915 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000916{
917 __x.swap(__y);
918}
919
Marshall Clow29b53f22018-12-14 18:49:35 +0000920#if _LIBCPP_STD_VER > 17
921template <class _Key, class _Compare, class _Allocator, class _Predicate>
922inline _LIBCPP_INLINE_VISIBILITY
923void erase_if(set<_Key, _Compare, _Allocator>& __c, _Predicate __pred)
924{ __libcpp_erase_if_container(__c, __pred); }
925#endif
926
Howard Hinnantc51e1022010-05-11 19:42:16 +0000927template <class _Key, class _Compare = less<_Key>,
928 class _Allocator = allocator<_Key> >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000929class _LIBCPP_TEMPLATE_VIS multiset
Howard Hinnantc51e1022010-05-11 19:42:16 +0000930{
931public:
932 // types:
933 typedef _Key key_type;
934 typedef key_type value_type;
935 typedef _Compare key_compare;
936 typedef key_compare value_compare;
937 typedef _Allocator allocator_type;
938 typedef value_type& reference;
939 typedef const value_type& const_reference;
940
Louis Dionne878a3a82018-12-06 21:46:17 +0000941 static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), "");
Marshall Clow5128cf32015-11-26 01:24:04 +0000942 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
943 "Allocator::value_type must be same type as value_type");
944
Howard Hinnantc51e1022010-05-11 19:42:16 +0000945private:
946 typedef __tree<value_type, value_compare, allocator_type> __base;
947 typedef allocator_traits<allocator_type> __alloc_traits;
948 typedef typename __base::__node_holder __node_holder;
949
950 __base __tree_;
951
952public:
953 typedef typename __base::pointer pointer;
954 typedef typename __base::const_pointer const_pointer;
955 typedef typename __base::size_type size_type;
956 typedef typename __base::difference_type difference_type;
957 typedef typename __base::const_iterator iterator;
958 typedef typename __base::const_iterator const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000959 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
960 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000961
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000962#if _LIBCPP_STD_VER > 14
963 typedef __set_node_handle<typename __base::__node, allocator_type> node_type;
964#endif
965
Erik Pilkington82a65ad2018-10-31 17:31:35 +0000966 template <class _Key2, class _Compare2, class _Alloc2>
967 friend class _LIBCPP_TEMPLATE_VIS set;
968 template <class _Key2, class _Compare2, class _Alloc2>
969 friend class _LIBCPP_TEMPLATE_VIS multiset;
970
Howard Hinnantc51e1022010-05-11 19:42:16 +0000971 // construct/copy/destroy:
Howard Hinnant192cf032010-09-23 16:27:36 +0000972 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +0000973 multiset()
974 _NOEXCEPT_(
975 is_nothrow_default_constructible<allocator_type>::value &&
976 is_nothrow_default_constructible<key_compare>::value &&
977 is_nothrow_copy_constructible<key_compare>::value)
978 : __tree_(value_compare()) {}
979
980 _LIBCPP_INLINE_VISIBILITY
981 explicit multiset(const value_compare& __comp)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000982 _NOEXCEPT_(
983 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000984 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000985 : __tree_(__comp) {}
Marshall Clow7086a5a2014-03-10 04:50:10 +0000986
Howard Hinnant192cf032010-09-23 16:27:36 +0000987 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7ed23a72014-03-05 19:06:20 +0000988 explicit multiset(const value_compare& __comp, const allocator_type& __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000989 : __tree_(__comp, __a) {}
990 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000991 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000992 multiset(_InputIterator __f, _InputIterator __l,
993 const value_compare& __comp = value_compare())
994 : __tree_(__comp)
995 {
996 insert(__f, __l);
997 }
998
Marshall Clow631788a2013-09-11 00:06:45 +0000999#if _LIBCPP_STD_VER > 11
1000 template <class _InputIterator>
Louis Dionned2322c82018-11-01 14:41:37 +00001001 _LIBCPP_INLINE_VISIBILITY
Marshall Clow631788a2013-09-11 00:06:45 +00001002 multiset(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
1003 : multiset(__f, __l, key_compare(), __a) {}
1004#endif
1005
Howard Hinnantc51e1022010-05-11 19:42:16 +00001006 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001007 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001008 multiset(_InputIterator __f, _InputIterator __l,
1009 const value_compare& __comp, const allocator_type& __a)
1010 : __tree_(__comp, __a)
1011 {
1012 insert(__f, __l);
1013 }
1014
Howard Hinnant192cf032010-09-23 16:27:36 +00001015 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001016 multiset(const multiset& __s)
1017 : __tree_(__s.__tree_.value_comp(),
1018 __alloc_traits::select_on_container_copy_construction(__s.__tree_.__alloc()))
1019 {
1020 insert(__s.begin(), __s.end());
1021 }
1022
Howard Hinnantd3a657f2011-07-01 19:24:36 +00001023 _LIBCPP_INLINE_VISIBILITY
1024 multiset& operator=(const multiset& __s)
1025 {
1026 __tree_ = __s.__tree_;
1027 return *this;
1028 }
1029
Eric Fiselier615961b2017-04-18 20:58:03 +00001030#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant192cf032010-09-23 16:27:36 +00001031 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001032 multiset(multiset&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001033 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001034 : __tree_(_VSTD::move(__s.__tree_)) {}
Eric Fiselier615961b2017-04-18 20:58:03 +00001035
1036 multiset(multiset&& __s, const allocator_type& __a);
1037#endif // _LIBCPP_CXX03_LANG
Howard Hinnant192cf032010-09-23 16:27:36 +00001038 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001039 explicit multiset(const allocator_type& __a)
1040 : __tree_(__a) {}
Howard Hinnant192cf032010-09-23 16:27:36 +00001041 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001042 multiset(const multiset& __s, const allocator_type& __a)
1043 : __tree_(__s.__tree_.value_comp(), __a)
1044 {
1045 insert(__s.begin(), __s.end());
1046 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001047
Eric Fiselier615961b2017-04-18 20:58:03 +00001048#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant192cf032010-09-23 16:27:36 +00001049 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001050 multiset(initializer_list<value_type> __il, const value_compare& __comp = value_compare())
1051 : __tree_(__comp)
1052 {
1053 insert(__il.begin(), __il.end());
1054 }
1055
Howard Hinnant192cf032010-09-23 16:27:36 +00001056 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001057 multiset(initializer_list<value_type> __il, const value_compare& __comp,
1058 const allocator_type& __a)
1059 : __tree_(__comp, __a)
1060 {
1061 insert(__il.begin(), __il.end());
1062 }
1063
Marshall Clow631788a2013-09-11 00:06:45 +00001064#if _LIBCPP_STD_VER > 11
Louis Dionned2322c82018-11-01 14:41:37 +00001065 _LIBCPP_INLINE_VISIBILITY
Marshall Clow631788a2013-09-11 00:06:45 +00001066 multiset(initializer_list<value_type> __il, const allocator_type& __a)
1067 : multiset(__il, key_compare(), __a) {}
1068#endif
1069
Howard Hinnant192cf032010-09-23 16:27:36 +00001070 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001071 multiset& operator=(initializer_list<value_type> __il)
1072 {
1073 __tree_.__assign_multi(__il.begin(), __il.end());
1074 return *this;
1075 }
1076
Howard Hinnant192cf032010-09-23 16:27:36 +00001077 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001078 multiset& operator=(multiset&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001079 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001080 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001081 __tree_ = _VSTD::move(__s.__tree_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001082 return *this;
1083 }
Eric Fiselier615961b2017-04-18 20:58:03 +00001084#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001085
Howard Hinnant192cf032010-09-23 16:27:36 +00001086 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001087 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001088 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001089 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001090 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001091 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001092 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001093 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001094
Howard Hinnant192cf032010-09-23 16:27:36 +00001095 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001096 reverse_iterator rbegin() _NOEXCEPT
1097 {return reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +00001098 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001099 const_reverse_iterator rbegin() const _NOEXCEPT
1100 {return const_reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +00001101 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001102 reverse_iterator rend() _NOEXCEPT
1103 {return reverse_iterator(begin());}
Howard Hinnant192cf032010-09-23 16:27:36 +00001104 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001105 const_reverse_iterator rend() const _NOEXCEPT
1106 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001107
Howard Hinnant192cf032010-09-23 16:27:36 +00001108 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001109 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001110 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001111 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001112 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001113 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001114 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001115 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001116
Marshall Clow425f5752017-11-15 05:51:26 +00001117 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001118 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant192cf032010-09-23 16:27:36 +00001119 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001120 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001121 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001122 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001123
1124 // modifiers:
Eric Fiselier615961b2017-04-18 20:58:03 +00001125#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001126 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +00001127 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001128 iterator emplace(_Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001129 {return __tree_.__emplace_multi(_VSTD::forward<_Args>(__args)...);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001130 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +00001131 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001132 iterator emplace_hint(const_iterator __p, _Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001133 {return __tree_.__emplace_hint_multi(__p, _VSTD::forward<_Args>(__args)...);}
Eric Fiselier615961b2017-04-18 20:58:03 +00001134#endif // _LIBCPP_CXX03_LANG
1135
Howard Hinnant192cf032010-09-23 16:27:36 +00001136 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001137 iterator insert(const value_type& __v)
1138 {return __tree_.__insert_multi(__v);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001139 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001140 iterator insert(const_iterator __p, const value_type& __v)
1141 {return __tree_.__insert_multi(__p, __v);}
Eric Fiselier615961b2017-04-18 20:58:03 +00001142
Howard Hinnantc51e1022010-05-11 19:42:16 +00001143 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001144 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001145 void insert(_InputIterator __f, _InputIterator __l)
1146 {
1147 for (const_iterator __e = cend(); __f != __l; ++__f)
1148 __tree_.__insert_multi(__e, *__f);
1149 }
1150
Eric Fiselier615961b2017-04-18 20:58:03 +00001151#ifndef _LIBCPP_CXX03_LANG
1152 _LIBCPP_INLINE_VISIBILITY
1153 iterator insert(value_type&& __v)
1154 {return __tree_.__insert_multi(_VSTD::move(__v));}
1155
1156 _LIBCPP_INLINE_VISIBILITY
1157 iterator insert(const_iterator __p, value_type&& __v)
1158 {return __tree_.__insert_multi(__p, _VSTD::move(__v));}
1159
Howard Hinnant192cf032010-09-23 16:27:36 +00001160 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001161 void insert(initializer_list<value_type> __il)
1162 {insert(__il.begin(), __il.end());}
Eric Fiselier615961b2017-04-18 20:58:03 +00001163#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001164
Howard Hinnant192cf032010-09-23 16:27:36 +00001165 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001166 iterator erase(const_iterator __p) {return __tree_.erase(__p);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001167 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001168 size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001169 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001170 iterator erase(const_iterator __f, const_iterator __l)
1171 {return __tree_.erase(__f, __l);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001172 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001173 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001174
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001175#if _LIBCPP_STD_VER > 14
1176 _LIBCPP_INLINE_VISIBILITY
1177 iterator insert(node_type&& __nh)
1178 {
1179 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1180 "node_type with incompatible allocator passed to multiset::insert()");
1181 return __tree_.template __node_handle_insert_multi<node_type>(
1182 _VSTD::move(__nh));
1183 }
1184 _LIBCPP_INLINE_VISIBILITY
1185 iterator insert(const_iterator __hint, node_type&& __nh)
1186 {
1187 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1188 "node_type with incompatible allocator passed to multiset::insert()");
1189 return __tree_.template __node_handle_insert_multi<node_type>(
1190 __hint, _VSTD::move(__nh));
1191 }
1192 _LIBCPP_INLINE_VISIBILITY
1193 node_type extract(key_type const& __key)
1194 {
1195 return __tree_.template __node_handle_extract<node_type>(__key);
1196 }
1197 _LIBCPP_INLINE_VISIBILITY
1198 node_type extract(const_iterator __it)
1199 {
1200 return __tree_.template __node_handle_extract<node_type>(__it);
1201 }
Louis Dionned2322c82018-11-01 14:41:37 +00001202 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001203 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001204 void merge(multiset<key_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001205 {
1206 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1207 "merging container with incompatible allocator");
1208 __tree_.__node_handle_merge_multi(__source.__tree_);
1209 }
Louis Dionned2322c82018-11-01 14:41:37 +00001210 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001211 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001212 void merge(multiset<key_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001213 {
1214 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1215 "merging container with incompatible allocator");
1216 __tree_.__node_handle_merge_multi(__source.__tree_);
1217 }
Louis Dionned2322c82018-11-01 14:41:37 +00001218 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001219 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001220 void merge(set<key_type, _Compare2, allocator_type>& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001221 {
1222 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1223 "merging container with incompatible allocator");
1224 __tree_.__node_handle_merge_multi(__source.__tree_);
1225 }
Louis Dionned2322c82018-11-01 14:41:37 +00001226 template <class _Compare2>
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001227 _LIBCPP_INLINE_VISIBILITY
Louis Dionned2322c82018-11-01 14:41:37 +00001228 void merge(set<key_type, _Compare2, allocator_type>&& __source)
Erik Pilkington82a65ad2018-10-31 17:31:35 +00001229 {
1230 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1231 "merging container with incompatible allocator");
1232 __tree_.__node_handle_merge_multi(__source.__tree_);
1233 }
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001234#endif
1235
Howard Hinnant192cf032010-09-23 16:27:36 +00001236 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001237 void swap(multiset& __s)
1238 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1239 {__tree_.swap(__s.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001240
Howard Hinnant192cf032010-09-23 16:27:36 +00001241 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001242 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001243 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001244 key_compare key_comp() const {return __tree_.value_comp();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001245 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001246 value_compare value_comp() const {return __tree_.value_comp();}
1247
1248 // set operations:
Howard Hinnant192cf032010-09-23 16:27:36 +00001249 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001250 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001251 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001252 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +00001253#if _LIBCPP_STD_VER > 11
1254 template <typename _K2>
1255 _LIBCPP_INLINE_VISIBILITY
1256 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,iterator>::type
1257 find(const _K2& __k) {return __tree_.find(__k);}
1258 template <typename _K2>
1259 _LIBCPP_INLINE_VISIBILITY
1260 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,const_iterator>::type
1261 find(const _K2& __k) const {return __tree_.find(__k);}
1262#endif
1263
Howard Hinnant192cf032010-09-23 16:27:36 +00001264 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001265 size_type count(const key_type& __k) const
1266 {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001267#if _LIBCPP_STD_VER > 11
1268 template <typename _K2>
1269 _LIBCPP_INLINE_VISIBILITY
1270 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
Marshall Clow5571bcd2018-01-07 17:39:57 +00001271 count(const _K2& __k) const {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001272#endif
Marshall Clowc0152142013-08-13 01:11:06 +00001273
Howard Hinnant192cf032010-09-23 16:27:36 +00001274 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001275 iterator lower_bound(const key_type& __k)
1276 {return __tree_.lower_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001277 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001278 const_iterator lower_bound(const key_type& __k) const
1279 {return __tree_.lower_bound(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +00001280#if _LIBCPP_STD_VER > 11
1281 template <typename _K2>
1282 _LIBCPP_INLINE_VISIBILITY
1283 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,iterator>::type
1284 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
1285
1286 template <typename _K2>
1287 _LIBCPP_INLINE_VISIBILITY
1288 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,const_iterator>::type
1289 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
1290#endif
1291
Howard Hinnant192cf032010-09-23 16:27:36 +00001292 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001293 iterator upper_bound(const key_type& __k)
1294 {return __tree_.upper_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001295 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001296 const_iterator upper_bound(const key_type& __k) const
1297 {return __tree_.upper_bound(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +00001298#if _LIBCPP_STD_VER > 11
1299 template <typename _K2>
1300 _LIBCPP_INLINE_VISIBILITY
1301 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,iterator>::type
1302 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
1303 template <typename _K2>
1304 _LIBCPP_INLINE_VISIBILITY
1305 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,const_iterator>::type
1306 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
1307#endif
1308
Howard Hinnant192cf032010-09-23 16:27:36 +00001309 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001310 pair<iterator,iterator> equal_range(const key_type& __k)
1311 {return __tree_.__equal_range_multi(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001312 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001313 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
1314 {return __tree_.__equal_range_multi(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +00001315#if _LIBCPP_STD_VER > 11
1316 template <typename _K2>
1317 _LIBCPP_INLINE_VISIBILITY
1318 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
1319 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
1320 template <typename _K2>
1321 _LIBCPP_INLINE_VISIBILITY
1322 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
1323 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
1324#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001325};
1326
Eric Fiselier615961b2017-04-18 20:58:03 +00001327#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001328
1329template <class _Key, class _Compare, class _Allocator>
1330multiset<_Key, _Compare, _Allocator>::multiset(multiset&& __s, const allocator_type& __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001331 : __tree_(_VSTD::move(__s.__tree_), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001332{
1333 if (__a != __s.get_allocator())
1334 {
1335 const_iterator __e = cend();
1336 while (!__s.empty())
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001337 insert(__e, _VSTD::move(__s.__tree_.remove(__s.begin())->__value_));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001338 }
1339}
1340
Eric Fiselier615961b2017-04-18 20:58:03 +00001341#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001342
1343template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001344inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001345bool
1346operator==(const multiset<_Key, _Compare, _Allocator>& __x,
1347 const multiset<_Key, _Compare, _Allocator>& __y)
1348{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001349 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001350}
1351
1352template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001353inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001354bool
1355operator< (const multiset<_Key, _Compare, _Allocator>& __x,
1356 const multiset<_Key, _Compare, _Allocator>& __y)
1357{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001358 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001359}
1360
1361template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001362inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001363bool
1364operator!=(const multiset<_Key, _Compare, _Allocator>& __x,
1365 const multiset<_Key, _Compare, _Allocator>& __y)
1366{
1367 return !(__x == __y);
1368}
1369
1370template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001371inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001372bool
1373operator> (const multiset<_Key, _Compare, _Allocator>& __x,
1374 const multiset<_Key, _Compare, _Allocator>& __y)
1375{
1376 return __y < __x;
1377}
1378
1379template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001380inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001381bool
1382operator>=(const multiset<_Key, _Compare, _Allocator>& __x,
1383 const multiset<_Key, _Compare, _Allocator>& __y)
1384{
1385 return !(__x < __y);
1386}
1387
1388template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001389inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001390bool
1391operator<=(const multiset<_Key, _Compare, _Allocator>& __x,
1392 const multiset<_Key, _Compare, _Allocator>& __y)
1393{
1394 return !(__y < __x);
1395}
1396
1397template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001398inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001399void
1400swap(multiset<_Key, _Compare, _Allocator>& __x,
1401 multiset<_Key, _Compare, _Allocator>& __y)
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001402 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001403{
1404 __x.swap(__y);
1405}
1406
Marshall Clow29b53f22018-12-14 18:49:35 +00001407#if _LIBCPP_STD_VER > 17
1408template <class _Key, class _Compare, class _Allocator, class _Predicate>
1409inline _LIBCPP_INLINE_VISIBILITY
1410void erase_if(multiset<_Key, _Compare, _Allocator>& __c, _Predicate __pred)
1411{ __libcpp_erase_if_container(__c, __pred); }
1412#endif
1413
Howard Hinnantc51e1022010-05-11 19:42:16 +00001414_LIBCPP_END_NAMESPACE_STD
1415
1416#endif // _LIBCPP_SET