blob: 9248fd79b24311691d5da524d19f53308899f276 [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);
69 ~set();
70
71 set& operator=(const set& s);
Howard Hinnantf95f4f52011-06-04 15:22:34 +000072 set& operator=(set&& s)
73 noexcept(
74 allocator_type::propagate_on_container_move_assignment::value &&
75 is_nothrow_move_assignable<allocator_type>::value &&
76 is_nothrow_move_assignable<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +000077 set& operator=(initializer_list<value_type> il);
78
79 // iterators:
Howard Hinnantf95f4f52011-06-04 15:22:34 +000080 iterator begin() noexcept;
81 const_iterator begin() const noexcept;
82 iterator end() noexcept;
83 const_iterator end() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000084
Howard Hinnantf95f4f52011-06-04 15:22:34 +000085 reverse_iterator rbegin() noexcept;
86 const_reverse_iterator rbegin() const noexcept;
87 reverse_iterator rend() noexcept;
88 const_reverse_iterator rend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000089
Howard Hinnantf95f4f52011-06-04 15:22:34 +000090 const_iterator cbegin() const noexcept;
91 const_iterator cend() const noexcept;
92 const_reverse_iterator crbegin() const noexcept;
93 const_reverse_iterator crend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000094
95 // capacity:
Howard Hinnantf95f4f52011-06-04 15:22:34 +000096 bool empty() const noexcept;
97 size_type size() const noexcept;
98 size_type max_size() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000099
100 // modifiers:
101 template <class... Args>
102 pair<iterator, bool> emplace(Args&&... args);
103 template <class... Args>
104 iterator emplace_hint(const_iterator position, Args&&... args);
105 pair<iterator,bool> insert(const value_type& v);
106 pair<iterator,bool> insert(value_type&& v);
107 iterator insert(const_iterator position, const value_type& v);
108 iterator insert(const_iterator position, value_type&& v);
109 template <class InputIterator>
110 void insert(InputIterator first, InputIterator last);
111 void insert(initializer_list<value_type> il);
112
113 iterator erase(const_iterator position);
114 size_type erase(const key_type& k);
115 iterator erase(const_iterator first, const_iterator last);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000116 void clear() noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000117
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000118 void swap(set& s)
119 noexcept(
120 __is_nothrow_swappable<key_compare>::value &&
121 (!allocator_type::propagate_on_container_swap::value ||
122 __is_nothrow_swappable<allocator_type>::value));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000123
124 // observers:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000125 allocator_type get_allocator() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000126 key_compare key_comp() const;
127 value_compare value_comp() const;
128
129 // set operations:
130 iterator find(const key_type& k);
131 const_iterator find(const key_type& k) const;
132 size_type count(const key_type& k) const;
133 iterator lower_bound(const key_type& k);
134 const_iterator lower_bound(const key_type& k) const;
135 iterator upper_bound(const key_type& k);
136 const_iterator upper_bound(const key_type& k) const;
137 pair<iterator,iterator> equal_range(const key_type& k);
138 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
139};
140
141template <class Key, class Compare, class Allocator>
142bool
143operator==(const set<Key, Compare, Allocator>& x,
144 const set<Key, Compare, Allocator>& y);
145
146template <class Key, class Compare, class Allocator>
147bool
148operator< (const set<Key, Compare, Allocator>& x,
149 const set<Key, Compare, Allocator>& y);
150
151template <class Key, class Compare, class Allocator>
152bool
153operator!=(const set<Key, Compare, Allocator>& x,
154 const set<Key, Compare, Allocator>& y);
155
156template <class Key, class Compare, class Allocator>
157bool
158operator> (const set<Key, Compare, Allocator>& x,
159 const set<Key, Compare, Allocator>& y);
160
161template <class Key, class Compare, class Allocator>
162bool
163operator>=(const set<Key, Compare, Allocator>& x,
164 const set<Key, Compare, Allocator>& y);
165
166template <class Key, class Compare, class Allocator>
167bool
168operator<=(const set<Key, Compare, Allocator>& x,
169 const set<Key, Compare, Allocator>& y);
170
171// specialized algorithms:
172template <class Key, class Compare, class Allocator>
173void
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000174swap(set<Key, Compare, Allocator>& x, set<Key, Compare, Allocator>& y)
175 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000176
Howard Hinnantc51e1022010-05-11 19:42:16 +0000177template <class Key, class Compare = less<Key>,
178 class Allocator = allocator<Key>>
179class multiset
180{
181public:
182 // types:
183 typedef Key key_type;
184 typedef key_type value_type;
185 typedef Compare key_compare;
186 typedef key_compare value_compare;
187 typedef Allocator allocator_type;
188 typedef typename allocator_type::reference reference;
189 typedef typename allocator_type::const_reference const_reference;
190 typedef typename allocator_type::size_type size_type;
191 typedef typename allocator_type::difference_type difference_type;
192 typedef typename allocator_type::pointer pointer;
193 typedef typename allocator_type::const_pointer const_pointer;
194
195 typedef implementation-defined iterator;
196 typedef implementation-defined const_iterator;
197 typedef std::reverse_iterator<iterator> reverse_iterator;
198 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
199
200 // construct/copy/destroy:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000201 multiset()
202 noexcept(
203 is_nothrow_default_constructible<allocator_type>::value &&
204 is_nothrow_default_constructible<key_compare>::value &&
205 is_nothrow_copy_constructible<key_compare>::value);
206 explicit multiset(const value_compare& comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000207 multiset(const value_compare& comp, const allocator_type& a);
208 template <class InputIterator>
209 multiset(InputIterator first, InputIterator last,
210 const value_compare& comp = value_compare());
211 template <class InputIterator>
212 multiset(InputIterator first, InputIterator last,
213 const value_compare& comp, const allocator_type& a);
214 multiset(const multiset& s);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000215 multiset(multiset&& s)
216 noexcept(
217 is_nothrow_move_constructible<allocator_type>::value &&
218 is_nothrow_move_constructible<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000219 explicit multiset(const allocator_type& a);
220 multiset(const multiset& s, const allocator_type& a);
221 multiset(multiset&& s, const allocator_type& a);
222 multiset(initializer_list<value_type> il, const value_compare& comp = value_compare());
223 multiset(initializer_list<value_type> il, const value_compare& comp,
224 const allocator_type& a);
225 ~multiset();
226
227 multiset& operator=(const multiset& s);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000228 multiset& operator=(multiset&& s)
229 noexcept(
230 allocator_type::propagate_on_container_move_assignment::value &&
231 is_nothrow_move_assignable<allocator_type>::value &&
232 is_nothrow_move_assignable<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000233 multiset& operator=(initializer_list<value_type> il);
234
235 // iterators:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000236 iterator begin() noexcept;
237 const_iterator begin() const noexcept;
238 iterator end() noexcept;
239 const_iterator end() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000240
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000241 reverse_iterator rbegin() noexcept;
242 const_reverse_iterator rbegin() const noexcept;
243 reverse_iterator rend() noexcept;
244 const_reverse_iterator rend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000245
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000246 const_iterator cbegin() const noexcept;
247 const_iterator cend() const noexcept;
248 const_reverse_iterator crbegin() const noexcept;
249 const_reverse_iterator crend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000250
251 // capacity:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000252 bool empty() const noexcept;
253 size_type size() const noexcept;
254 size_type max_size() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000255
256 // modifiers:
257 template <class... Args>
258 iterator emplace(Args&&... args);
259 template <class... Args>
260 iterator emplace_hint(const_iterator position, Args&&... args);
261 iterator insert(const value_type& v);
262 iterator insert(value_type&& v);
263 iterator insert(const_iterator position, const value_type& v);
264 iterator insert(const_iterator position, value_type&& v);
265 template <class InputIterator>
266 void insert(InputIterator first, InputIterator last);
267 void insert(initializer_list<value_type> il);
268
269 iterator erase(const_iterator position);
270 size_type erase(const key_type& k);
271 iterator erase(const_iterator first, const_iterator last);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000272 void clear() noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000273
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000274 void swap(multiset& s)
275 noexcept(
276 __is_nothrow_swappable<key_compare>::value &&
277 (!allocator_type::propagate_on_container_swap::value ||
278 __is_nothrow_swappable<allocator_type>::value));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000279
280 // observers:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000281 allocator_type get_allocator() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000282 key_compare key_comp() const;
283 value_compare value_comp() const;
284
285 // set operations:
286 iterator find(const key_type& k);
287 const_iterator find(const key_type& k) const;
288 size_type count(const key_type& k) const;
289 iterator lower_bound(const key_type& k);
290 const_iterator lower_bound(const key_type& k) const;
291 iterator upper_bound(const key_type& k);
292 const_iterator upper_bound(const key_type& k) const;
293 pair<iterator,iterator> equal_range(const key_type& k);
294 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
295};
296
297template <class Key, class Compare, class Allocator>
298bool
299operator==(const multiset<Key, Compare, Allocator>& x,
300 const multiset<Key, Compare, Allocator>& y);
301
302template <class Key, class Compare, class Allocator>
303bool
304operator< (const multiset<Key, Compare, Allocator>& x,
305 const multiset<Key, Compare, Allocator>& y);
306
307template <class Key, class Compare, class Allocator>
308bool
309operator!=(const multiset<Key, Compare, Allocator>& x,
310 const multiset<Key, Compare, Allocator>& y);
311
312template <class Key, class Compare, class Allocator>
313bool
314operator> (const multiset<Key, Compare, Allocator>& x,
315 const multiset<Key, Compare, Allocator>& y);
316
317template <class Key, class Compare, class Allocator>
318bool
319operator>=(const multiset<Key, Compare, Allocator>& x,
320 const multiset<Key, Compare, Allocator>& y);
321
322template <class Key, class Compare, class Allocator>
323bool
324operator<=(const multiset<Key, Compare, Allocator>& x,
325 const multiset<Key, Compare, Allocator>& y);
326
327// specialized algorithms:
328template <class Key, class Compare, class Allocator>
329void
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000330swap(multiset<Key, Compare, Allocator>& x, multiset<Key, Compare, Allocator>& y)
331 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000332
333} // std
334
335*/
336
337#include <__config>
338#include <__tree>
339#include <functional>
340
341#pragma GCC system_header
342
343_LIBCPP_BEGIN_NAMESPACE_STD
344
345template <class _Key, class _Compare = less<_Key>,
346 class _Allocator = allocator<_Key> >
Howard Hinnant192cf032010-09-23 16:27:36 +0000347class _LIBCPP_VISIBLE set
Howard Hinnantc51e1022010-05-11 19:42:16 +0000348{
349public:
350 // types:
351 typedef _Key key_type;
352 typedef key_type value_type;
353 typedef _Compare key_compare;
354 typedef key_compare value_compare;
355 typedef _Allocator allocator_type;
356 typedef value_type& reference;
357 typedef const value_type& const_reference;
358
359private:
360 typedef __tree<value_type, value_compare, allocator_type> __base;
361 typedef allocator_traits<allocator_type> __alloc_traits;
362 typedef typename __base::__node_holder __node_holder;
363
364 __base __tree_;
365
366public:
367 typedef typename __base::pointer pointer;
368 typedef typename __base::const_pointer const_pointer;
369 typedef typename __base::size_type size_type;
370 typedef typename __base::difference_type difference_type;
371 typedef typename __base::const_iterator iterator;
372 typedef typename __base::const_iterator const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000373 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
374 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000375
Howard Hinnant192cf032010-09-23 16:27:36 +0000376 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000377 explicit set(const value_compare& __comp = value_compare())
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000378 _NOEXCEPT_(
379 is_nothrow_default_constructible<allocator_type>::value &&
380 is_nothrow_default_constructible<key_compare>::value &&
381 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000382 : __tree_(__comp) {}
Howard Hinnant192cf032010-09-23 16:27:36 +0000383 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000384 set(const value_compare& __comp, const allocator_type& __a)
385 : __tree_(__comp, __a) {}
386 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000387 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000388 set(_InputIterator __f, _InputIterator __l,
389 const value_compare& __comp = value_compare())
390 : __tree_(__comp)
391 {
392 insert(__f, __l);
393 }
394
395 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000396 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000397 set(_InputIterator __f, _InputIterator __l, const value_compare& __comp,
398 const allocator_type& __a)
399 : __tree_(__comp, __a)
400 {
401 insert(__f, __l);
402 }
403
Howard Hinnant192cf032010-09-23 16:27:36 +0000404 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000405 set(const set& __s)
406 : __tree_(__s.__tree_)
407 {
408 insert(__s.begin(), __s.end());
409 }
410
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000411 _LIBCPP_INLINE_VISIBILITY
412 set& operator=(const set& __s)
413 {
414 __tree_ = __s.__tree_;
415 return *this;
416 }
417
Howard Hinnant74279a52010-09-04 23:28:19 +0000418#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant192cf032010-09-23 16:27:36 +0000419 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000420 set(set&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000421 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000422 : __tree_(_VSTD::move(__s.__tree_)) {}
Howard Hinnant74279a52010-09-04 23:28:19 +0000423#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000424
Howard Hinnant192cf032010-09-23 16:27:36 +0000425 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000426 explicit set(const allocator_type& __a)
427 : __tree_(__a) {}
428
Howard Hinnant192cf032010-09-23 16:27:36 +0000429 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000430 set(const set& __s, const allocator_type& __a)
431 : __tree_(__s.__tree_.value_comp(), __a)
432 {
433 insert(__s.begin(), __s.end());
434 }
435
Howard Hinnant74279a52010-09-04 23:28:19 +0000436#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000437 set(set&& __s, const allocator_type& __a);
438#endif
439
Howard Hinnant192cf032010-09-23 16:27:36 +0000440 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000441 set(initializer_list<value_type> __il, const value_compare& __comp = value_compare())
442 : __tree_(__comp)
443 {
444 insert(__il.begin(), __il.end());
445 }
446
Howard Hinnant192cf032010-09-23 16:27:36 +0000447 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000448 set(initializer_list<value_type> __il, const value_compare& __comp,
449 const allocator_type& __a)
450 : __tree_(__comp, __a)
451 {
452 insert(__il.begin(), __il.end());
453 }
454
Howard Hinnant192cf032010-09-23 16:27:36 +0000455 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000456 set& operator=(initializer_list<value_type> __il)
457 {
458 __tree_.__assign_unique(__il.begin(), __il.end());
459 return *this;
460 }
461
Howard Hinnant74279a52010-09-04 23:28:19 +0000462#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant192cf032010-09-23 16:27:36 +0000463 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000464 set& operator=(set&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000465 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000466 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000467 __tree_ = _VSTD::move(__s.__tree_);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000468 return *this;
469 }
Howard Hinnant74279a52010-09-04 23:28:19 +0000470#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000471
Howard Hinnant192cf032010-09-23 16:27:36 +0000472 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000473 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000474 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000475 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000476 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000477 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000478 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000479 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000480
Howard Hinnant192cf032010-09-23 16:27:36 +0000481 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000482 reverse_iterator rbegin() _NOEXCEPT
483 {return reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +0000484 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000485 const_reverse_iterator rbegin() const _NOEXCEPT
486 {return const_reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +0000487 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000488 reverse_iterator rend() _NOEXCEPT
489 {return reverse_iterator(begin());}
Howard Hinnant192cf032010-09-23 16:27:36 +0000490 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000491 const_reverse_iterator rend() const _NOEXCEPT
492 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000493
Howard Hinnant192cf032010-09-23 16:27:36 +0000494 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000495 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000496 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000497 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000498 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000499 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000500 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000501 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000502
Howard Hinnant192cf032010-09-23 16:27:36 +0000503 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000504 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant192cf032010-09-23 16:27:36 +0000505 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000506 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000507 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000508 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000509
510 // modifiers:
Howard Hinnant74279a52010-09-04 23:28:19 +0000511#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000512 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +0000513 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000514 pair<iterator, bool> emplace(_Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000515 {return __tree_.__emplace_unique(_VSTD::forward<_Args>(__args)...);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000516 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +0000517 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000518 iterator emplace_hint(const_iterator __p, _Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000519 {return __tree_.__emplace_hint_unique(__p, _VSTD::forward<_Args>(__args)...);}
Howard Hinnant74279a52010-09-04 23:28:19 +0000520#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnant192cf032010-09-23 16:27:36 +0000521 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000522 pair<iterator,bool> insert(const value_type& __v)
523 {return __tree_.__insert_unique(__v);}
Howard Hinnant74279a52010-09-04 23:28:19 +0000524#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant192cf032010-09-23 16:27:36 +0000525 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000526 pair<iterator,bool> insert(value_type&& __v)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000527 {return __tree_.__insert_unique(_VSTD::move(__v));}
Howard Hinnant74279a52010-09-04 23:28:19 +0000528#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant192cf032010-09-23 16:27:36 +0000529 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000530 iterator insert(const_iterator __p, const value_type& __v)
531 {return __tree_.__insert_unique(__p, __v);}
Howard Hinnant74279a52010-09-04 23:28:19 +0000532#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant192cf032010-09-23 16:27:36 +0000533 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000534 iterator insert(const_iterator __p, value_type&& __v)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000535 {return __tree_.__insert_unique(__p, _VSTD::move(__v));}
Howard Hinnant74279a52010-09-04 23:28:19 +0000536#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000537 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000538 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000539 void insert(_InputIterator __f, _InputIterator __l)
540 {
541 for (const_iterator __e = cend(); __f != __l; ++__f)
542 __tree_.__insert_unique(__e, *__f);
543 }
544
Howard Hinnant192cf032010-09-23 16:27:36 +0000545 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000546 void insert(initializer_list<value_type> __il)
547 {insert(__il.begin(), __il.end());}
548
Howard Hinnant192cf032010-09-23 16:27:36 +0000549 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000550 iterator erase(const_iterator __p) {return __tree_.erase(__p);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000551 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000552 size_type erase(const key_type& __k)
553 {return __tree_.__erase_unique(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000554 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000555 iterator erase(const_iterator __f, const_iterator __l)
556 {return __tree_.erase(__f, __l);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000557 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000558 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000559
Howard Hinnant192cf032010-09-23 16:27:36 +0000560 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000561 void swap(set& __s) _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
562 {__tree_.swap(__s.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000563
Howard Hinnant192cf032010-09-23 16:27:36 +0000564 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000565 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000566 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000567 key_compare key_comp() const {return __tree_.value_comp();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000568 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000569 value_compare value_comp() const {return __tree_.value_comp();}
570
571 // set operations:
Howard Hinnant192cf032010-09-23 16:27:36 +0000572 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000573 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000574 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000575 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000576 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000577 size_type count(const key_type& __k) const
578 {return __tree_.__count_unique(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000579 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000580 iterator lower_bound(const key_type& __k)
581 {return __tree_.lower_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000582 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000583 const_iterator lower_bound(const key_type& __k) const
584 {return __tree_.lower_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000585 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000586 iterator upper_bound(const key_type& __k)
587 {return __tree_.upper_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000588 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000589 const_iterator upper_bound(const key_type& __k) const
590 {return __tree_.upper_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000591 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000592 pair<iterator,iterator> equal_range(const key_type& __k)
593 {return __tree_.__equal_range_unique(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000594 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000595 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
596 {return __tree_.__equal_range_unique(__k);}
597};
598
Howard Hinnant74279a52010-09-04 23:28:19 +0000599#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000600
601template <class _Key, class _Compare, class _Allocator>
602set<_Key, _Compare, _Allocator>::set(set&& __s, const allocator_type& __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000603 : __tree_(_VSTD::move(__s.__tree_), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000604{
605 if (__a != __s.get_allocator())
606 {
607 const_iterator __e = cend();
608 while (!__s.empty())
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000609 insert(__e, _VSTD::move(__s.__tree_.remove(__s.begin())->__value_));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000610 }
611}
612
Howard Hinnant74279a52010-09-04 23:28:19 +0000613#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000614
615template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000616inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000617bool
618operator==(const set<_Key, _Compare, _Allocator>& __x,
619 const set<_Key, _Compare, _Allocator>& __y)
620{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000621 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000622}
623
624template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000625inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000626bool
627operator< (const set<_Key, _Compare, _Allocator>& __x,
628 const set<_Key, _Compare, _Allocator>& __y)
629{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000630 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000631}
632
633template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000634inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000635bool
636operator!=(const set<_Key, _Compare, _Allocator>& __x,
637 const set<_Key, _Compare, _Allocator>& __y)
638{
639 return !(__x == __y);
640}
641
642template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000643inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000644bool
645operator> (const set<_Key, _Compare, _Allocator>& __x,
646 const set<_Key, _Compare, _Allocator>& __y)
647{
648 return __y < __x;
649}
650
651template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000652inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000653bool
654operator>=(const set<_Key, _Compare, _Allocator>& __x,
655 const set<_Key, _Compare, _Allocator>& __y)
656{
657 return !(__x < __y);
658}
659
660template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000661inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000662bool
663operator<=(const set<_Key, _Compare, _Allocator>& __x,
664 const set<_Key, _Compare, _Allocator>& __y)
665{
666 return !(__y < __x);
667}
668
669// specialized algorithms:
670template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000671inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000672void
673swap(set<_Key, _Compare, _Allocator>& __x,
674 set<_Key, _Compare, _Allocator>& __y)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000675 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000676{
677 __x.swap(__y);
678}
679
Howard Hinnantc51e1022010-05-11 19:42:16 +0000680template <class _Key, class _Compare = less<_Key>,
681 class _Allocator = allocator<_Key> >
Howard Hinnant192cf032010-09-23 16:27:36 +0000682class _LIBCPP_VISIBLE multiset
Howard Hinnantc51e1022010-05-11 19:42:16 +0000683{
684public:
685 // types:
686 typedef _Key key_type;
687 typedef key_type value_type;
688 typedef _Compare key_compare;
689 typedef key_compare value_compare;
690 typedef _Allocator allocator_type;
691 typedef value_type& reference;
692 typedef const value_type& const_reference;
693
694private:
695 typedef __tree<value_type, value_compare, allocator_type> __base;
696 typedef allocator_traits<allocator_type> __alloc_traits;
697 typedef typename __base::__node_holder __node_holder;
698
699 __base __tree_;
700
701public:
702 typedef typename __base::pointer pointer;
703 typedef typename __base::const_pointer const_pointer;
704 typedef typename __base::size_type size_type;
705 typedef typename __base::difference_type difference_type;
706 typedef typename __base::const_iterator iterator;
707 typedef typename __base::const_iterator const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000708 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
709 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000710
711 // construct/copy/destroy:
Howard Hinnant192cf032010-09-23 16:27:36 +0000712 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000713 explicit multiset(const value_compare& __comp = value_compare())
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000714 _NOEXCEPT_(
715 is_nothrow_default_constructible<allocator_type>::value &&
716 is_nothrow_default_constructible<key_compare>::value &&
717 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000718 : __tree_(__comp) {}
Howard Hinnant192cf032010-09-23 16:27:36 +0000719 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000720 multiset(const value_compare& __comp, const allocator_type& __a)
721 : __tree_(__comp, __a) {}
722 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000723 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000724 multiset(_InputIterator __f, _InputIterator __l,
725 const value_compare& __comp = value_compare())
726 : __tree_(__comp)
727 {
728 insert(__f, __l);
729 }
730
731 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000732 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000733 multiset(_InputIterator __f, _InputIterator __l,
734 const value_compare& __comp, const allocator_type& __a)
735 : __tree_(__comp, __a)
736 {
737 insert(__f, __l);
738 }
739
Howard Hinnant192cf032010-09-23 16:27:36 +0000740 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000741 multiset(const multiset& __s)
742 : __tree_(__s.__tree_.value_comp(),
743 __alloc_traits::select_on_container_copy_construction(__s.__tree_.__alloc()))
744 {
745 insert(__s.begin(), __s.end());
746 }
747
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000748 _LIBCPP_INLINE_VISIBILITY
749 multiset& operator=(const multiset& __s)
750 {
751 __tree_ = __s.__tree_;
752 return *this;
753 }
754
Howard Hinnant74279a52010-09-04 23:28:19 +0000755#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant192cf032010-09-23 16:27:36 +0000756 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000757 multiset(multiset&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000758 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000759 : __tree_(_VSTD::move(__s.__tree_)) {}
Howard Hinnant74279a52010-09-04 23:28:19 +0000760#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant192cf032010-09-23 16:27:36 +0000761 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000762 explicit multiset(const allocator_type& __a)
763 : __tree_(__a) {}
Howard Hinnant192cf032010-09-23 16:27:36 +0000764 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000765 multiset(const multiset& __s, const allocator_type& __a)
766 : __tree_(__s.__tree_.value_comp(), __a)
767 {
768 insert(__s.begin(), __s.end());
769 }
Howard Hinnant74279a52010-09-04 23:28:19 +0000770#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000771 multiset(multiset&& __s, const allocator_type& __a);
772#endif
773
Howard Hinnant192cf032010-09-23 16:27:36 +0000774 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000775 multiset(initializer_list<value_type> __il, const value_compare& __comp = value_compare())
776 : __tree_(__comp)
777 {
778 insert(__il.begin(), __il.end());
779 }
780
Howard Hinnant192cf032010-09-23 16:27:36 +0000781 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000782 multiset(initializer_list<value_type> __il, const value_compare& __comp,
783 const allocator_type& __a)
784 : __tree_(__comp, __a)
785 {
786 insert(__il.begin(), __il.end());
787 }
788
Howard Hinnant192cf032010-09-23 16:27:36 +0000789 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000790 multiset& operator=(initializer_list<value_type> __il)
791 {
792 __tree_.__assign_multi(__il.begin(), __il.end());
793 return *this;
794 }
795
Howard Hinnant74279a52010-09-04 23:28:19 +0000796#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant192cf032010-09-23 16:27:36 +0000797 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000798 multiset& operator=(multiset&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000799 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000800 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000801 __tree_ = _VSTD::move(__s.__tree_);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000802 return *this;
803 }
Howard Hinnant74279a52010-09-04 23:28:19 +0000804#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000805
Howard Hinnant192cf032010-09-23 16:27:36 +0000806 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000807 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000808 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000809 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000810 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000811 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000812 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000813 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000814
Howard Hinnant192cf032010-09-23 16:27:36 +0000815 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000816 reverse_iterator rbegin() _NOEXCEPT
817 {return reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +0000818 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000819 const_reverse_iterator rbegin() const _NOEXCEPT
820 {return const_reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +0000821 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000822 reverse_iterator rend() _NOEXCEPT
823 {return reverse_iterator(begin());}
Howard Hinnant192cf032010-09-23 16:27:36 +0000824 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000825 const_reverse_iterator rend() const _NOEXCEPT
826 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000827
Howard Hinnant192cf032010-09-23 16:27:36 +0000828 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000829 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000830 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000831 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000832 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000833 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000834 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000835 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000836
Howard Hinnant192cf032010-09-23 16:27:36 +0000837 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000838 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant192cf032010-09-23 16:27:36 +0000839 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000840 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000841 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000842 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000843
844 // modifiers:
Howard Hinnant74279a52010-09-04 23:28:19 +0000845#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000846 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +0000847 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000848 iterator emplace(_Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000849 {return __tree_.__emplace_multi(_VSTD::forward<_Args>(__args)...);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000850 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +0000851 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000852 iterator emplace_hint(const_iterator __p, _Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000853 {return __tree_.__emplace_hint_multi(__p, _VSTD::forward<_Args>(__args)...);}
Howard Hinnant74279a52010-09-04 23:28:19 +0000854#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnant192cf032010-09-23 16:27:36 +0000855 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000856 iterator insert(const value_type& __v)
857 {return __tree_.__insert_multi(__v);}
Howard Hinnant74279a52010-09-04 23:28:19 +0000858#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant192cf032010-09-23 16:27:36 +0000859 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000860 iterator insert(value_type&& __v)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000861 {return __tree_.__insert_multi(_VSTD::move(__v));}
Howard Hinnant74279a52010-09-04 23:28:19 +0000862#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant192cf032010-09-23 16:27:36 +0000863 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000864 iterator insert(const_iterator __p, const value_type& __v)
865 {return __tree_.__insert_multi(__p, __v);}
Howard Hinnant74279a52010-09-04 23:28:19 +0000866#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant192cf032010-09-23 16:27:36 +0000867 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000868 iterator insert(const_iterator __p, value_type&& __v)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000869 {return __tree_.__insert_multi(_VSTD::move(__v));}
Howard Hinnant74279a52010-09-04 23:28:19 +0000870#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000871 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000872 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000873 void insert(_InputIterator __f, _InputIterator __l)
874 {
875 for (const_iterator __e = cend(); __f != __l; ++__f)
876 __tree_.__insert_multi(__e, *__f);
877 }
878
Howard Hinnant192cf032010-09-23 16:27:36 +0000879 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000880 void insert(initializer_list<value_type> __il)
881 {insert(__il.begin(), __il.end());}
882
Howard Hinnant192cf032010-09-23 16:27:36 +0000883 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000884 iterator erase(const_iterator __p) {return __tree_.erase(__p);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000885 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000886 size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000887 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000888 iterator erase(const_iterator __f, const_iterator __l)
889 {return __tree_.erase(__f, __l);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000890 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000891 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000892
Howard Hinnant192cf032010-09-23 16:27:36 +0000893 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000894 void swap(multiset& __s)
895 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
896 {__tree_.swap(__s.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000897
Howard Hinnant192cf032010-09-23 16:27:36 +0000898 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000899 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000900 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000901 key_compare key_comp() const {return __tree_.value_comp();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000902 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000903 value_compare value_comp() const {return __tree_.value_comp();}
904
905 // set operations:
Howard Hinnant192cf032010-09-23 16:27:36 +0000906 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000907 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000908 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000909 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000910 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000911 size_type count(const key_type& __k) const
912 {return __tree_.__count_multi(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000913 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000914 iterator lower_bound(const key_type& __k)
915 {return __tree_.lower_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000916 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000917 const_iterator lower_bound(const key_type& __k) const
918 {return __tree_.lower_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000919 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000920 iterator upper_bound(const key_type& __k)
921 {return __tree_.upper_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000922 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000923 const_iterator upper_bound(const key_type& __k) const
924 {return __tree_.upper_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000925 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000926 pair<iterator,iterator> equal_range(const key_type& __k)
927 {return __tree_.__equal_range_multi(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000928 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000929 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
930 {return __tree_.__equal_range_multi(__k);}
931};
932
Howard Hinnant74279a52010-09-04 23:28:19 +0000933#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000934
935template <class _Key, class _Compare, class _Allocator>
936multiset<_Key, _Compare, _Allocator>::multiset(multiset&& __s, const allocator_type& __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000937 : __tree_(_VSTD::move(__s.__tree_), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000938{
939 if (__a != __s.get_allocator())
940 {
941 const_iterator __e = cend();
942 while (!__s.empty())
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000943 insert(__e, _VSTD::move(__s.__tree_.remove(__s.begin())->__value_));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000944 }
945}
946
Howard Hinnant74279a52010-09-04 23:28:19 +0000947#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000948
949template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000950inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000951bool
952operator==(const multiset<_Key, _Compare, _Allocator>& __x,
953 const multiset<_Key, _Compare, _Allocator>& __y)
954{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000955 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000956}
957
958template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000959inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000960bool
961operator< (const multiset<_Key, _Compare, _Allocator>& __x,
962 const multiset<_Key, _Compare, _Allocator>& __y)
963{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000964 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000965}
966
967template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000968inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000969bool
970operator!=(const multiset<_Key, _Compare, _Allocator>& __x,
971 const multiset<_Key, _Compare, _Allocator>& __y)
972{
973 return !(__x == __y);
974}
975
976template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000977inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000978bool
979operator> (const multiset<_Key, _Compare, _Allocator>& __x,
980 const multiset<_Key, _Compare, _Allocator>& __y)
981{
982 return __y < __x;
983}
984
985template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000986inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000987bool
988operator>=(const multiset<_Key, _Compare, _Allocator>& __x,
989 const multiset<_Key, _Compare, _Allocator>& __y)
990{
991 return !(__x < __y);
992}
993
994template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000995inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000996bool
997operator<=(const multiset<_Key, _Compare, _Allocator>& __x,
998 const multiset<_Key, _Compare, _Allocator>& __y)
999{
1000 return !(__y < __x);
1001}
1002
1003template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001004inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001005void
1006swap(multiset<_Key, _Compare, _Allocator>& __x,
1007 multiset<_Key, _Compare, _Allocator>& __y)
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001008 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001009{
1010 __x.swap(__y);
1011}
1012
Howard Hinnantc51e1022010-05-11 19:42:16 +00001013_LIBCPP_END_NAMESPACE_STD
1014
1015#endif // _LIBCPP_SET