blob: 7e2cdc0debc27fff16751c298b0c2016871b0c5d [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:
45 explicit set(const value_compare& comp = value_compare());
46 set(const value_compare& comp, const allocator_type& a);
47 template <class InputIterator>
48 set(InputIterator first, InputIterator last,
49 const value_compare& comp = value_compare());
50 template <class InputIterator>
51 set(InputIterator first, InputIterator last, const value_compare& comp,
52 const allocator_type& a);
53 set(const set& s);
54 set(set&& s);
55 explicit set(const allocator_type& a);
56 set(const set& s, const allocator_type& a);
57 set(set&& s, const allocator_type& a);
58 set(initializer_list<value_type> il, const value_compare& comp = value_compare());
59 set(initializer_list<value_type> il, const value_compare& comp,
60 const allocator_type& a);
61 ~set();
62
63 set& operator=(const set& s);
64 set& operator=(set&& s);
65 set& operator=(initializer_list<value_type> il);
66
67 // iterators:
68 iterator begin();
69 const_iterator begin() const;
70 iterator end();
71 const_iterator end() const;
72
73 reverse_iterator rbegin();
74 const_reverse_iterator rbegin() const;
75 reverse_iterator rend();
76 const_reverse_iterator rend() const;
77
78 const_iterator cbegin() const;
79 const_iterator cend() const;
80 const_reverse_iterator crbegin() const;
81 const_reverse_iterator crend() const;
82
83 // capacity:
84 bool empty() const;
85 size_type size() const;
86 size_type max_size() const;
87
88 // modifiers:
89 template <class... Args>
90 pair<iterator, bool> emplace(Args&&... args);
91 template <class... Args>
92 iterator emplace_hint(const_iterator position, Args&&... args);
93 pair<iterator,bool> insert(const value_type& v);
94 pair<iterator,bool> insert(value_type&& v);
95 iterator insert(const_iterator position, const value_type& v);
96 iterator insert(const_iterator position, value_type&& v);
97 template <class InputIterator>
98 void insert(InputIterator first, InputIterator last);
99 void insert(initializer_list<value_type> il);
100
101 iterator erase(const_iterator position);
102 size_type erase(const key_type& k);
103 iterator erase(const_iterator first, const_iterator last);
104 void clear();
105
106 void swap(set& s);
107
108 // observers:
109 allocator_type get_allocator() const;
110 key_compare key_comp() const;
111 value_compare value_comp() const;
112
113 // set operations:
114 iterator find(const key_type& k);
115 const_iterator find(const key_type& k) const;
116 size_type count(const key_type& k) const;
117 iterator lower_bound(const key_type& k);
118 const_iterator lower_bound(const key_type& k) const;
119 iterator upper_bound(const key_type& k);
120 const_iterator upper_bound(const key_type& k) const;
121 pair<iterator,iterator> equal_range(const key_type& k);
122 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
123};
124
125template <class Key, class Compare, class Allocator>
126bool
127operator==(const set<Key, Compare, Allocator>& x,
128 const set<Key, Compare, Allocator>& y);
129
130template <class Key, class Compare, class Allocator>
131bool
132operator< (const set<Key, Compare, Allocator>& x,
133 const set<Key, Compare, Allocator>& y);
134
135template <class Key, class Compare, class Allocator>
136bool
137operator!=(const set<Key, Compare, Allocator>& x,
138 const set<Key, Compare, Allocator>& y);
139
140template <class Key, class Compare, class Allocator>
141bool
142operator> (const set<Key, Compare, Allocator>& x,
143 const set<Key, Compare, Allocator>& y);
144
145template <class Key, class Compare, class Allocator>
146bool
147operator>=(const set<Key, Compare, Allocator>& x,
148 const set<Key, Compare, Allocator>& y);
149
150template <class Key, class Compare, class Allocator>
151bool
152operator<=(const set<Key, Compare, Allocator>& x,
153 const set<Key, Compare, Allocator>& y);
154
155// specialized algorithms:
156template <class Key, class Compare, class Allocator>
157void
158swap(set<Key, Compare, Allocator>& x, set<Key, Compare, Allocator>& y);
159
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000160template <class Key, class Compare = less<Key>,
161 class Allocator = allocator<Key>>
162class multiset
163{
164public:
165 // types:
166 typedef Key key_type;
167 typedef key_type value_type;
168 typedef Compare key_compare;
169 typedef key_compare value_compare;
170 typedef Allocator allocator_type;
171 typedef typename allocator_type::reference reference;
172 typedef typename allocator_type::const_reference const_reference;
173 typedef typename allocator_type::size_type size_type;
174 typedef typename allocator_type::difference_type difference_type;
175 typedef typename allocator_type::pointer pointer;
176 typedef typename allocator_type::const_pointer const_pointer;
177
178 typedef implementation-defined iterator;
179 typedef implementation-defined const_iterator;
180 typedef std::reverse_iterator<iterator> reverse_iterator;
181 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
182
183 // construct/copy/destroy:
184 explicit multiset(const value_compare& comp = value_compare());
185 multiset(const value_compare& comp, const allocator_type& a);
186 template <class InputIterator>
187 multiset(InputIterator first, InputIterator last,
188 const value_compare& comp = value_compare());
189 template <class InputIterator>
190 multiset(InputIterator first, InputIterator last,
191 const value_compare& comp, const allocator_type& a);
192 multiset(const multiset& s);
193 multiset(multiset&& s);
194 explicit multiset(const allocator_type& a);
195 multiset(const multiset& s, const allocator_type& a);
196 multiset(multiset&& s, const allocator_type& a);
197 multiset(initializer_list<value_type> il, const value_compare& comp = value_compare());
198 multiset(initializer_list<value_type> il, const value_compare& comp,
199 const allocator_type& a);
200 ~multiset();
201
202 multiset& operator=(const multiset& s);
203 multiset& operator=(multiset&& s);
204 multiset& operator=(initializer_list<value_type> il);
205
206 // iterators:
207 iterator begin();
208 const_iterator begin() const;
209 iterator end();
210 const_iterator end() const;
211
212 reverse_iterator rbegin();
213 const_reverse_iterator rbegin() const;
214 reverse_iterator rend();
215 const_reverse_iterator rend() const;
216
217 const_iterator cbegin() const;
218 const_iterator cend() const;
219 const_reverse_iterator crbegin() const;
220 const_reverse_iterator crend() const;
221
222 // capacity:
223 bool empty() const;
224 size_type size() const;
225 size_type max_size() const;
226
227 // modifiers:
228 template <class... Args>
229 iterator emplace(Args&&... args);
230 template <class... Args>
231 iterator emplace_hint(const_iterator position, Args&&... args);
232 iterator insert(const value_type& v);
233 iterator insert(value_type&& v);
234 iterator insert(const_iterator position, const value_type& v);
235 iterator insert(const_iterator position, value_type&& v);
236 template <class InputIterator>
237 void insert(InputIterator first, InputIterator last);
238 void insert(initializer_list<value_type> il);
239
240 iterator erase(const_iterator position);
241 size_type erase(const key_type& k);
242 iterator erase(const_iterator first, const_iterator last);
243 void clear();
244
245 void swap(multiset& s);
246
247 // observers:
248 allocator_type get_allocator() const;
249 key_compare key_comp() const;
250 value_compare value_comp() const;
251
252 // set operations:
253 iterator find(const key_type& k);
254 const_iterator find(const key_type& k) const;
255 size_type count(const key_type& k) const;
256 iterator lower_bound(const key_type& k);
257 const_iterator lower_bound(const key_type& k) const;
258 iterator upper_bound(const key_type& k);
259 const_iterator upper_bound(const key_type& k) const;
260 pair<iterator,iterator> equal_range(const key_type& k);
261 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
262};
263
264template <class Key, class Compare, class Allocator>
265bool
266operator==(const multiset<Key, Compare, Allocator>& x,
267 const multiset<Key, Compare, Allocator>& y);
268
269template <class Key, class Compare, class Allocator>
270bool
271operator< (const multiset<Key, Compare, Allocator>& x,
272 const multiset<Key, Compare, Allocator>& y);
273
274template <class Key, class Compare, class Allocator>
275bool
276operator!=(const multiset<Key, Compare, Allocator>& x,
277 const multiset<Key, Compare, Allocator>& y);
278
279template <class Key, class Compare, class Allocator>
280bool
281operator> (const multiset<Key, Compare, Allocator>& x,
282 const multiset<Key, Compare, Allocator>& y);
283
284template <class Key, class Compare, class Allocator>
285bool
286operator>=(const multiset<Key, Compare, Allocator>& x,
287 const multiset<Key, Compare, Allocator>& y);
288
289template <class Key, class Compare, class Allocator>
290bool
291operator<=(const multiset<Key, Compare, Allocator>& x,
292 const multiset<Key, Compare, Allocator>& y);
293
294// specialized algorithms:
295template <class Key, class Compare, class Allocator>
296void
297swap(multiset<Key, Compare, Allocator>& x, multiset<Key, Compare, Allocator>& y);
298
299} // std
300
301*/
302
303#include <__config>
304#include <__tree>
305#include <functional>
306
307#pragma GCC system_header
308
309_LIBCPP_BEGIN_NAMESPACE_STD
310
311template <class _Key, class _Compare = less<_Key>,
312 class _Allocator = allocator<_Key> >
Howard Hinnant28c97e62010-09-23 16:27:36 +0000313class _LIBCPP_VISIBLE set
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000314{
315public:
316 // types:
317 typedef _Key key_type;
318 typedef key_type value_type;
319 typedef _Compare key_compare;
320 typedef key_compare value_compare;
321 typedef _Allocator allocator_type;
322 typedef value_type& reference;
323 typedef const value_type& const_reference;
324
325private:
326 typedef __tree<value_type, value_compare, allocator_type> __base;
327 typedef allocator_traits<allocator_type> __alloc_traits;
328 typedef typename __base::__node_holder __node_holder;
329
330 __base __tree_;
331
332public:
333 typedef typename __base::pointer pointer;
334 typedef typename __base::const_pointer const_pointer;
335 typedef typename __base::size_type size_type;
336 typedef typename __base::difference_type difference_type;
337 typedef typename __base::const_iterator iterator;
338 typedef typename __base::const_iterator const_iterator;
339 typedef _STD::reverse_iterator<iterator> reverse_iterator;
340 typedef _STD::reverse_iterator<const_iterator> const_reverse_iterator;
341
Howard Hinnant28c97e62010-09-23 16:27:36 +0000342 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000343 explicit set(const value_compare& __comp = value_compare())
344 : __tree_(__comp) {}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000345 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000346 set(const value_compare& __comp, const allocator_type& __a)
347 : __tree_(__comp, __a) {}
348 template <class _InputIterator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000349 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000350 set(_InputIterator __f, _InputIterator __l,
351 const value_compare& __comp = value_compare())
352 : __tree_(__comp)
353 {
354 insert(__f, __l);
355 }
356
357 template <class _InputIterator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000358 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000359 set(_InputIterator __f, _InputIterator __l, const value_compare& __comp,
360 const allocator_type& __a)
361 : __tree_(__comp, __a)
362 {
363 insert(__f, __l);
364 }
365
Howard Hinnant28c97e62010-09-23 16:27:36 +0000366 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000367 set(const set& __s)
368 : __tree_(__s.__tree_)
369 {
370 insert(__s.begin(), __s.end());
371 }
372
Howard Hinnant73d21a42010-09-04 23:28:19 +0000373#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant28c97e62010-09-23 16:27:36 +0000374 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000375 set(set&& __s)
376 : __tree_(_STD::move(__s.__tree_)) {}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000377#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000378
Howard Hinnant28c97e62010-09-23 16:27:36 +0000379 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000380 explicit set(const allocator_type& __a)
381 : __tree_(__a) {}
382
Howard Hinnant28c97e62010-09-23 16:27:36 +0000383 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000384 set(const set& __s, const allocator_type& __a)
385 : __tree_(__s.__tree_.value_comp(), __a)
386 {
387 insert(__s.begin(), __s.end());
388 }
389
Howard Hinnant73d21a42010-09-04 23:28:19 +0000390#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000391 set(set&& __s, const allocator_type& __a);
392#endif
393
Howard Hinnant28c97e62010-09-23 16:27:36 +0000394 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000395 set(initializer_list<value_type> __il, const value_compare& __comp = value_compare())
396 : __tree_(__comp)
397 {
398 insert(__il.begin(), __il.end());
399 }
400
Howard Hinnant28c97e62010-09-23 16:27:36 +0000401 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000402 set(initializer_list<value_type> __il, const value_compare& __comp,
403 const allocator_type& __a)
404 : __tree_(__comp, __a)
405 {
406 insert(__il.begin(), __il.end());
407 }
408
Howard Hinnant28c97e62010-09-23 16:27:36 +0000409 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000410 set& operator=(initializer_list<value_type> __il)
411 {
412 __tree_.__assign_unique(__il.begin(), __il.end());
413 return *this;
414 }
415
Howard Hinnant73d21a42010-09-04 23:28:19 +0000416#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant28c97e62010-09-23 16:27:36 +0000417 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000418 set& operator=(set&& __s)
419 {
420 __tree_ = _STD::move(__s.__tree_);
421 return *this;
422 }
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 iterator begin() {return __tree_.begin();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000427 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000428 const_iterator begin() const {return __tree_.begin();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000429 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000430 iterator end() {return __tree_.end();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000431 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000432 const_iterator end() const {return __tree_.end();}
433
Howard Hinnant28c97e62010-09-23 16:27:36 +0000434 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000435 reverse_iterator rbegin() {return reverse_iterator(end());}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000436 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000437 const_reverse_iterator rbegin() const {return const_reverse_iterator(end());}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000438 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000439 reverse_iterator rend() {return reverse_iterator(begin());}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000440 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000441 const_reverse_iterator rend() const {return const_reverse_iterator(begin());}
442
Howard Hinnant28c97e62010-09-23 16:27:36 +0000443 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000444 const_iterator cbegin() const {return begin();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000445 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000446 const_iterator cend() const {return end();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000447 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000448 const_reverse_iterator crbegin() const {return rbegin();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000449 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000450 const_reverse_iterator crend() const {return rend();}
451
Howard Hinnant28c97e62010-09-23 16:27:36 +0000452 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000453 bool empty() const {return __tree_.size() == 0;}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000454 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000455 size_type size() const {return __tree_.size();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000456 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000457 size_type max_size() const {return __tree_.max_size();}
458
459 // modifiers:
Howard Hinnant73d21a42010-09-04 23:28:19 +0000460#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000461 template <class... _Args>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000462 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000463 pair<iterator, bool> emplace(_Args&&... __args)
464 {return __tree_.__emplace_unique(_STD::forward<_Args>(__args)...);}
465 template <class... _Args>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000466 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000467 iterator emplace_hint(const_iterator __p, _Args&&... __args)
468 {return __tree_.__emplace_hint_unique(__p, _STD::forward<_Args>(__args)...);}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000469#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnant28c97e62010-09-23 16:27:36 +0000470 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000471 pair<iterator,bool> insert(const value_type& __v)
472 {return __tree_.__insert_unique(__v);}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000473#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant28c97e62010-09-23 16:27:36 +0000474 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000475 pair<iterator,bool> insert(value_type&& __v)
476 {return __tree_.__insert_unique(_STD::move(__v));}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000477#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant28c97e62010-09-23 16:27:36 +0000478 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000479 iterator insert(const_iterator __p, const value_type& __v)
480 {return __tree_.__insert_unique(__p, __v);}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000481#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant28c97e62010-09-23 16:27:36 +0000482 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000483 iterator insert(const_iterator __p, value_type&& __v)
484 {return __tree_.__insert_unique(__p, _STD::move(__v));}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000485#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000486 template <class _InputIterator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000487 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000488 void insert(_InputIterator __f, _InputIterator __l)
489 {
490 for (const_iterator __e = cend(); __f != __l; ++__f)
491 __tree_.__insert_unique(__e, *__f);
492 }
493
Howard Hinnant28c97e62010-09-23 16:27:36 +0000494 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000495 void insert(initializer_list<value_type> __il)
496 {insert(__il.begin(), __il.end());}
497
Howard Hinnant28c97e62010-09-23 16:27:36 +0000498 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000499 iterator erase(const_iterator __p) {return __tree_.erase(__p);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000500 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000501 size_type erase(const key_type& __k)
502 {return __tree_.__erase_unique(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000503 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000504 iterator erase(const_iterator __f, const_iterator __l)
505 {return __tree_.erase(__f, __l);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000506 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000507 void clear() {__tree_.clear();}
508
Howard Hinnant28c97e62010-09-23 16:27:36 +0000509 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000510 void swap(set& __s) {__tree_.swap(__s.__tree_);}
511
Howard Hinnant28c97e62010-09-23 16:27:36 +0000512 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000513 allocator_type get_allocator() const {return __tree_.__alloc();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000514 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000515 key_compare key_comp() const {return __tree_.value_comp();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000516 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000517 value_compare value_comp() const {return __tree_.value_comp();}
518
519 // set operations:
Howard Hinnant28c97e62010-09-23 16:27:36 +0000520 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000521 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000522 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000523 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000524 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000525 size_type count(const key_type& __k) const
526 {return __tree_.__count_unique(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000527 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000528 iterator lower_bound(const key_type& __k)
529 {return __tree_.lower_bound(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000530 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000531 const_iterator lower_bound(const key_type& __k) const
532 {return __tree_.lower_bound(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000533 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000534 iterator upper_bound(const key_type& __k)
535 {return __tree_.upper_bound(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000536 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000537 const_iterator upper_bound(const key_type& __k) const
538 {return __tree_.upper_bound(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000539 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000540 pair<iterator,iterator> equal_range(const key_type& __k)
541 {return __tree_.__equal_range_unique(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000542 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000543 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
544 {return __tree_.__equal_range_unique(__k);}
545};
546
Howard Hinnant73d21a42010-09-04 23:28:19 +0000547#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000548
549template <class _Key, class _Compare, class _Allocator>
550set<_Key, _Compare, _Allocator>::set(set&& __s, const allocator_type& __a)
551 : __tree_(_STD::move(__s.__tree_), __a)
552{
553 if (__a != __s.get_allocator())
554 {
555 const_iterator __e = cend();
556 while (!__s.empty())
557 insert(__e, _STD::move(__s.__tree_.remove(__s.begin())->__value_));
558 }
559}
560
Howard Hinnant73d21a42010-09-04 23:28:19 +0000561#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000562
563template <class _Key, class _Compare, class _Allocator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000564inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000565bool
566operator==(const set<_Key, _Compare, _Allocator>& __x,
567 const set<_Key, _Compare, _Allocator>& __y)
568{
569 return __x.size() == __y.size() && _STD::equal(__x.begin(), __x.end(), __y.begin());
570}
571
572template <class _Key, class _Compare, class _Allocator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000573inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000574bool
575operator< (const set<_Key, _Compare, _Allocator>& __x,
576 const set<_Key, _Compare, _Allocator>& __y)
577{
578 return _STD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
579}
580
581template <class _Key, class _Compare, class _Allocator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000582inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000583bool
584operator!=(const set<_Key, _Compare, _Allocator>& __x,
585 const set<_Key, _Compare, _Allocator>& __y)
586{
587 return !(__x == __y);
588}
589
590template <class _Key, class _Compare, class _Allocator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000591inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000592bool
593operator> (const set<_Key, _Compare, _Allocator>& __x,
594 const set<_Key, _Compare, _Allocator>& __y)
595{
596 return __y < __x;
597}
598
599template <class _Key, class _Compare, class _Allocator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000600inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000601bool
602operator>=(const set<_Key, _Compare, _Allocator>& __x,
603 const set<_Key, _Compare, _Allocator>& __y)
604{
605 return !(__x < __y);
606}
607
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 !(__y < __x);
615}
616
617// specialized algorithms:
618template <class _Key, class _Compare, class _Allocator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000619inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000620void
621swap(set<_Key, _Compare, _Allocator>& __x,
622 set<_Key, _Compare, _Allocator>& __y)
623{
624 __x.swap(__y);
625}
626
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000627template <class _Key, class _Compare = less<_Key>,
628 class _Allocator = allocator<_Key> >
Howard Hinnant28c97e62010-09-23 16:27:36 +0000629class _LIBCPP_VISIBLE multiset
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000630{
631public:
632 // types:
633 typedef _Key key_type;
634 typedef key_type value_type;
635 typedef _Compare key_compare;
636 typedef key_compare value_compare;
637 typedef _Allocator allocator_type;
638 typedef value_type& reference;
639 typedef const value_type& const_reference;
640
641private:
642 typedef __tree<value_type, value_compare, allocator_type> __base;
643 typedef allocator_traits<allocator_type> __alloc_traits;
644 typedef typename __base::__node_holder __node_holder;
645
646 __base __tree_;
647
648public:
649 typedef typename __base::pointer pointer;
650 typedef typename __base::const_pointer const_pointer;
651 typedef typename __base::size_type size_type;
652 typedef typename __base::difference_type difference_type;
653 typedef typename __base::const_iterator iterator;
654 typedef typename __base::const_iterator const_iterator;
655 typedef _STD::reverse_iterator<iterator> reverse_iterator;
656 typedef _STD::reverse_iterator<const_iterator> const_reverse_iterator;
657
658 // construct/copy/destroy:
Howard Hinnant28c97e62010-09-23 16:27:36 +0000659 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000660 explicit multiset(const value_compare& __comp = value_compare())
661 : __tree_(__comp) {}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000662 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000663 multiset(const value_compare& __comp, const allocator_type& __a)
664 : __tree_(__comp, __a) {}
665 template <class _InputIterator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000666 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000667 multiset(_InputIterator __f, _InputIterator __l,
668 const value_compare& __comp = value_compare())
669 : __tree_(__comp)
670 {
671 insert(__f, __l);
672 }
673
674 template <class _InputIterator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000675 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000676 multiset(_InputIterator __f, _InputIterator __l,
677 const value_compare& __comp, const allocator_type& __a)
678 : __tree_(__comp, __a)
679 {
680 insert(__f, __l);
681 }
682
Howard Hinnant28c97e62010-09-23 16:27:36 +0000683 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000684 multiset(const multiset& __s)
685 : __tree_(__s.__tree_.value_comp(),
686 __alloc_traits::select_on_container_copy_construction(__s.__tree_.__alloc()))
687 {
688 insert(__s.begin(), __s.end());
689 }
690
Howard Hinnant73d21a42010-09-04 23:28:19 +0000691#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant28c97e62010-09-23 16:27:36 +0000692 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000693 multiset(multiset&& __s)
694 : __tree_(_STD::move(__s.__tree_)) {}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000695#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant28c97e62010-09-23 16:27:36 +0000696 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000697 explicit multiset(const allocator_type& __a)
698 : __tree_(__a) {}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000699 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000700 multiset(const multiset& __s, const allocator_type& __a)
701 : __tree_(__s.__tree_.value_comp(), __a)
702 {
703 insert(__s.begin(), __s.end());
704 }
Howard Hinnant73d21a42010-09-04 23:28:19 +0000705#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000706 multiset(multiset&& __s, const allocator_type& __a);
707#endif
708
Howard Hinnant28c97e62010-09-23 16:27:36 +0000709 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000710 multiset(initializer_list<value_type> __il, const value_compare& __comp = value_compare())
711 : __tree_(__comp)
712 {
713 insert(__il.begin(), __il.end());
714 }
715
Howard Hinnant28c97e62010-09-23 16:27:36 +0000716 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000717 multiset(initializer_list<value_type> __il, const value_compare& __comp,
718 const allocator_type& __a)
719 : __tree_(__comp, __a)
720 {
721 insert(__il.begin(), __il.end());
722 }
723
Howard Hinnant28c97e62010-09-23 16:27:36 +0000724 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000725 multiset& operator=(initializer_list<value_type> __il)
726 {
727 __tree_.__assign_multi(__il.begin(), __il.end());
728 return *this;
729 }
730
Howard Hinnant73d21a42010-09-04 23:28:19 +0000731#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant28c97e62010-09-23 16:27:36 +0000732 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000733 multiset& operator=(multiset&& __s)
734 {
735 __tree_ = _STD::move(__s.__tree_);
736 return *this;
737 }
Howard Hinnant73d21a42010-09-04 23:28:19 +0000738#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000739
Howard Hinnant28c97e62010-09-23 16:27:36 +0000740 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000741 iterator begin() {return __tree_.begin();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000742 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000743 const_iterator begin() const {return __tree_.begin();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000744 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000745 iterator end() {return __tree_.end();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000746 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000747 const_iterator end() const {return __tree_.end();}
748
Howard Hinnant28c97e62010-09-23 16:27:36 +0000749 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000750 reverse_iterator rbegin() {return reverse_iterator(end());}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000751 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000752 const_reverse_iterator rbegin() const {return const_reverse_iterator(end());}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000753 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000754 reverse_iterator rend() {return reverse_iterator(begin());}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000755 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000756 const_reverse_iterator rend() const {return const_reverse_iterator(begin());}
757
Howard Hinnant28c97e62010-09-23 16:27:36 +0000758 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000759 const_iterator cbegin() const {return begin();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000760 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000761 const_iterator cend() const {return end();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000762 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000763 const_reverse_iterator crbegin() const {return rbegin();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000764 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000765 const_reverse_iterator crend() const {return rend();}
766
Howard Hinnant28c97e62010-09-23 16:27:36 +0000767 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000768 bool empty() const {return __tree_.size() == 0;}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000769 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000770 size_type size() const {return __tree_.size();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000771 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000772 size_type max_size() const {return __tree_.max_size();}
773
774 // modifiers:
Howard Hinnant73d21a42010-09-04 23:28:19 +0000775#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000776 template <class... _Args>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000777 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000778 iterator emplace(_Args&&... __args)
779 {return __tree_.__emplace_multi(_STD::forward<_Args>(__args)...);}
780 template <class... _Args>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000781 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000782 iterator emplace_hint(const_iterator __p, _Args&&... __args)
783 {return __tree_.__emplace_hint_multi(__p, _STD::forward<_Args>(__args)...);}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000784#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnant28c97e62010-09-23 16:27:36 +0000785 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000786 iterator insert(const value_type& __v)
787 {return __tree_.__insert_multi(__v);}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000788#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant28c97e62010-09-23 16:27:36 +0000789 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000790 iterator insert(value_type&& __v)
791 {return __tree_.__insert_multi(_STD::move(__v));}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000792#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant28c97e62010-09-23 16:27:36 +0000793 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000794 iterator insert(const_iterator __p, const value_type& __v)
795 {return __tree_.__insert_multi(__p, __v);}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000796#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant28c97e62010-09-23 16:27:36 +0000797 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000798 iterator insert(const_iterator __p, value_type&& __v)
799 {return __tree_.__insert_multi(_STD::move(__v));}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000800#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000801 template <class _InputIterator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000802 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000803 void insert(_InputIterator __f, _InputIterator __l)
804 {
805 for (const_iterator __e = cend(); __f != __l; ++__f)
806 __tree_.__insert_multi(__e, *__f);
807 }
808
Howard Hinnant28c97e62010-09-23 16:27:36 +0000809 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000810 void insert(initializer_list<value_type> __il)
811 {insert(__il.begin(), __il.end());}
812
Howard Hinnant28c97e62010-09-23 16:27:36 +0000813 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000814 iterator erase(const_iterator __p) {return __tree_.erase(__p);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000815 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000816 size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000817 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000818 iterator erase(const_iterator __f, const_iterator __l)
819 {return __tree_.erase(__f, __l);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000820 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000821 void clear() {__tree_.clear();}
822
Howard Hinnant28c97e62010-09-23 16:27:36 +0000823 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000824 void swap(multiset& __s) {__tree_.swap(__s.__tree_);}
825
Howard Hinnant28c97e62010-09-23 16:27:36 +0000826 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000827 allocator_type get_allocator() const {return __tree_.__alloc();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000828 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000829 key_compare key_comp() const {return __tree_.value_comp();}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000830 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000831 value_compare value_comp() const {return __tree_.value_comp();}
832
833 // set operations:
Howard Hinnant28c97e62010-09-23 16:27:36 +0000834 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000835 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000836 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000837 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000838 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000839 size_type count(const key_type& __k) const
840 {return __tree_.__count_multi(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000841 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000842 iterator lower_bound(const key_type& __k)
843 {return __tree_.lower_bound(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000844 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000845 const_iterator lower_bound(const key_type& __k) const
846 {return __tree_.lower_bound(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000847 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000848 iterator upper_bound(const key_type& __k)
849 {return __tree_.upper_bound(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000850 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000851 const_iterator upper_bound(const key_type& __k) const
852 {return __tree_.upper_bound(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000853 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000854 pair<iterator,iterator> equal_range(const key_type& __k)
855 {return __tree_.__equal_range_multi(__k);}
Howard Hinnant28c97e62010-09-23 16:27:36 +0000856 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000857 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
858 {return __tree_.__equal_range_multi(__k);}
859};
860
Howard Hinnant73d21a42010-09-04 23:28:19 +0000861#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000862
863template <class _Key, class _Compare, class _Allocator>
864multiset<_Key, _Compare, _Allocator>::multiset(multiset&& __s, const allocator_type& __a)
865 : __tree_(_STD::move(__s.__tree_), __a)
866{
867 if (__a != __s.get_allocator())
868 {
869 const_iterator __e = cend();
870 while (!__s.empty())
871 insert(__e, _STD::move(__s.__tree_.remove(__s.begin())->__value_));
872 }
873}
874
Howard Hinnant73d21a42010-09-04 23:28:19 +0000875#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000876
877template <class _Key, class _Compare, class _Allocator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000878inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000879bool
880operator==(const multiset<_Key, _Compare, _Allocator>& __x,
881 const multiset<_Key, _Compare, _Allocator>& __y)
882{
883 return __x.size() == __y.size() && _STD::equal(__x.begin(), __x.end(), __y.begin());
884}
885
886template <class _Key, class _Compare, class _Allocator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000887inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000888bool
889operator< (const multiset<_Key, _Compare, _Allocator>& __x,
890 const multiset<_Key, _Compare, _Allocator>& __y)
891{
892 return _STD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
893}
894
895template <class _Key, class _Compare, class _Allocator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000896inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000897bool
898operator!=(const multiset<_Key, _Compare, _Allocator>& __x,
899 const multiset<_Key, _Compare, _Allocator>& __y)
900{
901 return !(__x == __y);
902}
903
904template <class _Key, class _Compare, class _Allocator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000905inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000906bool
907operator> (const multiset<_Key, _Compare, _Allocator>& __x,
908 const multiset<_Key, _Compare, _Allocator>& __y)
909{
910 return __y < __x;
911}
912
913template <class _Key, class _Compare, class _Allocator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000914inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000915bool
916operator>=(const multiset<_Key, _Compare, _Allocator>& __x,
917 const multiset<_Key, _Compare, _Allocator>& __y)
918{
919 return !(__x < __y);
920}
921
922template <class _Key, class _Compare, class _Allocator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000923inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000924bool
925operator<=(const multiset<_Key, _Compare, _Allocator>& __x,
926 const multiset<_Key, _Compare, _Allocator>& __y)
927{
928 return !(__y < __x);
929}
930
931template <class _Key, class _Compare, class _Allocator>
Howard Hinnant28c97e62010-09-23 16:27:36 +0000932inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000933void
934swap(multiset<_Key, _Compare, _Allocator>& __x,
935 multiset<_Key, _Compare, _Allocator>& __y)
936{
937 __x.swap(__y);
938}
939
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000940_LIBCPP_END_NAMESPACE_STD
941
942#endif // _LIBCPP_SET