blob: b4c6b2ef8c53c6b19a2e03451d38be30a759e62a [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;
43
44 // construct/copy/destroy:
Howard Hinnantf95f4f52011-06-04 15:22:34 +000045 set()
46 noexcept(
47 is_nothrow_default_constructible<allocator_type>::value &&
48 is_nothrow_default_constructible<key_compare>::value &&
49 is_nothrow_copy_constructible<key_compare>::value);
50 explicit set(const value_compare& comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +000051 set(const value_compare& comp, const allocator_type& a);
52 template <class InputIterator>
53 set(InputIterator first, InputIterator last,
54 const value_compare& comp = value_compare());
55 template <class InputIterator>
56 set(InputIterator first, InputIterator last, const value_compare& comp,
57 const allocator_type& a);
58 set(const set& s);
Howard Hinnantf95f4f52011-06-04 15:22:34 +000059 set(set&& s)
60 noexcept(
61 is_nothrow_move_constructible<allocator_type>::value &&
62 is_nothrow_move_constructible<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +000063 explicit set(const allocator_type& a);
64 set(const set& s, const allocator_type& a);
65 set(set&& s, const allocator_type& a);
66 set(initializer_list<value_type> il, const value_compare& comp = value_compare());
67 set(initializer_list<value_type> il, const value_compare& comp,
68 const allocator_type& a);
Marshall Clow631788a2013-09-11 00:06:45 +000069 template <class InputIterator>
70 set(InputIterator first, InputIterator last, const allocator_type& a)
71 : set(first, last, Compare(), a) {} // C++14
72 set(initializer_list<value_type> il, const allocator_type& a)
73 : set(il, Compare(), a) {} // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000074 ~set();
75
76 set& operator=(const set& s);
Howard Hinnantf95f4f52011-06-04 15:22:34 +000077 set& operator=(set&& s)
78 noexcept(
79 allocator_type::propagate_on_container_move_assignment::value &&
80 is_nothrow_move_assignable<allocator_type>::value &&
81 is_nothrow_move_assignable<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +000082 set& operator=(initializer_list<value_type> il);
83
84 // iterators:
Howard Hinnantf95f4f52011-06-04 15:22:34 +000085 iterator begin() noexcept;
86 const_iterator begin() const noexcept;
87 iterator end() noexcept;
88 const_iterator end() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000089
Howard Hinnantf95f4f52011-06-04 15:22:34 +000090 reverse_iterator rbegin() noexcept;
91 const_reverse_iterator rbegin() const noexcept;
92 reverse_iterator rend() noexcept;
93 const_reverse_iterator rend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000094
Howard Hinnantf95f4f52011-06-04 15:22:34 +000095 const_iterator cbegin() const noexcept;
96 const_iterator cend() const noexcept;
97 const_reverse_iterator crbegin() const noexcept;
98 const_reverse_iterator crend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000099
100 // capacity:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000101 bool empty() const noexcept;
102 size_type size() const noexcept;
103 size_type max_size() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000104
105 // modifiers:
106 template <class... Args>
107 pair<iterator, bool> emplace(Args&&... args);
108 template <class... Args>
109 iterator emplace_hint(const_iterator position, Args&&... args);
110 pair<iterator,bool> insert(const value_type& v);
111 pair<iterator,bool> insert(value_type&& v);
112 iterator insert(const_iterator position, const value_type& v);
113 iterator insert(const_iterator position, value_type&& v);
114 template <class InputIterator>
115 void insert(InputIterator first, InputIterator last);
116 void insert(initializer_list<value_type> il);
117
118 iterator erase(const_iterator position);
Marshall Clow22ea5b82015-05-10 13:35:00 +0000119 iterator erase(iterator position); // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000120 size_type erase(const key_type& k);
121 iterator erase(const_iterator first, const_iterator last);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000122 void clear() noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000123
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000124 void swap(set& s)
125 noexcept(
126 __is_nothrow_swappable<key_compare>::value &&
127 (!allocator_type::propagate_on_container_swap::value ||
128 __is_nothrow_swappable<allocator_type>::value));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000129
130 // observers:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000131 allocator_type get_allocator() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000132 key_compare key_comp() const;
133 value_compare value_comp() const;
134
135 // set operations:
136 iterator find(const key_type& k);
137 const_iterator find(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000138 template<typename K>
139 iterator find(const K& x);
140 template<typename K>
141 const_iterator find(const K& x) const; // C++14
142 template<typename K>
143 size_type count(const K& x) const; // C++14
144
Howard Hinnantc51e1022010-05-11 19:42:16 +0000145 size_type count(const key_type& k) const;
146 iterator lower_bound(const key_type& k);
147 const_iterator lower_bound(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000148 template<typename K>
149 iterator lower_bound(const K& x); // C++14
150 template<typename K>
151 const_iterator lower_bound(const K& x) const; // C++14
152
Howard Hinnantc51e1022010-05-11 19:42:16 +0000153 iterator upper_bound(const key_type& k);
154 const_iterator upper_bound(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000155 template<typename K>
156 iterator upper_bound(const K& x); // C++14
157 template<typename K>
158 const_iterator upper_bound(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000159 pair<iterator,iterator> equal_range(const key_type& k);
160 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000161 template<typename K>
162 pair<iterator,iterator> equal_range(const K& x); // C++14
163 template<typename K>
164 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000165};
166
167template <class Key, class Compare, class Allocator>
168bool
169operator==(const set<Key, Compare, Allocator>& x,
170 const set<Key, Compare, Allocator>& y);
171
172template <class Key, class Compare, class Allocator>
173bool
174operator< (const set<Key, Compare, Allocator>& x,
175 const set<Key, Compare, Allocator>& y);
176
177template <class Key, class Compare, class Allocator>
178bool
179operator!=(const set<Key, Compare, Allocator>& x,
180 const set<Key, Compare, Allocator>& y);
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
197// specialized algorithms:
198template <class Key, class Compare, class Allocator>
199void
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000200swap(set<Key, Compare, Allocator>& x, set<Key, Compare, Allocator>& y)
201 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000202
Howard Hinnantc51e1022010-05-11 19:42:16 +0000203template <class Key, class Compare = less<Key>,
204 class Allocator = allocator<Key>>
205class multiset
206{
207public:
208 // types:
209 typedef Key key_type;
210 typedef key_type value_type;
211 typedef Compare key_compare;
212 typedef key_compare value_compare;
213 typedef Allocator allocator_type;
214 typedef typename allocator_type::reference reference;
215 typedef typename allocator_type::const_reference const_reference;
216 typedef typename allocator_type::size_type size_type;
217 typedef typename allocator_type::difference_type difference_type;
218 typedef typename allocator_type::pointer pointer;
219 typedef typename allocator_type::const_pointer const_pointer;
220
221 typedef implementation-defined iterator;
222 typedef implementation-defined const_iterator;
223 typedef std::reverse_iterator<iterator> reverse_iterator;
224 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
225
226 // construct/copy/destroy:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000227 multiset()
228 noexcept(
229 is_nothrow_default_constructible<allocator_type>::value &&
230 is_nothrow_default_constructible<key_compare>::value &&
231 is_nothrow_copy_constructible<key_compare>::value);
232 explicit multiset(const value_compare& comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000233 multiset(const value_compare& comp, const allocator_type& a);
234 template <class InputIterator>
235 multiset(InputIterator first, InputIterator last,
236 const value_compare& comp = value_compare());
237 template <class InputIterator>
238 multiset(InputIterator first, InputIterator last,
239 const value_compare& comp, const allocator_type& a);
240 multiset(const multiset& s);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000241 multiset(multiset&& s)
242 noexcept(
243 is_nothrow_move_constructible<allocator_type>::value &&
244 is_nothrow_move_constructible<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000245 explicit multiset(const allocator_type& a);
246 multiset(const multiset& s, const allocator_type& a);
247 multiset(multiset&& s, const allocator_type& a);
248 multiset(initializer_list<value_type> il, const value_compare& comp = value_compare());
249 multiset(initializer_list<value_type> il, const value_compare& comp,
250 const allocator_type& a);
Marshall Clow631788a2013-09-11 00:06:45 +0000251 template <class InputIterator>
252 multiset(InputIterator first, InputIterator last, const allocator_type& a)
253 : set(first, last, Compare(), a) {} // C++14
254 multiset(initializer_list<value_type> il, const allocator_type& a)
255 : set(il, Compare(), a) {} // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000256 ~multiset();
257
258 multiset& operator=(const multiset& s);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000259 multiset& operator=(multiset&& s)
260 noexcept(
261 allocator_type::propagate_on_container_move_assignment::value &&
262 is_nothrow_move_assignable<allocator_type>::value &&
263 is_nothrow_move_assignable<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000264 multiset& operator=(initializer_list<value_type> il);
265
266 // iterators:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000267 iterator begin() noexcept;
268 const_iterator begin() const noexcept;
269 iterator end() noexcept;
270 const_iterator end() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000271
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000272 reverse_iterator rbegin() noexcept;
273 const_reverse_iterator rbegin() const noexcept;
274 reverse_iterator rend() noexcept;
275 const_reverse_iterator rend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000276
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000277 const_iterator cbegin() const noexcept;
278 const_iterator cend() const noexcept;
279 const_reverse_iterator crbegin() const noexcept;
280 const_reverse_iterator crend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000281
282 // capacity:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000283 bool empty() const noexcept;
284 size_type size() const noexcept;
285 size_type max_size() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000286
287 // modifiers:
288 template <class... Args>
289 iterator emplace(Args&&... args);
290 template <class... Args>
291 iterator emplace_hint(const_iterator position, Args&&... args);
292 iterator insert(const value_type& v);
293 iterator insert(value_type&& v);
294 iterator insert(const_iterator position, const value_type& v);
295 iterator insert(const_iterator position, value_type&& v);
296 template <class InputIterator>
297 void insert(InputIterator first, InputIterator last);
298 void insert(initializer_list<value_type> il);
299
300 iterator erase(const_iterator position);
Marshall Clow22ea5b82015-05-10 13:35:00 +0000301 iterator erase(iterator position); // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000302 size_type erase(const key_type& k);
303 iterator erase(const_iterator first, const_iterator last);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000304 void clear() noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000305
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000306 void swap(multiset& s)
307 noexcept(
308 __is_nothrow_swappable<key_compare>::value &&
309 (!allocator_type::propagate_on_container_swap::value ||
310 __is_nothrow_swappable<allocator_type>::value));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000311
312 // observers:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000313 allocator_type get_allocator() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000314 key_compare key_comp() const;
315 value_compare value_comp() const;
316
317 // set operations:
318 iterator find(const key_type& k);
319 const_iterator find(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000320 template<typename K>
321 iterator find(const K& x);
322 template<typename K>
323 const_iterator find(const K& x) const; // C++14
324
Howard Hinnantc51e1022010-05-11 19:42:16 +0000325 size_type count(const key_type& k) const;
326 iterator lower_bound(const key_type& k);
327 const_iterator lower_bound(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000328 template<typename K>
329 iterator lower_bound(const K& x); // C++14
330 template<typename K>
331 const_iterator lower_bound(const K& x) const; // C++14
332
Howard Hinnantc51e1022010-05-11 19:42:16 +0000333 iterator upper_bound(const key_type& k);
334 const_iterator upper_bound(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000335 template<typename K>
336 iterator upper_bound(const K& x); // C++14
337 template<typename K>
338 const_iterator upper_bound(const K& x) const; // C++14
339
Howard Hinnantc51e1022010-05-11 19:42:16 +0000340 pair<iterator,iterator> equal_range(const key_type& k);
341 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000342 template<typename K>
343 pair<iterator,iterator> equal_range(const K& x); // C++14
344 template<typename K>
345 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000346};
347
348template <class Key, class Compare, class Allocator>
349bool
350operator==(const multiset<Key, Compare, Allocator>& x,
351 const multiset<Key, Compare, Allocator>& y);
352
353template <class Key, class Compare, class Allocator>
354bool
355operator< (const multiset<Key, Compare, Allocator>& x,
356 const multiset<Key, Compare, Allocator>& y);
357
358template <class Key, class Compare, class Allocator>
359bool
360operator!=(const multiset<Key, Compare, Allocator>& x,
361 const multiset<Key, Compare, Allocator>& y);
362
363template <class Key, class Compare, class Allocator>
364bool
365operator> (const multiset<Key, Compare, Allocator>& x,
366 const multiset<Key, Compare, Allocator>& y);
367
368template <class Key, class Compare, class Allocator>
369bool
370operator>=(const multiset<Key, Compare, Allocator>& x,
371 const multiset<Key, Compare, Allocator>& y);
372
373template <class Key, class Compare, class Allocator>
374bool
375operator<=(const multiset<Key, Compare, Allocator>& x,
376 const multiset<Key, Compare, Allocator>& y);
377
378// specialized algorithms:
379template <class Key, class Compare, class Allocator>
380void
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000381swap(multiset<Key, Compare, Allocator>& x, multiset<Key, Compare, Allocator>& y)
382 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000383
384} // std
385
386*/
387
388#include <__config>
389#include <__tree>
390#include <functional>
391
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000392#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000393#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000394#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000395
396_LIBCPP_BEGIN_NAMESPACE_STD
397
398template <class _Key, class _Compare = less<_Key>,
399 class _Allocator = allocator<_Key> >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000400class _LIBCPP_TEMPLATE_VIS set
Howard Hinnantc51e1022010-05-11 19:42:16 +0000401{
402public:
403 // types:
404 typedef _Key key_type;
405 typedef key_type value_type;
406 typedef _Compare key_compare;
407 typedef key_compare value_compare;
408 typedef _Allocator allocator_type;
409 typedef value_type& reference;
410 typedef const value_type& const_reference;
411
Marshall Clow5128cf32015-11-26 01:24:04 +0000412 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
413 "Allocator::value_type must be same type as value_type");
414
Howard Hinnantc51e1022010-05-11 19:42:16 +0000415private:
416 typedef __tree<value_type, value_compare, allocator_type> __base;
417 typedef allocator_traits<allocator_type> __alloc_traits;
418 typedef typename __base::__node_holder __node_holder;
419
420 __base __tree_;
421
422public:
423 typedef typename __base::pointer pointer;
424 typedef typename __base::const_pointer const_pointer;
425 typedef typename __base::size_type size_type;
426 typedef typename __base::difference_type difference_type;
427 typedef typename __base::const_iterator iterator;
428 typedef typename __base::const_iterator const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000429 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
430 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000431
Howard Hinnant192cf032010-09-23 16:27:36 +0000432 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +0000433 set()
434 _NOEXCEPT_(
435 is_nothrow_default_constructible<allocator_type>::value &&
436 is_nothrow_default_constructible<key_compare>::value &&
437 is_nothrow_copy_constructible<key_compare>::value)
438 : __tree_(value_compare()) {}
439
440 _LIBCPP_INLINE_VISIBILITY
441 explicit set(const value_compare& __comp)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000442 _NOEXCEPT_(
443 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000444 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000445 : __tree_(__comp) {}
Marshall Clow7086a5a2014-03-10 04:50:10 +0000446
Howard Hinnant192cf032010-09-23 16:27:36 +0000447 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7ed23a72014-03-05 19:06:20 +0000448 explicit set(const value_compare& __comp, const allocator_type& __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000449 : __tree_(__comp, __a) {}
450 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000451 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000452 set(_InputIterator __f, _InputIterator __l,
453 const value_compare& __comp = value_compare())
454 : __tree_(__comp)
455 {
456 insert(__f, __l);
457 }
458
459 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000460 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000461 set(_InputIterator __f, _InputIterator __l, const value_compare& __comp,
462 const allocator_type& __a)
463 : __tree_(__comp, __a)
464 {
465 insert(__f, __l);
466 }
467
Marshall Clow631788a2013-09-11 00:06:45 +0000468#if _LIBCPP_STD_VER > 11
469 template <class _InputIterator>
470 _LIBCPP_INLINE_VISIBILITY
471 set(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
472 : set(__f, __l, key_compare(), __a) {}
473#endif
474
Howard Hinnant192cf032010-09-23 16:27:36 +0000475 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000476 set(const set& __s)
477 : __tree_(__s.__tree_)
478 {
479 insert(__s.begin(), __s.end());
480 }
481
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000482 _LIBCPP_INLINE_VISIBILITY
483 set& operator=(const set& __s)
484 {
485 __tree_ = __s.__tree_;
486 return *this;
487 }
488
Eric Fiselier615961b2017-04-18 20:58:03 +0000489#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant192cf032010-09-23 16:27:36 +0000490 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000491 set(set&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000492 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000493 : __tree_(_VSTD::move(__s.__tree_)) {}
Eric Fiselier615961b2017-04-18 20:58:03 +0000494#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000495
Howard Hinnant192cf032010-09-23 16:27:36 +0000496 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000497 explicit set(const allocator_type& __a)
498 : __tree_(__a) {}
499
Howard Hinnant192cf032010-09-23 16:27:36 +0000500 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000501 set(const set& __s, const allocator_type& __a)
502 : __tree_(__s.__tree_.value_comp(), __a)
503 {
504 insert(__s.begin(), __s.end());
505 }
506
Eric Fiselier615961b2017-04-18 20:58:03 +0000507#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000508 set(set&& __s, const allocator_type& __a);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000509
Howard Hinnant192cf032010-09-23 16:27:36 +0000510 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000511 set(initializer_list<value_type> __il, const value_compare& __comp = value_compare())
512 : __tree_(__comp)
513 {
514 insert(__il.begin(), __il.end());
515 }
516
Howard Hinnant192cf032010-09-23 16:27:36 +0000517 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000518 set(initializer_list<value_type> __il, const value_compare& __comp,
519 const allocator_type& __a)
520 : __tree_(__comp, __a)
521 {
522 insert(__il.begin(), __il.end());
523 }
524
Marshall Clow631788a2013-09-11 00:06:45 +0000525#if _LIBCPP_STD_VER > 11
526 _LIBCPP_INLINE_VISIBILITY
527 set(initializer_list<value_type> __il, const allocator_type& __a)
528 : set(__il, key_compare(), __a) {}
529#endif
530
Howard Hinnant192cf032010-09-23 16:27:36 +0000531 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000532 set& operator=(initializer_list<value_type> __il)
533 {
534 __tree_.__assign_unique(__il.begin(), __il.end());
535 return *this;
536 }
537
Howard Hinnant192cf032010-09-23 16:27:36 +0000538 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000539 set& operator=(set&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000540 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000541 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000542 __tree_ = _VSTD::move(__s.__tree_);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000543 return *this;
544 }
Eric Fiselier615961b2017-04-18 20:58:03 +0000545#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000546
Howard Hinnant192cf032010-09-23 16:27:36 +0000547 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000548 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000549 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000550 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000551 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000552 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000553 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000554 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000555
Howard Hinnant192cf032010-09-23 16:27:36 +0000556 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000557 reverse_iterator rbegin() _NOEXCEPT
558 {return reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +0000559 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000560 const_reverse_iterator rbegin() const _NOEXCEPT
561 {return const_reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +0000562 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000563 reverse_iterator rend() _NOEXCEPT
564 {return reverse_iterator(begin());}
Howard Hinnant192cf032010-09-23 16:27:36 +0000565 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000566 const_reverse_iterator rend() const _NOEXCEPT
567 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000568
Howard Hinnant192cf032010-09-23 16:27:36 +0000569 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000570 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000571 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000572 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000573 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000574 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000575 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000576 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000577
Marshall Clow425f5752017-11-15 05:51:26 +0000578 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000579 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant192cf032010-09-23 16:27:36 +0000580 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000581 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000582 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000583 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000584
585 // modifiers:
Eric Fiselier615961b2017-04-18 20:58:03 +0000586#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000587 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +0000588 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000589 pair<iterator, bool> emplace(_Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000590 {return __tree_.__emplace_unique(_VSTD::forward<_Args>(__args)...);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000591 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +0000592 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000593 iterator emplace_hint(const_iterator __p, _Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000594 {return __tree_.__emplace_hint_unique(__p, _VSTD::forward<_Args>(__args)...);}
Eric Fiselier615961b2017-04-18 20:58:03 +0000595#endif // _LIBCPP_CXX03_LANG
596
Howard Hinnant192cf032010-09-23 16:27:36 +0000597 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000598 pair<iterator,bool> insert(const value_type& __v)
599 {return __tree_.__insert_unique(__v);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000600 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000601 iterator insert(const_iterator __p, const value_type& __v)
602 {return __tree_.__insert_unique(__p, __v);}
Eric Fiselier615961b2017-04-18 20:58:03 +0000603
Howard Hinnantc51e1022010-05-11 19:42:16 +0000604 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000605 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000606 void insert(_InputIterator __f, _InputIterator __l)
607 {
608 for (const_iterator __e = cend(); __f != __l; ++__f)
609 __tree_.__insert_unique(__e, *__f);
610 }
611
Eric Fiselier615961b2017-04-18 20:58:03 +0000612#ifndef _LIBCPP_CXX03_LANG
613 _LIBCPP_INLINE_VISIBILITY
614 pair<iterator,bool> insert(value_type&& __v)
615 {return __tree_.__insert_unique(_VSTD::move(__v));}
616
617 _LIBCPP_INLINE_VISIBILITY
618 iterator insert(const_iterator __p, value_type&& __v)
619 {return __tree_.__insert_unique(__p, _VSTD::move(__v));}
620
Howard Hinnant192cf032010-09-23 16:27:36 +0000621 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000622 void insert(initializer_list<value_type> __il)
623 {insert(__il.begin(), __il.end());}
Eric Fiselier615961b2017-04-18 20:58:03 +0000624#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000625
Howard Hinnant192cf032010-09-23 16:27:36 +0000626 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000627 iterator erase(const_iterator __p) {return __tree_.erase(__p);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000628 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000629 size_type erase(const key_type& __k)
630 {return __tree_.__erase_unique(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000631 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000632 iterator erase(const_iterator __f, const_iterator __l)
633 {return __tree_.erase(__f, __l);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000634 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000635 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000636
Howard Hinnant192cf032010-09-23 16:27:36 +0000637 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000638 void swap(set& __s) _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
639 {__tree_.swap(__s.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000640
Howard Hinnant192cf032010-09-23 16:27:36 +0000641 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000642 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000643 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000644 key_compare key_comp() const {return __tree_.value_comp();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000645 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000646 value_compare value_comp() const {return __tree_.value_comp();}
647
648 // set operations:
Howard Hinnant192cf032010-09-23 16:27:36 +0000649 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000650 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000651 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000652 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000653#if _LIBCPP_STD_VER > 11
654 template <typename _K2>
655 _LIBCPP_INLINE_VISIBILITY
656 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
657 find(const _K2& __k) {return __tree_.find(__k);}
658 template <typename _K2>
659 _LIBCPP_INLINE_VISIBILITY
660 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
661 find(const _K2& __k) const {return __tree_.find(__k);}
662#endif
663
Howard Hinnant192cf032010-09-23 16:27:36 +0000664 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000665 size_type count(const key_type& __k) const
666 {return __tree_.__count_unique(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +0000667#if _LIBCPP_STD_VER > 11
668 template <typename _K2>
669 _LIBCPP_INLINE_VISIBILITY
670 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
Eric Fiselier0546e852016-12-09 12:17:31 +0000671 count(const _K2& __k) const {return __tree_.__count_unique(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +0000672#endif
Howard Hinnant192cf032010-09-23 16:27:36 +0000673 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000674 iterator lower_bound(const key_type& __k)
675 {return __tree_.lower_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000676 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000677 const_iterator lower_bound(const key_type& __k) const
678 {return __tree_.lower_bound(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000679#if _LIBCPP_STD_VER > 11
680 template <typename _K2>
681 _LIBCPP_INLINE_VISIBILITY
682 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
683 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
684
685 template <typename _K2>
686 _LIBCPP_INLINE_VISIBILITY
687 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
688 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
689#endif
690
Howard Hinnant192cf032010-09-23 16:27:36 +0000691 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000692 iterator upper_bound(const key_type& __k)
693 {return __tree_.upper_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000694 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000695 const_iterator upper_bound(const key_type& __k) const
696 {return __tree_.upper_bound(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000697#if _LIBCPP_STD_VER > 11
698 template <typename _K2>
699 _LIBCPP_INLINE_VISIBILITY
700 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
701 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
702 template <typename _K2>
703 _LIBCPP_INLINE_VISIBILITY
704 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
705 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
706#endif
707
Howard Hinnant192cf032010-09-23 16:27:36 +0000708 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000709 pair<iterator,iterator> equal_range(const key_type& __k)
710 {return __tree_.__equal_range_unique(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000711 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000712 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
713 {return __tree_.__equal_range_unique(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000714#if _LIBCPP_STD_VER > 11
715 template <typename _K2>
716 _LIBCPP_INLINE_VISIBILITY
717 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
718 equal_range(const _K2& __k) {return __tree_.__equal_range_unique(__k);}
719 template <typename _K2>
720 _LIBCPP_INLINE_VISIBILITY
721 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
722 equal_range(const _K2& __k) const {return __tree_.__equal_range_unique(__k);}
723#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000724};
725
Eric Fiselier615961b2017-04-18 20:58:03 +0000726#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000727
728template <class _Key, class _Compare, class _Allocator>
729set<_Key, _Compare, _Allocator>::set(set&& __s, const allocator_type& __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000730 : __tree_(_VSTD::move(__s.__tree_), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000731{
732 if (__a != __s.get_allocator())
733 {
734 const_iterator __e = cend();
735 while (!__s.empty())
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000736 insert(__e, _VSTD::move(__s.__tree_.remove(__s.begin())->__value_));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000737 }
738}
739
Eric Fiselier615961b2017-04-18 20:58:03 +0000740#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000741
742template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000743inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000744bool
745operator==(const set<_Key, _Compare, _Allocator>& __x,
746 const set<_Key, _Compare, _Allocator>& __y)
747{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000748 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000749}
750
751template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000752inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000753bool
754operator< (const set<_Key, _Compare, _Allocator>& __x,
755 const set<_Key, _Compare, _Allocator>& __y)
756{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000757 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000758}
759
760template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000761inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000762bool
763operator!=(const set<_Key, _Compare, _Allocator>& __x,
764 const set<_Key, _Compare, _Allocator>& __y)
765{
766 return !(__x == __y);
767}
768
769template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000770inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000771bool
772operator> (const set<_Key, _Compare, _Allocator>& __x,
773 const set<_Key, _Compare, _Allocator>& __y)
774{
775 return __y < __x;
776}
777
778template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000779inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000780bool
781operator>=(const set<_Key, _Compare, _Allocator>& __x,
782 const set<_Key, _Compare, _Allocator>& __y)
783{
784 return !(__x < __y);
785}
786
787template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000788inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000789bool
790operator<=(const set<_Key, _Compare, _Allocator>& __x,
791 const set<_Key, _Compare, _Allocator>& __y)
792{
793 return !(__y < __x);
794}
795
796// specialized algorithms:
797template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000798inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000799void
800swap(set<_Key, _Compare, _Allocator>& __x,
801 set<_Key, _Compare, _Allocator>& __y)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000802 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000803{
804 __x.swap(__y);
805}
806
Howard Hinnantc51e1022010-05-11 19:42:16 +0000807template <class _Key, class _Compare = less<_Key>,
808 class _Allocator = allocator<_Key> >
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000809class _LIBCPP_TEMPLATE_VIS multiset
Howard Hinnantc51e1022010-05-11 19:42:16 +0000810{
811public:
812 // types:
813 typedef _Key key_type;
814 typedef key_type value_type;
815 typedef _Compare key_compare;
816 typedef key_compare value_compare;
817 typedef _Allocator allocator_type;
818 typedef value_type& reference;
819 typedef const value_type& const_reference;
820
Marshall Clow5128cf32015-11-26 01:24:04 +0000821 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
822 "Allocator::value_type must be same type as value_type");
823
Howard Hinnantc51e1022010-05-11 19:42:16 +0000824private:
825 typedef __tree<value_type, value_compare, allocator_type> __base;
826 typedef allocator_traits<allocator_type> __alloc_traits;
827 typedef typename __base::__node_holder __node_holder;
828
829 __base __tree_;
830
831public:
832 typedef typename __base::pointer pointer;
833 typedef typename __base::const_pointer const_pointer;
834 typedef typename __base::size_type size_type;
835 typedef typename __base::difference_type difference_type;
836 typedef typename __base::const_iterator iterator;
837 typedef typename __base::const_iterator const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000838 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
839 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000840
841 // construct/copy/destroy:
Howard Hinnant192cf032010-09-23 16:27:36 +0000842 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +0000843 multiset()
844 _NOEXCEPT_(
845 is_nothrow_default_constructible<allocator_type>::value &&
846 is_nothrow_default_constructible<key_compare>::value &&
847 is_nothrow_copy_constructible<key_compare>::value)
848 : __tree_(value_compare()) {}
849
850 _LIBCPP_INLINE_VISIBILITY
851 explicit multiset(const value_compare& __comp)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000852 _NOEXCEPT_(
853 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000854 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000855 : __tree_(__comp) {}
Marshall Clow7086a5a2014-03-10 04:50:10 +0000856
Howard Hinnant192cf032010-09-23 16:27:36 +0000857 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7ed23a72014-03-05 19:06:20 +0000858 explicit multiset(const value_compare& __comp, const allocator_type& __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000859 : __tree_(__comp, __a) {}
860 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000861 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000862 multiset(_InputIterator __f, _InputIterator __l,
863 const value_compare& __comp = value_compare())
864 : __tree_(__comp)
865 {
866 insert(__f, __l);
867 }
868
Marshall Clow631788a2013-09-11 00:06:45 +0000869#if _LIBCPP_STD_VER > 11
870 template <class _InputIterator>
871 _LIBCPP_INLINE_VISIBILITY
872 multiset(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
873 : multiset(__f, __l, key_compare(), __a) {}
874#endif
875
Howard Hinnantc51e1022010-05-11 19:42:16 +0000876 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000877 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000878 multiset(_InputIterator __f, _InputIterator __l,
879 const value_compare& __comp, const allocator_type& __a)
880 : __tree_(__comp, __a)
881 {
882 insert(__f, __l);
883 }
884
Howard Hinnant192cf032010-09-23 16:27:36 +0000885 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000886 multiset(const multiset& __s)
887 : __tree_(__s.__tree_.value_comp(),
888 __alloc_traits::select_on_container_copy_construction(__s.__tree_.__alloc()))
889 {
890 insert(__s.begin(), __s.end());
891 }
892
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000893 _LIBCPP_INLINE_VISIBILITY
894 multiset& operator=(const multiset& __s)
895 {
896 __tree_ = __s.__tree_;
897 return *this;
898 }
899
Eric Fiselier615961b2017-04-18 20:58:03 +0000900#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant192cf032010-09-23 16:27:36 +0000901 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000902 multiset(multiset&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000903 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000904 : __tree_(_VSTD::move(__s.__tree_)) {}
Eric Fiselier615961b2017-04-18 20:58:03 +0000905
906 multiset(multiset&& __s, const allocator_type& __a);
907#endif // _LIBCPP_CXX03_LANG
Howard Hinnant192cf032010-09-23 16:27:36 +0000908 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000909 explicit multiset(const allocator_type& __a)
910 : __tree_(__a) {}
Howard Hinnant192cf032010-09-23 16:27:36 +0000911 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000912 multiset(const multiset& __s, const allocator_type& __a)
913 : __tree_(__s.__tree_.value_comp(), __a)
914 {
915 insert(__s.begin(), __s.end());
916 }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000917
Eric Fiselier615961b2017-04-18 20:58:03 +0000918#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant192cf032010-09-23 16:27:36 +0000919 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000920 multiset(initializer_list<value_type> __il, const value_compare& __comp = value_compare())
921 : __tree_(__comp)
922 {
923 insert(__il.begin(), __il.end());
924 }
925
Howard Hinnant192cf032010-09-23 16:27:36 +0000926 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000927 multiset(initializer_list<value_type> __il, const value_compare& __comp,
928 const allocator_type& __a)
929 : __tree_(__comp, __a)
930 {
931 insert(__il.begin(), __il.end());
932 }
933
Marshall Clow631788a2013-09-11 00:06:45 +0000934#if _LIBCPP_STD_VER > 11
935 _LIBCPP_INLINE_VISIBILITY
936 multiset(initializer_list<value_type> __il, const allocator_type& __a)
937 : multiset(__il, key_compare(), __a) {}
938#endif
939
Howard Hinnant192cf032010-09-23 16:27:36 +0000940 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000941 multiset& operator=(initializer_list<value_type> __il)
942 {
943 __tree_.__assign_multi(__il.begin(), __il.end());
944 return *this;
945 }
946
Howard Hinnant192cf032010-09-23 16:27:36 +0000947 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000948 multiset& operator=(multiset&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000949 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000950 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000951 __tree_ = _VSTD::move(__s.__tree_);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000952 return *this;
953 }
Eric Fiselier615961b2017-04-18 20:58:03 +0000954#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000955
Howard Hinnant192cf032010-09-23 16:27:36 +0000956 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000957 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000958 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000959 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000960 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000961 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000962 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000963 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000964
Howard Hinnant192cf032010-09-23 16:27:36 +0000965 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000966 reverse_iterator rbegin() _NOEXCEPT
967 {return reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +0000968 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000969 const_reverse_iterator rbegin() const _NOEXCEPT
970 {return const_reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +0000971 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000972 reverse_iterator rend() _NOEXCEPT
973 {return reverse_iterator(begin());}
Howard Hinnant192cf032010-09-23 16:27:36 +0000974 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000975 const_reverse_iterator rend() const _NOEXCEPT
976 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000977
Howard Hinnant192cf032010-09-23 16:27:36 +0000978 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000979 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000980 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000981 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000982 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000983 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000984 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000985 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000986
Marshall Clow425f5752017-11-15 05:51:26 +0000987 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000988 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant192cf032010-09-23 16:27:36 +0000989 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000990 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000991 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000992 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000993
994 // modifiers:
Eric Fiselier615961b2017-04-18 20:58:03 +0000995#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000996 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +0000997 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000998 iterator emplace(_Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000999 {return __tree_.__emplace_multi(_VSTD::forward<_Args>(__args)...);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001000 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +00001001 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001002 iterator emplace_hint(const_iterator __p, _Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001003 {return __tree_.__emplace_hint_multi(__p, _VSTD::forward<_Args>(__args)...);}
Eric Fiselier615961b2017-04-18 20:58:03 +00001004#endif // _LIBCPP_CXX03_LANG
1005
Howard Hinnant192cf032010-09-23 16:27:36 +00001006 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001007 iterator insert(const value_type& __v)
1008 {return __tree_.__insert_multi(__v);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001009 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001010 iterator insert(const_iterator __p, const value_type& __v)
1011 {return __tree_.__insert_multi(__p, __v);}
Eric Fiselier615961b2017-04-18 20:58:03 +00001012
Howard Hinnantc51e1022010-05-11 19:42:16 +00001013 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001014 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001015 void insert(_InputIterator __f, _InputIterator __l)
1016 {
1017 for (const_iterator __e = cend(); __f != __l; ++__f)
1018 __tree_.__insert_multi(__e, *__f);
1019 }
1020
Eric Fiselier615961b2017-04-18 20:58:03 +00001021#ifndef _LIBCPP_CXX03_LANG
1022 _LIBCPP_INLINE_VISIBILITY
1023 iterator insert(value_type&& __v)
1024 {return __tree_.__insert_multi(_VSTD::move(__v));}
1025
1026 _LIBCPP_INLINE_VISIBILITY
1027 iterator insert(const_iterator __p, value_type&& __v)
1028 {return __tree_.__insert_multi(__p, _VSTD::move(__v));}
1029
Howard Hinnant192cf032010-09-23 16:27:36 +00001030 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001031 void insert(initializer_list<value_type> __il)
1032 {insert(__il.begin(), __il.end());}
Eric Fiselier615961b2017-04-18 20:58:03 +00001033#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001034
Howard Hinnant192cf032010-09-23 16:27:36 +00001035 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001036 iterator erase(const_iterator __p) {return __tree_.erase(__p);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001037 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001038 size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001039 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001040 iterator erase(const_iterator __f, const_iterator __l)
1041 {return __tree_.erase(__f, __l);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001042 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001043 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001044
Howard Hinnant192cf032010-09-23 16:27:36 +00001045 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001046 void swap(multiset& __s)
1047 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1048 {__tree_.swap(__s.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001049
Howard Hinnant192cf032010-09-23 16:27:36 +00001050 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001051 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001052 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001053 key_compare key_comp() const {return __tree_.value_comp();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001054 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001055 value_compare value_comp() const {return __tree_.value_comp();}
1056
1057 // set operations:
Howard Hinnant192cf032010-09-23 16:27:36 +00001058 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001059 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001060 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001061 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +00001062#if _LIBCPP_STD_VER > 11
1063 template <typename _K2>
1064 _LIBCPP_INLINE_VISIBILITY
1065 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,iterator>::type
1066 find(const _K2& __k) {return __tree_.find(__k);}
1067 template <typename _K2>
1068 _LIBCPP_INLINE_VISIBILITY
1069 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,const_iterator>::type
1070 find(const _K2& __k) const {return __tree_.find(__k);}
1071#endif
1072
Howard Hinnant192cf032010-09-23 16:27:36 +00001073 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001074 size_type count(const key_type& __k) const
1075 {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001076#if _LIBCPP_STD_VER > 11
1077 template <typename _K2>
1078 _LIBCPP_INLINE_VISIBILITY
1079 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
1080 count(const _K2& __k) {return __tree_.__count_multi(__k);}
1081#endif
Marshall Clowc0152142013-08-13 01:11:06 +00001082
Howard Hinnant192cf032010-09-23 16:27:36 +00001083 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001084 iterator lower_bound(const key_type& __k)
1085 {return __tree_.lower_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001086 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001087 const_iterator lower_bound(const key_type& __k) const
1088 {return __tree_.lower_bound(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +00001089#if _LIBCPP_STD_VER > 11
1090 template <typename _K2>
1091 _LIBCPP_INLINE_VISIBILITY
1092 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,iterator>::type
1093 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
1094
1095 template <typename _K2>
1096 _LIBCPP_INLINE_VISIBILITY
1097 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,const_iterator>::type
1098 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
1099#endif
1100
Howard Hinnant192cf032010-09-23 16:27:36 +00001101 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001102 iterator upper_bound(const key_type& __k)
1103 {return __tree_.upper_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001104 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001105 const_iterator upper_bound(const key_type& __k) const
1106 {return __tree_.upper_bound(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +00001107#if _LIBCPP_STD_VER > 11
1108 template <typename _K2>
1109 _LIBCPP_INLINE_VISIBILITY
1110 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,iterator>::type
1111 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
1112 template <typename _K2>
1113 _LIBCPP_INLINE_VISIBILITY
1114 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,const_iterator>::type
1115 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
1116#endif
1117
Howard Hinnant192cf032010-09-23 16:27:36 +00001118 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001119 pair<iterator,iterator> equal_range(const key_type& __k)
1120 {return __tree_.__equal_range_multi(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001121 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001122 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
1123 {return __tree_.__equal_range_multi(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +00001124#if _LIBCPP_STD_VER > 11
1125 template <typename _K2>
1126 _LIBCPP_INLINE_VISIBILITY
1127 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
1128 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
1129 template <typename _K2>
1130 _LIBCPP_INLINE_VISIBILITY
1131 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
1132 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
1133#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001134};
1135
Eric Fiselier615961b2017-04-18 20:58:03 +00001136#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001137
1138template <class _Key, class _Compare, class _Allocator>
1139multiset<_Key, _Compare, _Allocator>::multiset(multiset&& __s, const allocator_type& __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001140 : __tree_(_VSTD::move(__s.__tree_), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001141{
1142 if (__a != __s.get_allocator())
1143 {
1144 const_iterator __e = cend();
1145 while (!__s.empty())
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001146 insert(__e, _VSTD::move(__s.__tree_.remove(__s.begin())->__value_));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001147 }
1148}
1149
Eric Fiselier615961b2017-04-18 20:58:03 +00001150#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001151
1152template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001153inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001154bool
1155operator==(const multiset<_Key, _Compare, _Allocator>& __x,
1156 const multiset<_Key, _Compare, _Allocator>& __y)
1157{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001158 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001159}
1160
1161template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001162inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001163bool
1164operator< (const multiset<_Key, _Compare, _Allocator>& __x,
1165 const multiset<_Key, _Compare, _Allocator>& __y)
1166{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001167 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001168}
1169
1170template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001171inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001172bool
1173operator!=(const multiset<_Key, _Compare, _Allocator>& __x,
1174 const multiset<_Key, _Compare, _Allocator>& __y)
1175{
1176 return !(__x == __y);
1177}
1178
1179template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001180inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001181bool
1182operator> (const multiset<_Key, _Compare, _Allocator>& __x,
1183 const multiset<_Key, _Compare, _Allocator>& __y)
1184{
1185 return __y < __x;
1186}
1187
1188template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001189inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001190bool
1191operator>=(const multiset<_Key, _Compare, _Allocator>& __x,
1192 const multiset<_Key, _Compare, _Allocator>& __y)
1193{
1194 return !(__x < __y);
1195}
1196
1197template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001198inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001199bool
1200operator<=(const multiset<_Key, _Compare, _Allocator>& __x,
1201 const multiset<_Key, _Compare, _Allocator>& __y)
1202{
1203 return !(__y < __x);
1204}
1205
1206template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001207inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001208void
1209swap(multiset<_Key, _Compare, _Allocator>& __x,
1210 multiset<_Key, _Compare, _Allocator>& __y)
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001211 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001212{
1213 __x.swap(__y);
1214}
1215
Howard Hinnantc51e1022010-05-11 19:42:16 +00001216_LIBCPP_END_NAMESPACE_STD
1217
1218#endif // _LIBCPP_SET