blob: fe3d382768e3d45f93f183bf5b84093d21797454 [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;
Howard Hinnant0949eed2011-06-30 21:18:19 +0000373 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
374 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000375
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 Hinnant61aa6012011-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 Hinnant73d21a42010-09-04 23:28:19 +0000418#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant28c97e62010-09-23 16:27:36 +0000419 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000420 set(set&& __s)
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000421 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000422 : __tree_(_VSTD::move(__s.__tree_)) {}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000423#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000424
Howard Hinnant28c97e62010-09-23 16:27:36 +0000425 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000426 explicit set(const allocator_type& __a)
427 : __tree_(__a) {}
428
Howard Hinnant28c97e62010-09-23 16:27:36 +0000429 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-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 Hinnant73d21a42010-09-04 23:28:19 +0000436#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000437 set(set&& __s, const allocator_type& __a);
438#endif
439
Howard Hinnante3e32912011-08-12 21:56:02 +0000440#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant28c97e62010-09-23 16:27:36 +0000441 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000442 set(initializer_list<value_type> __il, const value_compare& __comp = value_compare())
443 : __tree_(__comp)
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(initializer_list<value_type> __il, const value_compare& __comp,
450 const allocator_type& __a)
451 : __tree_(__comp, __a)
452 {
453 insert(__il.begin(), __il.end());
454 }
455
Howard Hinnant28c97e62010-09-23 16:27:36 +0000456 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000457 set& operator=(initializer_list<value_type> __il)
458 {
459 __tree_.__assign_unique(__il.begin(), __il.end());
460 return *this;
461 }
Howard Hinnante3e32912011-08-12 21:56:02 +0000462#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000463
Howard Hinnant73d21a42010-09-04 23:28:19 +0000464#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant28c97e62010-09-23 16:27:36 +0000465 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000466 set& operator=(set&& __s)
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000467 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000468 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000469 __tree_ = _VSTD::move(__s.__tree_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000470 return *this;
471 }
Howard Hinnant73d21a42010-09-04 23:28:19 +0000472#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
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 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000476 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000477 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000478 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000479 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000480 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000481 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000482
Howard Hinnant28c97e62010-09-23 16:27:36 +0000483 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000484 reverse_iterator rbegin() _NOEXCEPT
485 {return reverse_iterator(end());}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000486 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000487 const_reverse_iterator rbegin() const _NOEXCEPT
488 {return const_reverse_iterator(end());}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000489 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000490 reverse_iterator rend() _NOEXCEPT
491 {return reverse_iterator(begin());}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000492 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000493 const_reverse_iterator rend() const _NOEXCEPT
494 {return const_reverse_iterator(begin());}
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 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000498 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000499 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000500 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000501 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000502 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000503 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000504
Howard Hinnant28c97e62010-09-23 16:27:36 +0000505 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000506 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000507 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000508 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000509 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000510 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000511
512 // modifiers:
Howard Hinnant73d21a42010-09-04 23:28:19 +0000513#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000514 template <class... _Args>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000515 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000516 pair<iterator, bool> emplace(_Args&&... __args)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000517 {return __tree_.__emplace_unique(_VSTD::forward<_Args>(__args)...);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000518 template <class... _Args>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000519 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000520 iterator emplace_hint(const_iterator __p, _Args&&... __args)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000521 {return __tree_.__emplace_hint_unique(__p, _VSTD::forward<_Args>(__args)...);}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000522#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnant28c97e62010-09-23 16:27:36 +0000523 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000524 pair<iterator,bool> insert(const value_type& __v)
525 {return __tree_.__insert_unique(__v);}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000526#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant28c97e62010-09-23 16:27:36 +0000527 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000528 pair<iterator,bool> insert(value_type&& __v)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000529 {return __tree_.__insert_unique(_VSTD::move(__v));}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000530#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant28c97e62010-09-23 16:27:36 +0000531 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000532 iterator insert(const_iterator __p, const value_type& __v)
533 {return __tree_.__insert_unique(__p, __v);}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000534#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant28c97e62010-09-23 16:27:36 +0000535 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000536 iterator insert(const_iterator __p, value_type&& __v)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000537 {return __tree_.__insert_unique(__p, _VSTD::move(__v));}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000538#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000539 template <class _InputIterator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000540 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000541 void insert(_InputIterator __f, _InputIterator __l)
542 {
543 for (const_iterator __e = cend(); __f != __l; ++__f)
544 __tree_.__insert_unique(__e, *__f);
545 }
546
Howard Hinnante3e32912011-08-12 21:56:02 +0000547#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant28c97e62010-09-23 16:27:36 +0000548 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000549 void insert(initializer_list<value_type> __il)
550 {insert(__il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +0000551#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000552
Howard Hinnant28c97e62010-09-23 16:27:36 +0000553 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000554 iterator erase(const_iterator __p) {return __tree_.erase(__p);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000555 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000556 size_type erase(const key_type& __k)
557 {return __tree_.__erase_unique(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000558 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000559 iterator erase(const_iterator __f, const_iterator __l)
560 {return __tree_.erase(__f, __l);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000561 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000562 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000563
Howard Hinnant28c97e62010-09-23 16:27:36 +0000564 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000565 void swap(set& __s) _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
566 {__tree_.swap(__s.__tree_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000567
Howard Hinnant28c97e62010-09-23 16:27:36 +0000568 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000569 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000570 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000571 key_compare key_comp() const {return __tree_.value_comp();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000572 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000573 value_compare value_comp() const {return __tree_.value_comp();}
574
575 // set operations:
Howard Hinnant28c97e62010-09-23 16:27:36 +0000576 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000577 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000578 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000579 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000580 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000581 size_type count(const key_type& __k) const
582 {return __tree_.__count_unique(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000583 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000584 iterator lower_bound(const key_type& __k)
585 {return __tree_.lower_bound(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000586 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000587 const_iterator lower_bound(const key_type& __k) const
588 {return __tree_.lower_bound(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000589 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000590 iterator upper_bound(const key_type& __k)
591 {return __tree_.upper_bound(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000592 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000593 const_iterator upper_bound(const key_type& __k) const
594 {return __tree_.upper_bound(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000595 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000596 pair<iterator,iterator> equal_range(const key_type& __k)
597 {return __tree_.__equal_range_unique(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000598 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000599 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
600 {return __tree_.__equal_range_unique(__k);}
601};
602
Howard Hinnant73d21a42010-09-04 23:28:19 +0000603#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000604
605template <class _Key, class _Compare, class _Allocator>
606set<_Key, _Compare, _Allocator>::set(set&& __s, const allocator_type& __a)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000607 : __tree_(_VSTD::move(__s.__tree_), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000608{
609 if (__a != __s.get_allocator())
610 {
611 const_iterator __e = cend();
612 while (!__s.empty())
Howard Hinnant0949eed2011-06-30 21:18:19 +0000613 insert(__e, _VSTD::move(__s.__tree_.remove(__s.begin())->__value_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000614 }
615}
616
Howard Hinnant73d21a42010-09-04 23:28:19 +0000617#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000618
619template <class _Key, class _Compare, class _Allocator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000620inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000621bool
622operator==(const set<_Key, _Compare, _Allocator>& __x,
623 const set<_Key, _Compare, _Allocator>& __y)
624{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000625 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000626}
627
628template <class _Key, class _Compare, class _Allocator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000629inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000630bool
631operator< (const set<_Key, _Compare, _Allocator>& __x,
632 const set<_Key, _Compare, _Allocator>& __y)
633{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000634 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000635}
636
637template <class _Key, class _Compare, class _Allocator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000638inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000639bool
640operator!=(const set<_Key, _Compare, _Allocator>& __x,
641 const set<_Key, _Compare, _Allocator>& __y)
642{
643 return !(__x == __y);
644}
645
646template <class _Key, class _Compare, class _Allocator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000647inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000648bool
649operator> (const set<_Key, _Compare, _Allocator>& __x,
650 const set<_Key, _Compare, _Allocator>& __y)
651{
652 return __y < __x;
653}
654
655template <class _Key, class _Compare, class _Allocator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000656inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000657bool
658operator>=(const set<_Key, _Compare, _Allocator>& __x,
659 const set<_Key, _Compare, _Allocator>& __y)
660{
661 return !(__x < __y);
662}
663
664template <class _Key, class _Compare, class _Allocator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000665inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000666bool
667operator<=(const set<_Key, _Compare, _Allocator>& __x,
668 const set<_Key, _Compare, _Allocator>& __y)
669{
670 return !(__y < __x);
671}
672
673// specialized algorithms:
674template <class _Key, class _Compare, class _Allocator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000675inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000676void
677swap(set<_Key, _Compare, _Allocator>& __x,
678 set<_Key, _Compare, _Allocator>& __y)
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000679 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000680{
681 __x.swap(__y);
682}
683
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000684template <class _Key, class _Compare = less<_Key>,
685 class _Allocator = allocator<_Key> >
Howard Hinnant28c97e62010-09-23 16:27:36 +0000686class _LIBCPP_VISIBLE multiset
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000687{
688public:
689 // types:
690 typedef _Key key_type;
691 typedef key_type value_type;
692 typedef _Compare key_compare;
693 typedef key_compare value_compare;
694 typedef _Allocator allocator_type;
695 typedef value_type& reference;
696 typedef const value_type& const_reference;
697
698private:
699 typedef __tree<value_type, value_compare, allocator_type> __base;
700 typedef allocator_traits<allocator_type> __alloc_traits;
701 typedef typename __base::__node_holder __node_holder;
702
703 __base __tree_;
704
705public:
706 typedef typename __base::pointer pointer;
707 typedef typename __base::const_pointer const_pointer;
708 typedef typename __base::size_type size_type;
709 typedef typename __base::difference_type difference_type;
710 typedef typename __base::const_iterator iterator;
711 typedef typename __base::const_iterator const_iterator;
Howard Hinnant0949eed2011-06-30 21:18:19 +0000712 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
713 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000714
715 // construct/copy/destroy:
Howard Hinnant28c97e62010-09-23 16:27:36 +0000716 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000717 explicit multiset(const value_compare& __comp = value_compare())
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000718 _NOEXCEPT_(
719 is_nothrow_default_constructible<allocator_type>::value &&
720 is_nothrow_default_constructible<key_compare>::value &&
721 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000722 : __tree_(__comp) {}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000723 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000724 multiset(const value_compare& __comp, const allocator_type& __a)
725 : __tree_(__comp, __a) {}
726 template <class _InputIterator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000727 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000728 multiset(_InputIterator __f, _InputIterator __l,
729 const value_compare& __comp = value_compare())
730 : __tree_(__comp)
731 {
732 insert(__f, __l);
733 }
734
735 template <class _InputIterator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000736 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000737 multiset(_InputIterator __f, _InputIterator __l,
738 const value_compare& __comp, const allocator_type& __a)
739 : __tree_(__comp, __a)
740 {
741 insert(__f, __l);
742 }
743
Howard Hinnant28c97e62010-09-23 16:27:36 +0000744 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000745 multiset(const multiset& __s)
746 : __tree_(__s.__tree_.value_comp(),
747 __alloc_traits::select_on_container_copy_construction(__s.__tree_.__alloc()))
748 {
749 insert(__s.begin(), __s.end());
750 }
751
Howard Hinnant61aa6012011-07-01 19:24:36 +0000752 _LIBCPP_INLINE_VISIBILITY
753 multiset& operator=(const multiset& __s)
754 {
755 __tree_ = __s.__tree_;
756 return *this;
757 }
758
Howard Hinnant73d21a42010-09-04 23:28:19 +0000759#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant28c97e62010-09-23 16:27:36 +0000760 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000761 multiset(multiset&& __s)
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000762 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000763 : __tree_(_VSTD::move(__s.__tree_)) {}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000764#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant28c97e62010-09-23 16:27:36 +0000765 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000766 explicit multiset(const allocator_type& __a)
767 : __tree_(__a) {}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000768 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000769 multiset(const multiset& __s, const allocator_type& __a)
770 : __tree_(__s.__tree_.value_comp(), __a)
771 {
772 insert(__s.begin(), __s.end());
773 }
Howard Hinnant73d21a42010-09-04 23:28:19 +0000774#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000775 multiset(multiset&& __s, const allocator_type& __a);
776#endif
777
Howard Hinnante3e32912011-08-12 21:56:02 +0000778#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant28c97e62010-09-23 16:27:36 +0000779 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000780 multiset(initializer_list<value_type> __il, const value_compare& __comp = value_compare())
781 : __tree_(__comp)
782 {
783 insert(__il.begin(), __il.end());
784 }
785
Howard Hinnant28c97e62010-09-23 16:27:36 +0000786 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000787 multiset(initializer_list<value_type> __il, const value_compare& __comp,
788 const allocator_type& __a)
789 : __tree_(__comp, __a)
790 {
791 insert(__il.begin(), __il.end());
792 }
793
Howard Hinnant28c97e62010-09-23 16:27:36 +0000794 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000795 multiset& operator=(initializer_list<value_type> __il)
796 {
797 __tree_.__assign_multi(__il.begin(), __il.end());
798 return *this;
799 }
Howard Hinnante3e32912011-08-12 21:56:02 +0000800#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000801
Howard Hinnant73d21a42010-09-04 23:28:19 +0000802#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant28c97e62010-09-23 16:27:36 +0000803 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000804 multiset& operator=(multiset&& __s)
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000805 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000806 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000807 __tree_ = _VSTD::move(__s.__tree_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000808 return *this;
809 }
Howard Hinnant73d21a42010-09-04 23:28:19 +0000810#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000811
Howard Hinnant28c97e62010-09-23 16:27:36 +0000812 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000813 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000814 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000815 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000816 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000817 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000818 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000819 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000820
Howard Hinnant28c97e62010-09-23 16:27:36 +0000821 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000822 reverse_iterator rbegin() _NOEXCEPT
823 {return reverse_iterator(end());}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000824 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000825 const_reverse_iterator rbegin() const _NOEXCEPT
826 {return const_reverse_iterator(end());}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000827 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000828 reverse_iterator rend() _NOEXCEPT
829 {return reverse_iterator(begin());}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000830 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000831 const_reverse_iterator rend() const _NOEXCEPT
832 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000833
Howard Hinnant28c97e62010-09-23 16:27:36 +0000834 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000835 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000836 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000837 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000838 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000839 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000840 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000841 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000842
Howard Hinnant28c97e62010-09-23 16:27:36 +0000843 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000844 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000845 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000846 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000847 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000848 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000849
850 // modifiers:
Howard Hinnant73d21a42010-09-04 23:28:19 +0000851#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000852 template <class... _Args>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000853 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000854 iterator emplace(_Args&&... __args)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000855 {return __tree_.__emplace_multi(_VSTD::forward<_Args>(__args)...);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000856 template <class... _Args>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000857 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000858 iterator emplace_hint(const_iterator __p, _Args&&... __args)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000859 {return __tree_.__emplace_hint_multi(__p, _VSTD::forward<_Args>(__args)...);}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000860#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnant28c97e62010-09-23 16:27:36 +0000861 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000862 iterator insert(const value_type& __v)
863 {return __tree_.__insert_multi(__v);}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000864#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant28c97e62010-09-23 16:27:36 +0000865 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000866 iterator insert(value_type&& __v)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000867 {return __tree_.__insert_multi(_VSTD::move(__v));}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000868#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant28c97e62010-09-23 16:27:36 +0000869 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000870 iterator insert(const_iterator __p, const value_type& __v)
871 {return __tree_.__insert_multi(__p, __v);}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000872#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant28c97e62010-09-23 16:27:36 +0000873 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000874 iterator insert(const_iterator __p, value_type&& __v)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000875 {return __tree_.__insert_multi(_VSTD::move(__v));}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000876#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000877 template <class _InputIterator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000878 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000879 void insert(_InputIterator __f, _InputIterator __l)
880 {
881 for (const_iterator __e = cend(); __f != __l; ++__f)
882 __tree_.__insert_multi(__e, *__f);
883 }
884
Howard Hinnante3e32912011-08-12 21:56:02 +0000885#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant28c97e62010-09-23 16:27:36 +0000886 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000887 void insert(initializer_list<value_type> __il)
888 {insert(__il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +0000889#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000890
Howard Hinnant28c97e62010-09-23 16:27:36 +0000891 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000892 iterator erase(const_iterator __p) {return __tree_.erase(__p);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000893 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000894 size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000895 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000896 iterator erase(const_iterator __f, const_iterator __l)
897 {return __tree_.erase(__f, __l);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000898 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000899 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000900
Howard Hinnant28c97e62010-09-23 16:27:36 +0000901 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000902 void swap(multiset& __s)
903 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
904 {__tree_.swap(__s.__tree_);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000905
Howard Hinnant28c97e62010-09-23 16:27:36 +0000906 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +0000907 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000908 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000909 key_compare key_comp() const {return __tree_.value_comp();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000910 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000911 value_compare value_comp() const {return __tree_.value_comp();}
912
913 // set operations:
Howard Hinnant28c97e62010-09-23 16:27:36 +0000914 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000915 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000916 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000917 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000918 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000919 size_type count(const key_type& __k) const
920 {return __tree_.__count_multi(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000921 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000922 iterator lower_bound(const key_type& __k)
923 {return __tree_.lower_bound(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000924 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000925 const_iterator lower_bound(const key_type& __k) const
926 {return __tree_.lower_bound(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000927 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000928 iterator upper_bound(const key_type& __k)
929 {return __tree_.upper_bound(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000930 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000931 const_iterator upper_bound(const key_type& __k) const
932 {return __tree_.upper_bound(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000933 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000934 pair<iterator,iterator> equal_range(const key_type& __k)
935 {return __tree_.__equal_range_multi(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000936 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000937 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
938 {return __tree_.__equal_range_multi(__k);}
939};
940
Howard Hinnant73d21a42010-09-04 23:28:19 +0000941#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000942
943template <class _Key, class _Compare, class _Allocator>
944multiset<_Key, _Compare, _Allocator>::multiset(multiset&& __s, const allocator_type& __a)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000945 : __tree_(_VSTD::move(__s.__tree_), __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000946{
947 if (__a != __s.get_allocator())
948 {
949 const_iterator __e = cend();
950 while (!__s.empty())
Howard Hinnant0949eed2011-06-30 21:18:19 +0000951 insert(__e, _VSTD::move(__s.__tree_.remove(__s.begin())->__value_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000952 }
953}
954
Howard Hinnant73d21a42010-09-04 23:28:19 +0000955#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000956
957template <class _Key, class _Compare, class _Allocator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000958inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000959bool
960operator==(const multiset<_Key, _Compare, _Allocator>& __x,
961 const multiset<_Key, _Compare, _Allocator>& __y)
962{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000963 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000964}
965
966template <class _Key, class _Compare, class _Allocator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000967inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000968bool
969operator< (const multiset<_Key, _Compare, _Allocator>& __x,
970 const multiset<_Key, _Compare, _Allocator>& __y)
971{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000972 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000973}
974
975template <class _Key, class _Compare, class _Allocator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000976inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000977bool
978operator!=(const multiset<_Key, _Compare, _Allocator>& __x,
979 const multiset<_Key, _Compare, _Allocator>& __y)
980{
981 return !(__x == __y);
982}
983
984template <class _Key, class _Compare, class _Allocator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000985inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000986bool
987operator> (const multiset<_Key, _Compare, _Allocator>& __x,
988 const multiset<_Key, _Compare, _Allocator>& __y)
989{
990 return __y < __x;
991}
992
993template <class _Key, class _Compare, class _Allocator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000994inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000995bool
996operator>=(const multiset<_Key, _Compare, _Allocator>& __x,
997 const multiset<_Key, _Compare, _Allocator>& __y)
998{
999 return !(__x < __y);
1000}
1001
1002template <class _Key, class _Compare, class _Allocator>
Howard Hinnant28c97e62010-09-23 16:27:36 +00001003inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001004bool
1005operator<=(const multiset<_Key, _Compare, _Allocator>& __x,
1006 const multiset<_Key, _Compare, _Allocator>& __y)
1007{
1008 return !(__y < __x);
1009}
1010
1011template <class _Key, class _Compare, class _Allocator>
Howard Hinnant28c97e62010-09-23 16:27:36 +00001012inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001013void
1014swap(multiset<_Key, _Compare, _Allocator>& __x,
1015 multiset<_Key, _Compare, _Allocator>& __y)
Howard Hinnantb2e2a8f2011-06-04 15:22:34 +00001016 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001017{
1018 __x.swap(__y);
1019}
1020
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001021_LIBCPP_END_NAMESPACE_STD
1022
1023#endif // _LIBCPP_SET