blob: 108a9e97f88d94e5e09ae9681403d235695ca2e1 [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===---------------------------- set -------------------------------------===//
3//
Howard Hinnantc566dc32010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantc51e1022010-05-11 19:42:16 +00005//
Howard Hinnantee11c312010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantc51e1022010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_SET
12#define _LIBCPP_SET
13
14/*
15
16 set synopsis
17
18namespace std
19{
20
21template <class Key, class Compare = less<Key>,
22 class Allocator = allocator<Key>>
23class set
24{
25public:
26 // types:
27 typedef Key key_type;
28 typedef key_type value_type;
29 typedef Compare key_compare;
30 typedef key_compare value_compare;
31 typedef Allocator allocator_type;
32 typedef typename allocator_type::reference reference;
33 typedef typename allocator_type::const_reference const_reference;
34 typedef typename allocator_type::size_type size_type;
35 typedef typename allocator_type::difference_type difference_type;
36 typedef typename allocator_type::pointer pointer;
37 typedef typename allocator_type::const_pointer const_pointer;
38
39 typedef implementation-defined iterator;
40 typedef implementation-defined const_iterator;
41 typedef std::reverse_iterator<iterator> reverse_iterator;
42 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +000043 typedef unspecified node_type; // C++17
44 typedef INSERT_RETURN_TYPE<iterator, node_type> insert_return_type; // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +000045
46 // construct/copy/destroy:
Howard Hinnantf95f4f52011-06-04 15:22:34 +000047 set()
48 noexcept(
49 is_nothrow_default_constructible<allocator_type>::value &&
50 is_nothrow_default_constructible<key_compare>::value &&
51 is_nothrow_copy_constructible<key_compare>::value);
52 explicit set(const value_compare& comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +000053 set(const value_compare& comp, const allocator_type& a);
54 template <class InputIterator>
55 set(InputIterator first, InputIterator last,
56 const value_compare& comp = value_compare());
57 template <class InputIterator>
58 set(InputIterator first, InputIterator last, const value_compare& comp,
59 const allocator_type& a);
60 set(const set& s);
Howard Hinnantf95f4f52011-06-04 15:22:34 +000061 set(set&& s)
62 noexcept(
63 is_nothrow_move_constructible<allocator_type>::value &&
64 is_nothrow_move_constructible<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +000065 explicit set(const allocator_type& a);
66 set(const set& s, const allocator_type& a);
67 set(set&& s, const allocator_type& a);
68 set(initializer_list<value_type> il, const value_compare& comp = value_compare());
69 set(initializer_list<value_type> il, const value_compare& comp,
70 const allocator_type& a);
Marshall Clow631788a2013-09-11 00:06:45 +000071 template <class InputIterator>
72 set(InputIterator first, InputIterator last, const allocator_type& a)
73 : set(first, last, Compare(), a) {} // C++14
74 set(initializer_list<value_type> il, const allocator_type& a)
75 : set(il, Compare(), a) {} // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000076 ~set();
77
78 set& operator=(const set& s);
Howard Hinnantf95f4f52011-06-04 15:22:34 +000079 set& operator=(set&& s)
80 noexcept(
81 allocator_type::propagate_on_container_move_assignment::value &&
82 is_nothrow_move_assignable<allocator_type>::value &&
83 is_nothrow_move_assignable<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +000084 set& operator=(initializer_list<value_type> il);
85
86 // iterators:
Howard Hinnantf95f4f52011-06-04 15:22:34 +000087 iterator begin() noexcept;
88 const_iterator begin() const noexcept;
89 iterator end() noexcept;
90 const_iterator end() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000091
Howard Hinnantf95f4f52011-06-04 15:22:34 +000092 reverse_iterator rbegin() noexcept;
93 const_reverse_iterator rbegin() const noexcept;
94 reverse_iterator rend() noexcept;
95 const_reverse_iterator rend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000096
Howard Hinnantf95f4f52011-06-04 15:22:34 +000097 const_iterator cbegin() const noexcept;
98 const_iterator cend() const noexcept;
99 const_reverse_iterator crbegin() const noexcept;
100 const_reverse_iterator crend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000101
102 // capacity:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000103 bool empty() const noexcept;
104 size_type size() const noexcept;
105 size_type max_size() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000106
107 // modifiers:
108 template <class... Args>
109 pair<iterator, bool> emplace(Args&&... args);
110 template <class... Args>
111 iterator emplace_hint(const_iterator position, Args&&... args);
112 pair<iterator,bool> insert(const value_type& v);
113 pair<iterator,bool> insert(value_type&& v);
114 iterator insert(const_iterator position, const value_type& v);
115 iterator insert(const_iterator position, value_type&& v);
116 template <class InputIterator>
117 void insert(InputIterator first, InputIterator last);
118 void insert(initializer_list<value_type> il);
119
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000120 node_type extract(const_iterator position); // C++17
121 node_type extract(const key_type& x); // C++17
122 insert_return_type insert(node_type&& nh); // C++17
123 iterator insert(const_iterator hint, node_type&& nh); // C++17
124
Howard Hinnantc51e1022010-05-11 19:42:16 +0000125 iterator erase(const_iterator position);
Marshall Clow22ea5b82015-05-10 13:35:00 +0000126 iterator erase(iterator position); // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000127 size_type erase(const key_type& k);
128 iterator erase(const_iterator first, const_iterator last);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000129 void clear() noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000130
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000131 void swap(set& s)
132 noexcept(
133 __is_nothrow_swappable<key_compare>::value &&
134 (!allocator_type::propagate_on_container_swap::value ||
135 __is_nothrow_swappable<allocator_type>::value));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000136
137 // observers:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000138 allocator_type get_allocator() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000139 key_compare key_comp() const;
140 value_compare value_comp() const;
141
142 // set operations:
143 iterator find(const key_type& k);
144 const_iterator find(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000145 template<typename K>
146 iterator find(const K& x);
147 template<typename K>
148 const_iterator find(const K& x) const; // C++14
149 template<typename K>
150 size_type count(const K& x) const; // C++14
151
Howard Hinnantc51e1022010-05-11 19:42:16 +0000152 size_type count(const key_type& k) const;
153 iterator lower_bound(const key_type& k);
154 const_iterator lower_bound(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000155 template<typename K>
156 iterator lower_bound(const K& x); // C++14
157 template<typename K>
158 const_iterator lower_bound(const K& x) const; // C++14
159
Howard Hinnantc51e1022010-05-11 19:42:16 +0000160 iterator upper_bound(const key_type& k);
161 const_iterator upper_bound(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000162 template<typename K>
163 iterator upper_bound(const K& x); // C++14
164 template<typename K>
165 const_iterator upper_bound(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000166 pair<iterator,iterator> equal_range(const key_type& k);
167 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000168 template<typename K>
169 pair<iterator,iterator> equal_range(const K& x); // C++14
170 template<typename K>
171 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000172};
173
174template <class Key, class Compare, class Allocator>
175bool
176operator==(const set<Key, Compare, Allocator>& x,
177 const set<Key, Compare, Allocator>& y);
178
179template <class Key, class Compare, class Allocator>
180bool
181operator< (const set<Key, Compare, Allocator>& x,
182 const set<Key, Compare, Allocator>& y);
183
184template <class Key, class Compare, class Allocator>
185bool
186operator!=(const set<Key, Compare, Allocator>& x,
187 const set<Key, Compare, Allocator>& y);
188
189template <class Key, class Compare, class Allocator>
190bool
191operator> (const set<Key, Compare, Allocator>& x,
192 const set<Key, Compare, Allocator>& y);
193
194template <class Key, class Compare, class Allocator>
195bool
196operator>=(const set<Key, Compare, Allocator>& x,
197 const set<Key, Compare, Allocator>& y);
198
199template <class Key, class Compare, class Allocator>
200bool
201operator<=(const set<Key, Compare, Allocator>& x,
202 const set<Key, Compare, Allocator>& y);
203
204// specialized algorithms:
205template <class Key, class Compare, class Allocator>
206void
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000207swap(set<Key, Compare, Allocator>& x, set<Key, Compare, Allocator>& y)
208 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000209
Howard Hinnantc51e1022010-05-11 19:42:16 +0000210template <class Key, class Compare = less<Key>,
211 class Allocator = allocator<Key>>
212class multiset
213{
214public:
215 // types:
216 typedef Key key_type;
217 typedef key_type value_type;
218 typedef Compare key_compare;
219 typedef key_compare value_compare;
220 typedef Allocator allocator_type;
221 typedef typename allocator_type::reference reference;
222 typedef typename allocator_type::const_reference const_reference;
223 typedef typename allocator_type::size_type size_type;
224 typedef typename allocator_type::difference_type difference_type;
225 typedef typename allocator_type::pointer pointer;
226 typedef typename allocator_type::const_pointer const_pointer;
227
228 typedef implementation-defined iterator;
229 typedef implementation-defined const_iterator;
230 typedef std::reverse_iterator<iterator> reverse_iterator;
231 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000232 typedef unspecified node_type; // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000233
234 // construct/copy/destroy:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000235 multiset()
236 noexcept(
237 is_nothrow_default_constructible<allocator_type>::value &&
238 is_nothrow_default_constructible<key_compare>::value &&
239 is_nothrow_copy_constructible<key_compare>::value);
240 explicit multiset(const value_compare& comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000241 multiset(const value_compare& comp, const allocator_type& a);
242 template <class InputIterator>
243 multiset(InputIterator first, InputIterator last,
244 const value_compare& comp = value_compare());
245 template <class InputIterator>
246 multiset(InputIterator first, InputIterator last,
247 const value_compare& comp, const allocator_type& a);
248 multiset(const multiset& s);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000249 multiset(multiset&& s)
250 noexcept(
251 is_nothrow_move_constructible<allocator_type>::value &&
252 is_nothrow_move_constructible<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000253 explicit multiset(const allocator_type& a);
254 multiset(const multiset& s, const allocator_type& a);
255 multiset(multiset&& s, const allocator_type& a);
256 multiset(initializer_list<value_type> il, const value_compare& comp = value_compare());
257 multiset(initializer_list<value_type> il, const value_compare& comp,
258 const allocator_type& a);
Marshall Clow631788a2013-09-11 00:06:45 +0000259 template <class InputIterator>
260 multiset(InputIterator first, InputIterator last, const allocator_type& a)
261 : set(first, last, Compare(), a) {} // C++14
262 multiset(initializer_list<value_type> il, const allocator_type& a)
263 : set(il, Compare(), a) {} // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000264 ~multiset();
265
266 multiset& operator=(const multiset& s);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000267 multiset& operator=(multiset&& s)
268 noexcept(
269 allocator_type::propagate_on_container_move_assignment::value &&
270 is_nothrow_move_assignable<allocator_type>::value &&
271 is_nothrow_move_assignable<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000272 multiset& operator=(initializer_list<value_type> il);
273
274 // iterators:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000275 iterator begin() noexcept;
276 const_iterator begin() const noexcept;
277 iterator end() noexcept;
278 const_iterator end() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000279
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000280 reverse_iterator rbegin() noexcept;
281 const_reverse_iterator rbegin() const noexcept;
282 reverse_iterator rend() noexcept;
283 const_reverse_iterator rend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000284
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000285 const_iterator cbegin() const noexcept;
286 const_iterator cend() const noexcept;
287 const_reverse_iterator crbegin() const noexcept;
288 const_reverse_iterator crend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000289
290 // capacity:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000291 bool empty() const noexcept;
292 size_type size() const noexcept;
293 size_type max_size() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000294
295 // modifiers:
296 template <class... Args>
297 iterator emplace(Args&&... args);
298 template <class... Args>
299 iterator emplace_hint(const_iterator position, Args&&... args);
300 iterator insert(const value_type& v);
301 iterator insert(value_type&& v);
302 iterator insert(const_iterator position, const value_type& v);
303 iterator insert(const_iterator position, value_type&& v);
304 template <class InputIterator>
305 void insert(InputIterator first, InputIterator last);
306 void insert(initializer_list<value_type> il);
307
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000308 node_type extract(const_iterator position); // C++17
309 node_type extract(const key_type& x); // C++17
310 iterator insert(node_type&& nh); // C++17
311 iterator insert(const_iterator hint, node_type&& nh); // C++17
312
Howard Hinnantc51e1022010-05-11 19:42:16 +0000313 iterator erase(const_iterator position);
Marshall Clow22ea5b82015-05-10 13:35:00 +0000314 iterator erase(iterator position); // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000315 size_type erase(const key_type& k);
316 iterator erase(const_iterator first, const_iterator last);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000317 void clear() noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000318
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000319 void swap(multiset& s)
320 noexcept(
321 __is_nothrow_swappable<key_compare>::value &&
322 (!allocator_type::propagate_on_container_swap::value ||
323 __is_nothrow_swappable<allocator_type>::value));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000324
325 // observers:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000326 allocator_type get_allocator() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000327 key_compare key_comp() const;
328 value_compare value_comp() const;
329
330 // set operations:
331 iterator find(const key_type& k);
332 const_iterator find(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000333 template<typename K>
334 iterator find(const K& x);
335 template<typename K>
336 const_iterator find(const K& x) const; // C++14
337
Howard Hinnantc51e1022010-05-11 19:42:16 +0000338 size_type count(const key_type& k) const;
339 iterator lower_bound(const key_type& k);
340 const_iterator lower_bound(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000341 template<typename K>
342 iterator lower_bound(const K& x); // C++14
343 template<typename K>
344 const_iterator lower_bound(const K& x) const; // C++14
345
Howard Hinnantc51e1022010-05-11 19:42:16 +0000346 iterator upper_bound(const key_type& k);
347 const_iterator upper_bound(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000348 template<typename K>
349 iterator upper_bound(const K& x); // C++14
350 template<typename K>
351 const_iterator upper_bound(const K& x) const; // C++14
352
Howard Hinnantc51e1022010-05-11 19:42:16 +0000353 pair<iterator,iterator> equal_range(const key_type& k);
354 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000355 template<typename K>
356 pair<iterator,iterator> equal_range(const K& x); // C++14
357 template<typename K>
358 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000359};
360
361template <class Key, class Compare, class Allocator>
362bool
363operator==(const multiset<Key, Compare, Allocator>& x,
364 const multiset<Key, Compare, Allocator>& y);
365
366template <class Key, class Compare, class Allocator>
367bool
368operator< (const multiset<Key, Compare, Allocator>& x,
369 const multiset<Key, Compare, Allocator>& y);
370
371template <class Key, class Compare, class Allocator>
372bool
373operator!=(const multiset<Key, Compare, Allocator>& x,
374 const multiset<Key, Compare, Allocator>& y);
375
376template <class Key, class Compare, class Allocator>
377bool
378operator> (const multiset<Key, Compare, Allocator>& x,
379 const multiset<Key, Compare, Allocator>& y);
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
391// specialized algorithms:
392template <class Key, class Compare, class Allocator>
393void
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000394swap(multiset<Key, Compare, Allocator>& x, multiset<Key, Compare, Allocator>& y)
395 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000396
397} // std
398
399*/
400
401#include <__config>
402#include <__tree>
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000403#include <__node_handle>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000404#include <functional>
405
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000406#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000407#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000408#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000409
410_LIBCPP_BEGIN_NAMESPACE_STD
411
412template <class _Key, class _Compare = less<_Key>,
413 class _Allocator = allocator<_Key> >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000414class _LIBCPP_TEMPLATE_VIS set
Howard Hinnantc51e1022010-05-11 19:42:16 +0000415{
416public:
417 // types:
418 typedef _Key key_type;
419 typedef key_type value_type;
420 typedef _Compare key_compare;
421 typedef key_compare value_compare;
422 typedef _Allocator allocator_type;
423 typedef value_type& reference;
424 typedef const value_type& const_reference;
425
Marshall Clow5128cf32015-11-26 01:24:04 +0000426 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
427 "Allocator::value_type must be same type as value_type");
428
Howard Hinnantc51e1022010-05-11 19:42:16 +0000429private:
430 typedef __tree<value_type, value_compare, allocator_type> __base;
431 typedef allocator_traits<allocator_type> __alloc_traits;
432 typedef typename __base::__node_holder __node_holder;
433
434 __base __tree_;
435
436public:
437 typedef typename __base::pointer pointer;
438 typedef typename __base::const_pointer const_pointer;
439 typedef typename __base::size_type size_type;
440 typedef typename __base::difference_type difference_type;
441 typedef typename __base::const_iterator iterator;
442 typedef typename __base::const_iterator const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000443 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
444 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000445
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000446#if _LIBCPP_STD_VER > 14
447 typedef __set_node_handle<typename __base::__node, allocator_type> node_type;
448 typedef __insert_return_type<iterator, node_type> insert_return_type;
449#endif
450
Howard Hinnant192cf032010-09-23 16:27:36 +0000451 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +0000452 set()
453 _NOEXCEPT_(
454 is_nothrow_default_constructible<allocator_type>::value &&
455 is_nothrow_default_constructible<key_compare>::value &&
456 is_nothrow_copy_constructible<key_compare>::value)
457 : __tree_(value_compare()) {}
458
459 _LIBCPP_INLINE_VISIBILITY
460 explicit set(const value_compare& __comp)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000461 _NOEXCEPT_(
462 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000463 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000464 : __tree_(__comp) {}
Marshall Clow7086a5a2014-03-10 04:50:10 +0000465
Howard Hinnant192cf032010-09-23 16:27:36 +0000466 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7ed23a72014-03-05 19:06:20 +0000467 explicit set(const value_compare& __comp, const allocator_type& __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000468 : __tree_(__comp, __a) {}
469 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000470 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000471 set(_InputIterator __f, _InputIterator __l,
472 const value_compare& __comp = value_compare())
473 : __tree_(__comp)
474 {
475 insert(__f, __l);
476 }
477
478 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000479 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000480 set(_InputIterator __f, _InputIterator __l, const value_compare& __comp,
481 const allocator_type& __a)
482 : __tree_(__comp, __a)
483 {
484 insert(__f, __l);
485 }
486
Marshall Clow631788a2013-09-11 00:06:45 +0000487#if _LIBCPP_STD_VER > 11
488 template <class _InputIterator>
489 _LIBCPP_INLINE_VISIBILITY
490 set(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
491 : set(__f, __l, key_compare(), __a) {}
492#endif
493
Howard Hinnant192cf032010-09-23 16:27:36 +0000494 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000495 set(const set& __s)
496 : __tree_(__s.__tree_)
497 {
498 insert(__s.begin(), __s.end());
499 }
500
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000501 _LIBCPP_INLINE_VISIBILITY
502 set& operator=(const set& __s)
503 {
504 __tree_ = __s.__tree_;
505 return *this;
506 }
507
Eric Fiselier615961b2017-04-18 20:58:03 +0000508#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant192cf032010-09-23 16:27:36 +0000509 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000510 set(set&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000511 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000512 : __tree_(_VSTD::move(__s.__tree_)) {}
Eric Fiselier615961b2017-04-18 20:58:03 +0000513#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000514
Howard Hinnant192cf032010-09-23 16:27:36 +0000515 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000516 explicit set(const allocator_type& __a)
517 : __tree_(__a) {}
518
Howard Hinnant192cf032010-09-23 16:27:36 +0000519 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000520 set(const set& __s, const allocator_type& __a)
521 : __tree_(__s.__tree_.value_comp(), __a)
522 {
523 insert(__s.begin(), __s.end());
524 }
525
Eric Fiselier615961b2017-04-18 20:58:03 +0000526#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000527 set(set&& __s, const allocator_type& __a);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000528
Howard Hinnant192cf032010-09-23 16:27:36 +0000529 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000530 set(initializer_list<value_type> __il, const value_compare& __comp = value_compare())
531 : __tree_(__comp)
532 {
533 insert(__il.begin(), __il.end());
534 }
535
Howard Hinnant192cf032010-09-23 16:27:36 +0000536 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000537 set(initializer_list<value_type> __il, const value_compare& __comp,
538 const allocator_type& __a)
539 : __tree_(__comp, __a)
540 {
541 insert(__il.begin(), __il.end());
542 }
543
Marshall Clow631788a2013-09-11 00:06:45 +0000544#if _LIBCPP_STD_VER > 11
545 _LIBCPP_INLINE_VISIBILITY
546 set(initializer_list<value_type> __il, const allocator_type& __a)
547 : set(__il, key_compare(), __a) {}
548#endif
549
Howard Hinnant192cf032010-09-23 16:27:36 +0000550 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000551 set& operator=(initializer_list<value_type> __il)
552 {
553 __tree_.__assign_unique(__il.begin(), __il.end());
554 return *this;
555 }
556
Howard Hinnant192cf032010-09-23 16:27:36 +0000557 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000558 set& operator=(set&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000559 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000560 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000561 __tree_ = _VSTD::move(__s.__tree_);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000562 return *this;
563 }
Eric Fiselier615961b2017-04-18 20:58:03 +0000564#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000565
Howard Hinnant192cf032010-09-23 16:27:36 +0000566 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000567 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000568 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000569 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000570 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000571 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000572 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000573 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000574
Howard Hinnant192cf032010-09-23 16:27:36 +0000575 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000576 reverse_iterator rbegin() _NOEXCEPT
577 {return reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +0000578 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000579 const_reverse_iterator rbegin() const _NOEXCEPT
580 {return const_reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +0000581 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000582 reverse_iterator rend() _NOEXCEPT
583 {return reverse_iterator(begin());}
Howard Hinnant192cf032010-09-23 16:27:36 +0000584 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000585 const_reverse_iterator rend() const _NOEXCEPT
586 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000587
Howard Hinnant192cf032010-09-23 16:27:36 +0000588 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000589 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000590 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000591 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000592 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000593 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000594 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000595 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000596
Marshall Clow425f5752017-11-15 05:51:26 +0000597 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000598 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant192cf032010-09-23 16:27:36 +0000599 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000600 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000601 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000602 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000603
604 // modifiers:
Eric Fiselier615961b2017-04-18 20:58:03 +0000605#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000606 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +0000607 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000608 pair<iterator, bool> emplace(_Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000609 {return __tree_.__emplace_unique(_VSTD::forward<_Args>(__args)...);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000610 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +0000611 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000612 iterator emplace_hint(const_iterator __p, _Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000613 {return __tree_.__emplace_hint_unique(__p, _VSTD::forward<_Args>(__args)...);}
Eric Fiselier615961b2017-04-18 20:58:03 +0000614#endif // _LIBCPP_CXX03_LANG
615
Howard Hinnant192cf032010-09-23 16:27:36 +0000616 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000617 pair<iterator,bool> insert(const value_type& __v)
618 {return __tree_.__insert_unique(__v);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000619 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000620 iterator insert(const_iterator __p, const value_type& __v)
621 {return __tree_.__insert_unique(__p, __v);}
Eric Fiselier615961b2017-04-18 20:58:03 +0000622
Howard Hinnantc51e1022010-05-11 19:42:16 +0000623 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000624 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000625 void insert(_InputIterator __f, _InputIterator __l)
626 {
627 for (const_iterator __e = cend(); __f != __l; ++__f)
628 __tree_.__insert_unique(__e, *__f);
629 }
630
Eric Fiselier615961b2017-04-18 20:58:03 +0000631#ifndef _LIBCPP_CXX03_LANG
632 _LIBCPP_INLINE_VISIBILITY
633 pair<iterator,bool> insert(value_type&& __v)
634 {return __tree_.__insert_unique(_VSTD::move(__v));}
635
636 _LIBCPP_INLINE_VISIBILITY
637 iterator insert(const_iterator __p, value_type&& __v)
638 {return __tree_.__insert_unique(__p, _VSTD::move(__v));}
639
Howard Hinnant192cf032010-09-23 16:27:36 +0000640 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000641 void insert(initializer_list<value_type> __il)
642 {insert(__il.begin(), __il.end());}
Eric Fiselier615961b2017-04-18 20:58:03 +0000643#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000644
Howard Hinnant192cf032010-09-23 16:27:36 +0000645 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000646 iterator erase(const_iterator __p) {return __tree_.erase(__p);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000647 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000648 size_type erase(const key_type& __k)
649 {return __tree_.__erase_unique(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000650 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000651 iterator erase(const_iterator __f, const_iterator __l)
652 {return __tree_.erase(__f, __l);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000653 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000654 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000655
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000656#if _LIBCPP_STD_VER > 14
657 _LIBCPP_INLINE_VISIBILITY
658 insert_return_type insert(node_type&& __nh)
659 {
660 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
661 "node_type with incompatible allocator passed to set::insert()");
662 return __tree_.template __node_handle_insert_unique<
663 node_type, insert_return_type>(_VSTD::move(__nh));
664 }
665 _LIBCPP_INLINE_VISIBILITY
666 iterator insert(const_iterator __hint, node_type&& __nh)
667 {
668 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
669 "node_type with incompatible allocator passed to set::insert()");
670 return __tree_.template __node_handle_insert_unique<node_type>(
671 __hint, _VSTD::move(__nh));
672 }
673 _LIBCPP_INLINE_VISIBILITY
674 node_type extract(key_type const& __key)
675 {
676 return __tree_.template __node_handle_extract<node_type>(__key);
677 }
678 _LIBCPP_INLINE_VISIBILITY
679 node_type extract(const_iterator __it)
680 {
681 return __tree_.template __node_handle_extract<node_type>(__it);
682 }
683#endif
684
Howard Hinnant192cf032010-09-23 16:27:36 +0000685 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000686 void swap(set& __s) _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
687 {__tree_.swap(__s.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000688
Howard Hinnant192cf032010-09-23 16:27:36 +0000689 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000690 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000691 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000692 key_compare key_comp() const {return __tree_.value_comp();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000693 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000694 value_compare value_comp() const {return __tree_.value_comp();}
695
696 // set operations:
Howard Hinnant192cf032010-09-23 16:27:36 +0000697 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000698 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000699 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000700 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000701#if _LIBCPP_STD_VER > 11
702 template <typename _K2>
703 _LIBCPP_INLINE_VISIBILITY
704 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
705 find(const _K2& __k) {return __tree_.find(__k);}
706 template <typename _K2>
707 _LIBCPP_INLINE_VISIBILITY
708 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
709 find(const _K2& __k) const {return __tree_.find(__k);}
710#endif
711
Howard Hinnant192cf032010-09-23 16:27:36 +0000712 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000713 size_type count(const key_type& __k) const
714 {return __tree_.__count_unique(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +0000715#if _LIBCPP_STD_VER > 11
716 template <typename _K2>
717 _LIBCPP_INLINE_VISIBILITY
718 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +0000719 count(const _K2& __k) const {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +0000720#endif
Howard Hinnant192cf032010-09-23 16:27:36 +0000721 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000722 iterator lower_bound(const key_type& __k)
723 {return __tree_.lower_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000724 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000725 const_iterator lower_bound(const key_type& __k) const
726 {return __tree_.lower_bound(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000727#if _LIBCPP_STD_VER > 11
728 template <typename _K2>
729 _LIBCPP_INLINE_VISIBILITY
730 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
731 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
732
733 template <typename _K2>
734 _LIBCPP_INLINE_VISIBILITY
735 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
736 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
737#endif
738
Howard Hinnant192cf032010-09-23 16:27:36 +0000739 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000740 iterator upper_bound(const key_type& __k)
741 {return __tree_.upper_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000742 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000743 const_iterator upper_bound(const key_type& __k) const
744 {return __tree_.upper_bound(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000745#if _LIBCPP_STD_VER > 11
746 template <typename _K2>
747 _LIBCPP_INLINE_VISIBILITY
748 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
749 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
750 template <typename _K2>
751 _LIBCPP_INLINE_VISIBILITY
752 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
753 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
754#endif
755
Howard Hinnant192cf032010-09-23 16:27:36 +0000756 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000757 pair<iterator,iterator> equal_range(const key_type& __k)
758 {return __tree_.__equal_range_unique(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000759 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000760 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
761 {return __tree_.__equal_range_unique(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000762#if _LIBCPP_STD_VER > 11
763 template <typename _K2>
764 _LIBCPP_INLINE_VISIBILITY
765 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +0000766 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000767 template <typename _K2>
768 _LIBCPP_INLINE_VISIBILITY
769 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
Eric Fiseliera85c9e92018-02-10 02:53:47 +0000770 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000771#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000772};
773
Eric Fiselier615961b2017-04-18 20:58:03 +0000774#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000775
776template <class _Key, class _Compare, class _Allocator>
777set<_Key, _Compare, _Allocator>::set(set&& __s, const allocator_type& __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000778 : __tree_(_VSTD::move(__s.__tree_), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000779{
780 if (__a != __s.get_allocator())
781 {
782 const_iterator __e = cend();
783 while (!__s.empty())
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000784 insert(__e, _VSTD::move(__s.__tree_.remove(__s.begin())->__value_));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000785 }
786}
787
Eric Fiselier615961b2017-04-18 20:58:03 +0000788#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000789
790template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000791inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000792bool
793operator==(const set<_Key, _Compare, _Allocator>& __x,
794 const set<_Key, _Compare, _Allocator>& __y)
795{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000796 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000797}
798
799template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000800inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000801bool
802operator< (const set<_Key, _Compare, _Allocator>& __x,
803 const set<_Key, _Compare, _Allocator>& __y)
804{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000805 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000806}
807
808template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000809inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000810bool
811operator!=(const set<_Key, _Compare, _Allocator>& __x,
812 const set<_Key, _Compare, _Allocator>& __y)
813{
814 return !(__x == __y);
815}
816
817template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000818inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000819bool
820operator> (const set<_Key, _Compare, _Allocator>& __x,
821 const set<_Key, _Compare, _Allocator>& __y)
822{
823 return __y < __x;
824}
825
826template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000827inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000828bool
829operator>=(const set<_Key, _Compare, _Allocator>& __x,
830 const set<_Key, _Compare, _Allocator>& __y)
831{
832 return !(__x < __y);
833}
834
835template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000836inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000837bool
838operator<=(const set<_Key, _Compare, _Allocator>& __x,
839 const set<_Key, _Compare, _Allocator>& __y)
840{
841 return !(__y < __x);
842}
843
844// specialized algorithms:
845template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000846inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000847void
848swap(set<_Key, _Compare, _Allocator>& __x,
849 set<_Key, _Compare, _Allocator>& __y)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000850 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000851{
852 __x.swap(__y);
853}
854
Howard Hinnantc51e1022010-05-11 19:42:16 +0000855template <class _Key, class _Compare = less<_Key>,
856 class _Allocator = allocator<_Key> >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000857class _LIBCPP_TEMPLATE_VIS multiset
Howard Hinnantc51e1022010-05-11 19:42:16 +0000858{
859public:
860 // types:
861 typedef _Key key_type;
862 typedef key_type value_type;
863 typedef _Compare key_compare;
864 typedef key_compare value_compare;
865 typedef _Allocator allocator_type;
866 typedef value_type& reference;
867 typedef const value_type& const_reference;
868
Marshall Clow5128cf32015-11-26 01:24:04 +0000869 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
870 "Allocator::value_type must be same type as value_type");
871
Howard Hinnantc51e1022010-05-11 19:42:16 +0000872private:
873 typedef __tree<value_type, value_compare, allocator_type> __base;
874 typedef allocator_traits<allocator_type> __alloc_traits;
875 typedef typename __base::__node_holder __node_holder;
876
877 __base __tree_;
878
879public:
880 typedef typename __base::pointer pointer;
881 typedef typename __base::const_pointer const_pointer;
882 typedef typename __base::size_type size_type;
883 typedef typename __base::difference_type difference_type;
884 typedef typename __base::const_iterator iterator;
885 typedef typename __base::const_iterator const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000886 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
887 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000888
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +0000889#if _LIBCPP_STD_VER > 14
890 typedef __set_node_handle<typename __base::__node, allocator_type> node_type;
891#endif
892
Howard Hinnantc51e1022010-05-11 19:42:16 +0000893 // construct/copy/destroy:
Howard Hinnant192cf032010-09-23 16:27:36 +0000894 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +0000895 multiset()
896 _NOEXCEPT_(
897 is_nothrow_default_constructible<allocator_type>::value &&
898 is_nothrow_default_constructible<key_compare>::value &&
899 is_nothrow_copy_constructible<key_compare>::value)
900 : __tree_(value_compare()) {}
901
902 _LIBCPP_INLINE_VISIBILITY
903 explicit multiset(const value_compare& __comp)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000904 _NOEXCEPT_(
905 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000906 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000907 : __tree_(__comp) {}
Marshall Clow7086a5a2014-03-10 04:50:10 +0000908
Howard Hinnant192cf032010-09-23 16:27:36 +0000909 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7ed23a72014-03-05 19:06:20 +0000910 explicit multiset(const value_compare& __comp, const allocator_type& __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000911 : __tree_(__comp, __a) {}
912 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000913 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000914 multiset(_InputIterator __f, _InputIterator __l,
915 const value_compare& __comp = value_compare())
916 : __tree_(__comp)
917 {
918 insert(__f, __l);
919 }
920
Marshall Clow631788a2013-09-11 00:06:45 +0000921#if _LIBCPP_STD_VER > 11
922 template <class _InputIterator>
923 _LIBCPP_INLINE_VISIBILITY
924 multiset(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
925 : multiset(__f, __l, key_compare(), __a) {}
926#endif
927
Howard Hinnantc51e1022010-05-11 19:42:16 +0000928 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000929 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000930 multiset(_InputIterator __f, _InputIterator __l,
931 const value_compare& __comp, const allocator_type& __a)
932 : __tree_(__comp, __a)
933 {
934 insert(__f, __l);
935 }
936
Howard Hinnant192cf032010-09-23 16:27:36 +0000937 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000938 multiset(const multiset& __s)
939 : __tree_(__s.__tree_.value_comp(),
940 __alloc_traits::select_on_container_copy_construction(__s.__tree_.__alloc()))
941 {
942 insert(__s.begin(), __s.end());
943 }
944
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000945 _LIBCPP_INLINE_VISIBILITY
946 multiset& operator=(const multiset& __s)
947 {
948 __tree_ = __s.__tree_;
949 return *this;
950 }
951
Eric Fiselier615961b2017-04-18 20:58:03 +0000952#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant192cf032010-09-23 16:27:36 +0000953 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000954 multiset(multiset&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000955 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000956 : __tree_(_VSTD::move(__s.__tree_)) {}
Eric Fiselier615961b2017-04-18 20:58:03 +0000957
958 multiset(multiset&& __s, const allocator_type& __a);
959#endif // _LIBCPP_CXX03_LANG
Howard Hinnant192cf032010-09-23 16:27:36 +0000960 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000961 explicit multiset(const allocator_type& __a)
962 : __tree_(__a) {}
Howard Hinnant192cf032010-09-23 16:27:36 +0000963 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000964 multiset(const multiset& __s, const allocator_type& __a)
965 : __tree_(__s.__tree_.value_comp(), __a)
966 {
967 insert(__s.begin(), __s.end());
968 }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000969
Eric Fiselier615961b2017-04-18 20:58:03 +0000970#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant192cf032010-09-23 16:27:36 +0000971 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000972 multiset(initializer_list<value_type> __il, const value_compare& __comp = value_compare())
973 : __tree_(__comp)
974 {
975 insert(__il.begin(), __il.end());
976 }
977
Howard Hinnant192cf032010-09-23 16:27:36 +0000978 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000979 multiset(initializer_list<value_type> __il, const value_compare& __comp,
980 const allocator_type& __a)
981 : __tree_(__comp, __a)
982 {
983 insert(__il.begin(), __il.end());
984 }
985
Marshall Clow631788a2013-09-11 00:06:45 +0000986#if _LIBCPP_STD_VER > 11
987 _LIBCPP_INLINE_VISIBILITY
988 multiset(initializer_list<value_type> __il, const allocator_type& __a)
989 : multiset(__il, key_compare(), __a) {}
990#endif
991
Howard Hinnant192cf032010-09-23 16:27:36 +0000992 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000993 multiset& operator=(initializer_list<value_type> __il)
994 {
995 __tree_.__assign_multi(__il.begin(), __il.end());
996 return *this;
997 }
998
Howard Hinnant192cf032010-09-23 16:27:36 +0000999 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001000 multiset& operator=(multiset&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001001 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001002 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001003 __tree_ = _VSTD::move(__s.__tree_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001004 return *this;
1005 }
Eric Fiselier615961b2017-04-18 20:58:03 +00001006#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001007
Howard Hinnant192cf032010-09-23 16:27:36 +00001008 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001009 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001010 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001011 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001012 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001013 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001014 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001015 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001016
Howard Hinnant192cf032010-09-23 16:27:36 +00001017 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001018 reverse_iterator rbegin() _NOEXCEPT
1019 {return reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +00001020 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001021 const_reverse_iterator rbegin() const _NOEXCEPT
1022 {return const_reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +00001023 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001024 reverse_iterator rend() _NOEXCEPT
1025 {return reverse_iterator(begin());}
Howard Hinnant192cf032010-09-23 16:27:36 +00001026 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001027 const_reverse_iterator rend() const _NOEXCEPT
1028 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001029
Howard Hinnant192cf032010-09-23 16:27:36 +00001030 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001031 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001032 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001033 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001034 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001035 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001036 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001037 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001038
Marshall Clow425f5752017-11-15 05:51:26 +00001039 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001040 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant192cf032010-09-23 16:27:36 +00001041 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001042 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001043 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001044 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001045
1046 // modifiers:
Eric Fiselier615961b2017-04-18 20:58:03 +00001047#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001048 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +00001049 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001050 iterator emplace(_Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001051 {return __tree_.__emplace_multi(_VSTD::forward<_Args>(__args)...);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001052 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +00001053 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001054 iterator emplace_hint(const_iterator __p, _Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001055 {return __tree_.__emplace_hint_multi(__p, _VSTD::forward<_Args>(__args)...);}
Eric Fiselier615961b2017-04-18 20:58:03 +00001056#endif // _LIBCPP_CXX03_LANG
1057
Howard Hinnant192cf032010-09-23 16:27:36 +00001058 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001059 iterator insert(const value_type& __v)
1060 {return __tree_.__insert_multi(__v);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001061 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001062 iterator insert(const_iterator __p, const value_type& __v)
1063 {return __tree_.__insert_multi(__p, __v);}
Eric Fiselier615961b2017-04-18 20:58:03 +00001064
Howard Hinnantc51e1022010-05-11 19:42:16 +00001065 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001066 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001067 void insert(_InputIterator __f, _InputIterator __l)
1068 {
1069 for (const_iterator __e = cend(); __f != __l; ++__f)
1070 __tree_.__insert_multi(__e, *__f);
1071 }
1072
Eric Fiselier615961b2017-04-18 20:58:03 +00001073#ifndef _LIBCPP_CXX03_LANG
1074 _LIBCPP_INLINE_VISIBILITY
1075 iterator insert(value_type&& __v)
1076 {return __tree_.__insert_multi(_VSTD::move(__v));}
1077
1078 _LIBCPP_INLINE_VISIBILITY
1079 iterator insert(const_iterator __p, value_type&& __v)
1080 {return __tree_.__insert_multi(__p, _VSTD::move(__v));}
1081
Howard Hinnant192cf032010-09-23 16:27:36 +00001082 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001083 void insert(initializer_list<value_type> __il)
1084 {insert(__il.begin(), __il.end());}
Eric Fiselier615961b2017-04-18 20:58:03 +00001085#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001086
Howard Hinnant192cf032010-09-23 16:27:36 +00001087 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001088 iterator erase(const_iterator __p) {return __tree_.erase(__p);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001089 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001090 size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001091 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001092 iterator erase(const_iterator __f, const_iterator __l)
1093 {return __tree_.erase(__f, __l);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001094 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001095 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001096
Erik Pilkingtonc37a3d82018-08-01 01:33:38 +00001097#if _LIBCPP_STD_VER > 14
1098 _LIBCPP_INLINE_VISIBILITY
1099 iterator insert(node_type&& __nh)
1100 {
1101 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1102 "node_type with incompatible allocator passed to multiset::insert()");
1103 return __tree_.template __node_handle_insert_multi<node_type>(
1104 _VSTD::move(__nh));
1105 }
1106 _LIBCPP_INLINE_VISIBILITY
1107 iterator insert(const_iterator __hint, node_type&& __nh)
1108 {
1109 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1110 "node_type with incompatible allocator passed to multiset::insert()");
1111 return __tree_.template __node_handle_insert_multi<node_type>(
1112 __hint, _VSTD::move(__nh));
1113 }
1114 _LIBCPP_INLINE_VISIBILITY
1115 node_type extract(key_type const& __key)
1116 {
1117 return __tree_.template __node_handle_extract<node_type>(__key);
1118 }
1119 _LIBCPP_INLINE_VISIBILITY
1120 node_type extract(const_iterator __it)
1121 {
1122 return __tree_.template __node_handle_extract<node_type>(__it);
1123 }
1124#endif
1125
Howard Hinnant192cf032010-09-23 16:27:36 +00001126 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001127 void swap(multiset& __s)
1128 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1129 {__tree_.swap(__s.__tree_);}
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 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001133 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001134 key_compare key_comp() const {return __tree_.value_comp();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001135 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001136 value_compare value_comp() const {return __tree_.value_comp();}
1137
1138 // set operations:
Howard Hinnant192cf032010-09-23 16:27:36 +00001139 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001140 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001141 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001142 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +00001143#if _LIBCPP_STD_VER > 11
1144 template <typename _K2>
1145 _LIBCPP_INLINE_VISIBILITY
1146 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,iterator>::type
1147 find(const _K2& __k) {return __tree_.find(__k);}
1148 template <typename _K2>
1149 _LIBCPP_INLINE_VISIBILITY
1150 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,const_iterator>::type
1151 find(const _K2& __k) const {return __tree_.find(__k);}
1152#endif
1153
Howard Hinnant192cf032010-09-23 16:27:36 +00001154 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001155 size_type count(const key_type& __k) const
1156 {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001157#if _LIBCPP_STD_VER > 11
1158 template <typename _K2>
1159 _LIBCPP_INLINE_VISIBILITY
1160 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
Marshall Clow5571bcd2018-01-07 17:39:57 +00001161 count(const _K2& __k) const {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001162#endif
Marshall Clowc0152142013-08-13 01:11:06 +00001163
Howard Hinnant192cf032010-09-23 16:27:36 +00001164 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001165 iterator lower_bound(const key_type& __k)
1166 {return __tree_.lower_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001167 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001168 const_iterator lower_bound(const key_type& __k) const
1169 {return __tree_.lower_bound(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +00001170#if _LIBCPP_STD_VER > 11
1171 template <typename _K2>
1172 _LIBCPP_INLINE_VISIBILITY
1173 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,iterator>::type
1174 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
1175
1176 template <typename _K2>
1177 _LIBCPP_INLINE_VISIBILITY
1178 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,const_iterator>::type
1179 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
1180#endif
1181
Howard Hinnant192cf032010-09-23 16:27:36 +00001182 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001183 iterator upper_bound(const key_type& __k)
1184 {return __tree_.upper_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001185 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001186 const_iterator upper_bound(const key_type& __k) const
1187 {return __tree_.upper_bound(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +00001188#if _LIBCPP_STD_VER > 11
1189 template <typename _K2>
1190 _LIBCPP_INLINE_VISIBILITY
1191 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,iterator>::type
1192 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
1193 template <typename _K2>
1194 _LIBCPP_INLINE_VISIBILITY
1195 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,const_iterator>::type
1196 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
1197#endif
1198
Howard Hinnant192cf032010-09-23 16:27:36 +00001199 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001200 pair<iterator,iterator> equal_range(const key_type& __k)
1201 {return __tree_.__equal_range_multi(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001202 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001203 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
1204 {return __tree_.__equal_range_multi(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +00001205#if _LIBCPP_STD_VER > 11
1206 template <typename _K2>
1207 _LIBCPP_INLINE_VISIBILITY
1208 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
1209 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
1210 template <typename _K2>
1211 _LIBCPP_INLINE_VISIBILITY
1212 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
1213 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
1214#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001215};
1216
Eric Fiselier615961b2017-04-18 20:58:03 +00001217#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001218
1219template <class _Key, class _Compare, class _Allocator>
1220multiset<_Key, _Compare, _Allocator>::multiset(multiset&& __s, const allocator_type& __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001221 : __tree_(_VSTD::move(__s.__tree_), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001222{
1223 if (__a != __s.get_allocator())
1224 {
1225 const_iterator __e = cend();
1226 while (!__s.empty())
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001227 insert(__e, _VSTD::move(__s.__tree_.remove(__s.begin())->__value_));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001228 }
1229}
1230
Eric Fiselier615961b2017-04-18 20:58:03 +00001231#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001232
1233template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001234inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001235bool
1236operator==(const multiset<_Key, _Compare, _Allocator>& __x,
1237 const multiset<_Key, _Compare, _Allocator>& __y)
1238{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001239 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001240}
1241
1242template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001243inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001244bool
1245operator< (const multiset<_Key, _Compare, _Allocator>& __x,
1246 const multiset<_Key, _Compare, _Allocator>& __y)
1247{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001248 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001249}
1250
1251template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001252inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001253bool
1254operator!=(const multiset<_Key, _Compare, _Allocator>& __x,
1255 const multiset<_Key, _Compare, _Allocator>& __y)
1256{
1257 return !(__x == __y);
1258}
1259
1260template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001261inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001262bool
1263operator> (const multiset<_Key, _Compare, _Allocator>& __x,
1264 const multiset<_Key, _Compare, _Allocator>& __y)
1265{
1266 return __y < __x;
1267}
1268
1269template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001270inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001271bool
1272operator>=(const multiset<_Key, _Compare, _Allocator>& __x,
1273 const multiset<_Key, _Compare, _Allocator>& __y)
1274{
1275 return !(__x < __y);
1276}
1277
1278template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001279inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001280bool
1281operator<=(const multiset<_Key, _Compare, _Allocator>& __x,
1282 const multiset<_Key, _Compare, _Allocator>& __y)
1283{
1284 return !(__y < __x);
1285}
1286
1287template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001288inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001289void
1290swap(multiset<_Key, _Compare, _Allocator>& __x,
1291 multiset<_Key, _Compare, _Allocator>& __y)
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001292 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001293{
1294 __x.swap(__y);
1295}
1296
Howard Hinnantc51e1022010-05-11 19:42:16 +00001297_LIBCPP_END_NAMESPACE_STD
1298
1299#endif // _LIBCPP_SET