blob: 0f8a19adfe4dc321a0a5ba14bd619616ca0268a0 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===---------------------------- set -------------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005//
Howard Hinnantb64f8b02010-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 Hinnantbc8d3f92010-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 Hinnantb2e2a8f2011-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 Hinnantbc8d3f92010-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 Hinnantb2e2a8f2011-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 Hinnantbc8d3f92010-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 Hinnantb2e2a8f2011-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 Hinnantbc8d3f92010-05-11 19:42:16 +000077 set& operator=(initializer_list<value_type> il);
78
79 // iterators:
Howard Hinnantb2e2a8f2011-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 Hinnantbc8d3f92010-05-11 19:42:16 +000084
Howard Hinnantb2e2a8f2011-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 Hinnantbc8d3f92010-05-11 19:42:16 +000089
Howard Hinnantb2e2a8f2011-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 Hinnantbc8d3f92010-05-11 19:42:16 +000094
95 // capacity:
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +000096 bool empty() const noexcept;
97 size_type size() const noexcept;
98 size_type max_size() const noexcept;
Howard Hinnantbc8d3f92010-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 Hinnantb2e2a8f2011-06-04 15:22:34 +0000116 void clear() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000117
Howard Hinnantb2e2a8f2011-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 Hinnantbc8d3f92010-05-11 19:42:16 +0000123
124 // observers:
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000125 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-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 Hinnantb2e2a8f2011-06-04 15:22:34 +0000174swap(set<Key, Compare, Allocator>& x, set<Key, Compare, Allocator>& y)
175 noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000176
Howard Hinnantbc8d3f92010-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 Hinnantb2e2a8f2011-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 Hinnantbc8d3f92010-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 Hinnantb2e2a8f2011-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 Hinnantbc8d3f92010-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 Hinnantb2e2a8f2011-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 Hinnantbc8d3f92010-05-11 19:42:16 +0000233 multiset& operator=(initializer_list<value_type> il);
234
235 // iterators:
Howard Hinnantb2e2a8f2011-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 Hinnantbc8d3f92010-05-11 19:42:16 +0000240
Howard Hinnantb2e2a8f2011-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 Hinnantbc8d3f92010-05-11 19:42:16 +0000245
Howard Hinnantb2e2a8f2011-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 Hinnantbc8d3f92010-05-11 19:42:16 +0000250
251 // capacity:
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000252 bool empty() const noexcept;
253 size_type size() const noexcept;
254 size_type max_size() const noexcept;
Howard Hinnantbc8d3f92010-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 Hinnantb2e2a8f2011-06-04 15:22:34 +0000272 void clear() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000273
Howard Hinnantb2e2a8f2011-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 Hinnantbc8d3f92010-05-11 19:42:16 +0000279
280 // observers:
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000281 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-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 Hinnantb2e2a8f2011-06-04 15:22:34 +0000330swap(multiset<Key, Compare, Allocator>& x, multiset<Key, Compare, Allocator>& y)
331 noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-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 Hinnant28c97e62010-09-23 16:27:36 +0000347class _LIBCPP_VISIBLE set
Howard Hinnantbc8d3f92010-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;
373 typedef _STD::reverse_iterator<iterator> reverse_iterator;
374 typedef _STD::reverse_iterator<const_iterator> const_reverse_iterator;
375
Howard Hinnant28c97e62010-09-23 16:27:36 +0000376 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000377 explicit set(const value_compare& __comp = value_compare())
Howard Hinnantb2e2a8f2011-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 Hinnantbc8d3f92010-05-11 19:42:16 +0000382 : __tree_(__comp) {}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000383 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000384 set(const value_compare& __comp, const allocator_type& __a)
385 : __tree_(__comp, __a) {}
386 template <class _InputIterator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000387 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-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 Hinnant28c97e62010-09-23 16:27:36 +0000396 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-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 Hinnant28c97e62010-09-23 16:27:36 +0000404 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000405 set(const set& __s)
406 : __tree_(__s.__tree_)
407 {
408 insert(__s.begin(), __s.end());
409 }
410
Howard Hinnant73d21a42010-09-04 23:28:19 +0000411#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant28c97e62010-09-23 16:27:36 +0000412 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000413 set(set&& __s)
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000414 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000415 : __tree_(_STD::move(__s.__tree_)) {}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000416#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000417
Howard Hinnant28c97e62010-09-23 16:27:36 +0000418 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000419 explicit set(const allocator_type& __a)
420 : __tree_(__a) {}
421
Howard Hinnant28c97e62010-09-23 16:27:36 +0000422 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000423 set(const set& __s, const allocator_type& __a)
424 : __tree_(__s.__tree_.value_comp(), __a)
425 {
426 insert(__s.begin(), __s.end());
427 }
428
Howard Hinnant73d21a42010-09-04 23:28:19 +0000429#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000430 set(set&& __s, const allocator_type& __a);
431#endif
432
Howard Hinnant28c97e62010-09-23 16:27:36 +0000433 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000434 set(initializer_list<value_type> __il, const value_compare& __comp = value_compare())
435 : __tree_(__comp)
436 {
437 insert(__il.begin(), __il.end());
438 }
439
Howard Hinnant28c97e62010-09-23 16:27:36 +0000440 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000441 set(initializer_list<value_type> __il, const value_compare& __comp,
442 const allocator_type& __a)
443 : __tree_(__comp, __a)
444 {
445 insert(__il.begin(), __il.end());
446 }
447
Howard Hinnant28c97e62010-09-23 16:27:36 +0000448 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000449 set& operator=(initializer_list<value_type> __il)
450 {
451 __tree_.__assign_unique(__il.begin(), __il.end());
452 return *this;
453 }
454
Howard Hinnant73d21a42010-09-04 23:28:19 +0000455#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant28c97e62010-09-23 16:27:36 +0000456 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000457 set& operator=(set&& __s)
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000458 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000459 {
460 __tree_ = _STD::move(__s.__tree_);
461 return *this;
462 }
Howard Hinnant73d21a42010-09-04 23:28:19 +0000463#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000464
Howard Hinnant28c97e62010-09-23 16:27:36 +0000465 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000466 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000467 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000468 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000469 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000470 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000471 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000472 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000473
Howard Hinnant28c97e62010-09-23 16:27:36 +0000474 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000475 reverse_iterator rbegin() _NOEXCEPT
476 {return reverse_iterator(end());}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000477 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000478 const_reverse_iterator rbegin() const _NOEXCEPT
479 {return const_reverse_iterator(end());}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000480 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000481 reverse_iterator rend() _NOEXCEPT
482 {return reverse_iterator(begin());}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000483 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000484 const_reverse_iterator rend() const _NOEXCEPT
485 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000486
Howard Hinnant28c97e62010-09-23 16:27:36 +0000487 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000488 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000489 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000490 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000491 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000492 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000493 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000494 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000495
Howard Hinnant28c97e62010-09-23 16:27:36 +0000496 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000497 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000498 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000499 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000500 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000501 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000502
503 // modifiers:
Howard Hinnant73d21a42010-09-04 23:28:19 +0000504#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000505 template <class... _Args>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000506 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000507 pair<iterator, bool> emplace(_Args&&... __args)
508 {return __tree_.__emplace_unique(_STD::forward<_Args>(__args)...);}
509 template <class... _Args>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000510 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000511 iterator emplace_hint(const_iterator __p, _Args&&... __args)
512 {return __tree_.__emplace_hint_unique(__p, _STD::forward<_Args>(__args)...);}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000513#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnant28c97e62010-09-23 16:27:36 +0000514 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000515 pair<iterator,bool> insert(const value_type& __v)
516 {return __tree_.__insert_unique(__v);}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000517#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant28c97e62010-09-23 16:27:36 +0000518 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000519 pair<iterator,bool> insert(value_type&& __v)
520 {return __tree_.__insert_unique(_STD::move(__v));}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000521#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant28c97e62010-09-23 16:27:36 +0000522 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000523 iterator insert(const_iterator __p, const value_type& __v)
524 {return __tree_.__insert_unique(__p, __v);}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000525#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant28c97e62010-09-23 16:27:36 +0000526 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000527 iterator insert(const_iterator __p, value_type&& __v)
528 {return __tree_.__insert_unique(__p, _STD::move(__v));}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000529#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000530 template <class _InputIterator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000531 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000532 void insert(_InputIterator __f, _InputIterator __l)
533 {
534 for (const_iterator __e = cend(); __f != __l; ++__f)
535 __tree_.__insert_unique(__e, *__f);
536 }
537
Howard Hinnant28c97e62010-09-23 16:27:36 +0000538 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000539 void insert(initializer_list<value_type> __il)
540 {insert(__il.begin(), __il.end());}
541
Howard Hinnant28c97e62010-09-23 16:27:36 +0000542 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000543 iterator erase(const_iterator __p) {return __tree_.erase(__p);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000544 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000545 size_type erase(const key_type& __k)
546 {return __tree_.__erase_unique(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000547 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000548 iterator erase(const_iterator __f, const_iterator __l)
549 {return __tree_.erase(__f, __l);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000550 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000551 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000552
Howard Hinnant28c97e62010-09-23 16:27:36 +0000553 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000554 void swap(set& __s) _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
555 {__tree_.swap(__s.__tree_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000556
Howard Hinnant28c97e62010-09-23 16:27:36 +0000557 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000558 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000559 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000560 key_compare key_comp() const {return __tree_.value_comp();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000561 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000562 value_compare value_comp() const {return __tree_.value_comp();}
563
564 // set operations:
Howard Hinnant28c97e62010-09-23 16:27:36 +0000565 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000566 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000567 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000568 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000569 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000570 size_type count(const key_type& __k) const
571 {return __tree_.__count_unique(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000572 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000573 iterator lower_bound(const key_type& __k)
574 {return __tree_.lower_bound(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000575 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000576 const_iterator lower_bound(const key_type& __k) const
577 {return __tree_.lower_bound(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000578 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000579 iterator upper_bound(const key_type& __k)
580 {return __tree_.upper_bound(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000581 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000582 const_iterator upper_bound(const key_type& __k) const
583 {return __tree_.upper_bound(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000584 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000585 pair<iterator,iterator> equal_range(const key_type& __k)
586 {return __tree_.__equal_range_unique(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000587 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000588 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
589 {return __tree_.__equal_range_unique(__k);}
590};
591
Howard Hinnant73d21a42010-09-04 23:28:19 +0000592#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000593
594template <class _Key, class _Compare, class _Allocator>
595set<_Key, _Compare, _Allocator>::set(set&& __s, const allocator_type& __a)
596 : __tree_(_STD::move(__s.__tree_), __a)
597{
598 if (__a != __s.get_allocator())
599 {
600 const_iterator __e = cend();
601 while (!__s.empty())
602 insert(__e, _STD::move(__s.__tree_.remove(__s.begin())->__value_));
603 }
604}
605
Howard Hinnant73d21a42010-09-04 23:28:19 +0000606#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000607
608template <class _Key, class _Compare, class _Allocator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000609inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000610bool
611operator==(const set<_Key, _Compare, _Allocator>& __x,
612 const set<_Key, _Compare, _Allocator>& __y)
613{
614 return __x.size() == __y.size() && _STD::equal(__x.begin(), __x.end(), __y.begin());
615}
616
617template <class _Key, class _Compare, class _Allocator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000618inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000619bool
620operator< (const set<_Key, _Compare, _Allocator>& __x,
621 const set<_Key, _Compare, _Allocator>& __y)
622{
623 return _STD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
624}
625
626template <class _Key, class _Compare, class _Allocator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000627inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000628bool
629operator!=(const set<_Key, _Compare, _Allocator>& __x,
630 const set<_Key, _Compare, _Allocator>& __y)
631{
632 return !(__x == __y);
633}
634
635template <class _Key, class _Compare, class _Allocator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000636inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000637bool
638operator> (const set<_Key, _Compare, _Allocator>& __x,
639 const set<_Key, _Compare, _Allocator>& __y)
640{
641 return __y < __x;
642}
643
644template <class _Key, class _Compare, class _Allocator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000645inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000646bool
647operator>=(const set<_Key, _Compare, _Allocator>& __x,
648 const set<_Key, _Compare, _Allocator>& __y)
649{
650 return !(__x < __y);
651}
652
653template <class _Key, class _Compare, class _Allocator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000654inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000655bool
656operator<=(const set<_Key, _Compare, _Allocator>& __x,
657 const set<_Key, _Compare, _Allocator>& __y)
658{
659 return !(__y < __x);
660}
661
662// specialized algorithms:
663template <class _Key, class _Compare, class _Allocator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000664inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000665void
666swap(set<_Key, _Compare, _Allocator>& __x,
667 set<_Key, _Compare, _Allocator>& __y)
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000668 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000669{
670 __x.swap(__y);
671}
672
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000673template <class _Key, class _Compare = less<_Key>,
674 class _Allocator = allocator<_Key> >
Howard Hinnant28c97e62010-09-23 16:27:36 +0000675class _LIBCPP_VISIBLE multiset
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000676{
677public:
678 // types:
679 typedef _Key key_type;
680 typedef key_type value_type;
681 typedef _Compare key_compare;
682 typedef key_compare value_compare;
683 typedef _Allocator allocator_type;
684 typedef value_type& reference;
685 typedef const value_type& const_reference;
686
687private:
688 typedef __tree<value_type, value_compare, allocator_type> __base;
689 typedef allocator_traits<allocator_type> __alloc_traits;
690 typedef typename __base::__node_holder __node_holder;
691
692 __base __tree_;
693
694public:
695 typedef typename __base::pointer pointer;
696 typedef typename __base::const_pointer const_pointer;
697 typedef typename __base::size_type size_type;
698 typedef typename __base::difference_type difference_type;
699 typedef typename __base::const_iterator iterator;
700 typedef typename __base::const_iterator const_iterator;
701 typedef _STD::reverse_iterator<iterator> reverse_iterator;
702 typedef _STD::reverse_iterator<const_iterator> const_reverse_iterator;
703
704 // construct/copy/destroy:
Howard Hinnant28c97e62010-09-23 16:27:36 +0000705 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000706 explicit multiset(const value_compare& __comp = value_compare())
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000707 _NOEXCEPT_(
708 is_nothrow_default_constructible<allocator_type>::value &&
709 is_nothrow_default_constructible<key_compare>::value &&
710 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000711 : __tree_(__comp) {}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000712 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000713 multiset(const value_compare& __comp, const allocator_type& __a)
714 : __tree_(__comp, __a) {}
715 template <class _InputIterator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000716 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000717 multiset(_InputIterator __f, _InputIterator __l,
718 const value_compare& __comp = value_compare())
719 : __tree_(__comp)
720 {
721 insert(__f, __l);
722 }
723
724 template <class _InputIterator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000725 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000726 multiset(_InputIterator __f, _InputIterator __l,
727 const value_compare& __comp, const allocator_type& __a)
728 : __tree_(__comp, __a)
729 {
730 insert(__f, __l);
731 }
732
Howard Hinnant28c97e62010-09-23 16:27:36 +0000733 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000734 multiset(const multiset& __s)
735 : __tree_(__s.__tree_.value_comp(),
736 __alloc_traits::select_on_container_copy_construction(__s.__tree_.__alloc()))
737 {
738 insert(__s.begin(), __s.end());
739 }
740
Howard Hinnant73d21a42010-09-04 23:28:19 +0000741#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant28c97e62010-09-23 16:27:36 +0000742 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000743 multiset(multiset&& __s)
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000744 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000745 : __tree_(_STD::move(__s.__tree_)) {}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000746#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant28c97e62010-09-23 16:27:36 +0000747 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000748 explicit multiset(const allocator_type& __a)
749 : __tree_(__a) {}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000750 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000751 multiset(const multiset& __s, const allocator_type& __a)
752 : __tree_(__s.__tree_.value_comp(), __a)
753 {
754 insert(__s.begin(), __s.end());
755 }
Howard Hinnant73d21a42010-09-04 23:28:19 +0000756#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000757 multiset(multiset&& __s, const allocator_type& __a);
758#endif
759
Howard Hinnant28c97e62010-09-23 16:27:36 +0000760 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000761 multiset(initializer_list<value_type> __il, const value_compare& __comp = value_compare())
762 : __tree_(__comp)
763 {
764 insert(__il.begin(), __il.end());
765 }
766
Howard Hinnant28c97e62010-09-23 16:27:36 +0000767 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000768 multiset(initializer_list<value_type> __il, const value_compare& __comp,
769 const allocator_type& __a)
770 : __tree_(__comp, __a)
771 {
772 insert(__il.begin(), __il.end());
773 }
774
Howard Hinnant28c97e62010-09-23 16:27:36 +0000775 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000776 multiset& operator=(initializer_list<value_type> __il)
777 {
778 __tree_.__assign_multi(__il.begin(), __il.end());
779 return *this;
780 }
781
Howard Hinnant73d21a42010-09-04 23:28:19 +0000782#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant28c97e62010-09-23 16:27:36 +0000783 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000784 multiset& operator=(multiset&& __s)
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000785 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000786 {
787 __tree_ = _STD::move(__s.__tree_);
788 return *this;
789 }
Howard Hinnant73d21a42010-09-04 23:28:19 +0000790#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000791
Howard Hinnant28c97e62010-09-23 16:27:36 +0000792 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000793 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000794 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000795 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000796 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000797 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000798 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000799 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000800
Howard Hinnant28c97e62010-09-23 16:27:36 +0000801 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000802 reverse_iterator rbegin() _NOEXCEPT
803 {return reverse_iterator(end());}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000804 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000805 const_reverse_iterator rbegin() const _NOEXCEPT
806 {return const_reverse_iterator(end());}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000807 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000808 reverse_iterator rend() _NOEXCEPT
809 {return reverse_iterator(begin());}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000810 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000811 const_reverse_iterator rend() const _NOEXCEPT
812 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000813
Howard Hinnant28c97e62010-09-23 16:27:36 +0000814 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000815 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000816 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000817 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000818 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000819 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000820 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000821 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000822
Howard Hinnant28c97e62010-09-23 16:27:36 +0000823 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000824 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000825 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000826 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000827 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000828 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000829
830 // modifiers:
Howard Hinnant73d21a42010-09-04 23:28:19 +0000831#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000832 template <class... _Args>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000833 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000834 iterator emplace(_Args&&... __args)
835 {return __tree_.__emplace_multi(_STD::forward<_Args>(__args)...);}
836 template <class... _Args>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000837 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000838 iterator emplace_hint(const_iterator __p, _Args&&... __args)
839 {return __tree_.__emplace_hint_multi(__p, _STD::forward<_Args>(__args)...);}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000840#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnant28c97e62010-09-23 16:27:36 +0000841 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000842 iterator insert(const value_type& __v)
843 {return __tree_.__insert_multi(__v);}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000844#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant28c97e62010-09-23 16:27:36 +0000845 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000846 iterator insert(value_type&& __v)
847 {return __tree_.__insert_multi(_STD::move(__v));}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000848#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant28c97e62010-09-23 16:27:36 +0000849 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000850 iterator insert(const_iterator __p, const value_type& __v)
851 {return __tree_.__insert_multi(__p, __v);}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000852#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant28c97e62010-09-23 16:27:36 +0000853 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000854 iterator insert(const_iterator __p, value_type&& __v)
855 {return __tree_.__insert_multi(_STD::move(__v));}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000856#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000857 template <class _InputIterator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000858 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000859 void insert(_InputIterator __f, _InputIterator __l)
860 {
861 for (const_iterator __e = cend(); __f != __l; ++__f)
862 __tree_.__insert_multi(__e, *__f);
863 }
864
Howard Hinnant28c97e62010-09-23 16:27:36 +0000865 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000866 void insert(initializer_list<value_type> __il)
867 {insert(__il.begin(), __il.end());}
868
Howard Hinnant28c97e62010-09-23 16:27:36 +0000869 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000870 iterator erase(const_iterator __p) {return __tree_.erase(__p);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000871 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000872 size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000873 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000874 iterator erase(const_iterator __f, const_iterator __l)
875 {return __tree_.erase(__f, __l);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000876 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000877 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000878
Howard Hinnant28c97e62010-09-23 16:27:36 +0000879 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000880 void swap(multiset& __s)
881 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
882 {__tree_.swap(__s.__tree_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000883
Howard Hinnant28c97e62010-09-23 16:27:36 +0000884 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000885 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000886 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000887 key_compare key_comp() const {return __tree_.value_comp();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000888 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000889 value_compare value_comp() const {return __tree_.value_comp();}
890
891 // set operations:
Howard Hinnant28c97e62010-09-23 16:27:36 +0000892 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000893 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000894 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000895 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000896 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000897 size_type count(const key_type& __k) const
898 {return __tree_.__count_multi(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000899 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000900 iterator lower_bound(const key_type& __k)
901 {return __tree_.lower_bound(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000902 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000903 const_iterator lower_bound(const key_type& __k) const
904 {return __tree_.lower_bound(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000905 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000906 iterator upper_bound(const key_type& __k)
907 {return __tree_.upper_bound(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000908 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000909 const_iterator upper_bound(const key_type& __k) const
910 {return __tree_.upper_bound(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000911 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000912 pair<iterator,iterator> equal_range(const key_type& __k)
913 {return __tree_.__equal_range_multi(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000914 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000915 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
916 {return __tree_.__equal_range_multi(__k);}
917};
918
Howard Hinnant73d21a42010-09-04 23:28:19 +0000919#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000920
921template <class _Key, class _Compare, class _Allocator>
922multiset<_Key, _Compare, _Allocator>::multiset(multiset&& __s, const allocator_type& __a)
923 : __tree_(_STD::move(__s.__tree_), __a)
924{
925 if (__a != __s.get_allocator())
926 {
927 const_iterator __e = cend();
928 while (!__s.empty())
929 insert(__e, _STD::move(__s.__tree_.remove(__s.begin())->__value_));
930 }
931}
932
Howard Hinnant73d21a42010-09-04 23:28:19 +0000933#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000934
935template <class _Key, class _Compare, class _Allocator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000936inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000937bool
938operator==(const multiset<_Key, _Compare, _Allocator>& __x,
939 const multiset<_Key, _Compare, _Allocator>& __y)
940{
941 return __x.size() == __y.size() && _STD::equal(__x.begin(), __x.end(), __y.begin());
942}
943
944template <class _Key, class _Compare, class _Allocator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000945inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000946bool
947operator< (const multiset<_Key, _Compare, _Allocator>& __x,
948 const multiset<_Key, _Compare, _Allocator>& __y)
949{
950 return _STD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
951}
952
953template <class _Key, class _Compare, class _Allocator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000954inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000955bool
956operator!=(const multiset<_Key, _Compare, _Allocator>& __x,
957 const multiset<_Key, _Compare, _Allocator>& __y)
958{
959 return !(__x == __y);
960}
961
962template <class _Key, class _Compare, class _Allocator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000963inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000964bool
965operator> (const multiset<_Key, _Compare, _Allocator>& __x,
966 const multiset<_Key, _Compare, _Allocator>& __y)
967{
968 return __y < __x;
969}
970
971template <class _Key, class _Compare, class _Allocator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000972inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000973bool
974operator>=(const multiset<_Key, _Compare, _Allocator>& __x,
975 const multiset<_Key, _Compare, _Allocator>& __y)
976{
977 return !(__x < __y);
978}
979
980template <class _Key, class _Compare, class _Allocator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000981inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000982bool
983operator<=(const multiset<_Key, _Compare, _Allocator>& __x,
984 const multiset<_Key, _Compare, _Allocator>& __y)
985{
986 return !(__y < __x);
987}
988
989template <class _Key, class _Compare, class _Allocator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000990inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000991void
992swap(multiset<_Key, _Compare, _Allocator>& __x,
993 multiset<_Key, _Compare, _Allocator>& __y)
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000994 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000995{
996 __x.swap(__y);
997}
998
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000999_LIBCPP_END_NAMESPACE_STD
1000
1001#endif // _LIBCPP_SET