blob: 606af726abf6d8edd6666aa58daeb372e825ea47 [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===---------------------------- set -------------------------------------===//
3//
Howard Hinnantc566dc32010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantc51e1022010-05-11 19:42:16 +00005//
Howard Hinnantee11c312010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantc51e1022010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_SET
12#define _LIBCPP_SET
13
14/*
15
16 set synopsis
17
18namespace std
19{
20
21template <class Key, class Compare = less<Key>,
22 class Allocator = allocator<Key>>
23class set
24{
25public:
26 // types:
27 typedef Key key_type;
28 typedef key_type value_type;
29 typedef Compare key_compare;
30 typedef key_compare value_compare;
31 typedef Allocator allocator_type;
32 typedef typename allocator_type::reference reference;
33 typedef typename allocator_type::const_reference const_reference;
34 typedef typename allocator_type::size_type size_type;
35 typedef typename allocator_type::difference_type difference_type;
36 typedef typename allocator_type::pointer pointer;
37 typedef typename allocator_type::const_pointer const_pointer;
38
39 typedef implementation-defined iterator;
40 typedef implementation-defined const_iterator;
41 typedef std::reverse_iterator<iterator> reverse_iterator;
42 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
43
44 // construct/copy/destroy:
Howard Hinnantf95f4f52011-06-04 15:22:34 +000045 set()
46 noexcept(
47 is_nothrow_default_constructible<allocator_type>::value &&
48 is_nothrow_default_constructible<key_compare>::value &&
49 is_nothrow_copy_constructible<key_compare>::value);
50 explicit set(const value_compare& comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +000051 set(const value_compare& comp, const allocator_type& a);
52 template <class InputIterator>
53 set(InputIterator first, InputIterator last,
54 const value_compare& comp = value_compare());
55 template <class InputIterator>
56 set(InputIterator first, InputIterator last, const value_compare& comp,
57 const allocator_type& a);
58 set(const set& s);
Howard Hinnantf95f4f52011-06-04 15:22:34 +000059 set(set&& s)
60 noexcept(
61 is_nothrow_move_constructible<allocator_type>::value &&
62 is_nothrow_move_constructible<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +000063 explicit set(const allocator_type& a);
64 set(const set& s, const allocator_type& a);
65 set(set&& s, const allocator_type& a);
66 set(initializer_list<value_type> il, const value_compare& comp = value_compare());
67 set(initializer_list<value_type> il, const value_compare& comp,
68 const allocator_type& a);
Marshall Clow631788a2013-09-11 00:06:45 +000069 template <class InputIterator>
70 set(InputIterator first, InputIterator last, const allocator_type& a)
71 : set(first, last, Compare(), a) {} // C++14
72 set(initializer_list<value_type> il, const allocator_type& a)
73 : set(il, Compare(), a) {} // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000074 ~set();
75
76 set& operator=(const set& s);
Howard Hinnantf95f4f52011-06-04 15:22:34 +000077 set& operator=(set&& s)
78 noexcept(
79 allocator_type::propagate_on_container_move_assignment::value &&
80 is_nothrow_move_assignable<allocator_type>::value &&
81 is_nothrow_move_assignable<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +000082 set& operator=(initializer_list<value_type> il);
83
84 // iterators:
Howard Hinnantf95f4f52011-06-04 15:22:34 +000085 iterator begin() noexcept;
86 const_iterator begin() const noexcept;
87 iterator end() noexcept;
88 const_iterator end() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000089
Howard Hinnantf95f4f52011-06-04 15:22:34 +000090 reverse_iterator rbegin() noexcept;
91 const_reverse_iterator rbegin() const noexcept;
92 reverse_iterator rend() noexcept;
93 const_reverse_iterator rend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000094
Howard Hinnantf95f4f52011-06-04 15:22:34 +000095 const_iterator cbegin() const noexcept;
96 const_iterator cend() const noexcept;
97 const_reverse_iterator crbegin() const noexcept;
98 const_reverse_iterator crend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000099
100 // capacity:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000101 bool empty() const noexcept;
102 size_type size() const noexcept;
103 size_type max_size() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000104
105 // modifiers:
106 template <class... Args>
107 pair<iterator, bool> emplace(Args&&... args);
108 template <class... Args>
109 iterator emplace_hint(const_iterator position, Args&&... args);
110 pair<iterator,bool> insert(const value_type& v);
111 pair<iterator,bool> insert(value_type&& v);
112 iterator insert(const_iterator position, const value_type& v);
113 iterator insert(const_iterator position, value_type&& v);
114 template <class InputIterator>
115 void insert(InputIterator first, InputIterator last);
116 void insert(initializer_list<value_type> il);
117
118 iterator erase(const_iterator position);
Marshall Clow22ea5b82015-05-10 13:35:00 +0000119 iterator erase(iterator position); // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000120 size_type erase(const key_type& k);
121 iterator erase(const_iterator first, const_iterator last);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000122 void clear() noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000123
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000124 void swap(set& s)
125 noexcept(
126 __is_nothrow_swappable<key_compare>::value &&
127 (!allocator_type::propagate_on_container_swap::value ||
128 __is_nothrow_swappable<allocator_type>::value));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000129
130 // observers:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000131 allocator_type get_allocator() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000132 key_compare key_comp() const;
133 value_compare value_comp() const;
134
135 // set operations:
136 iterator find(const key_type& k);
137 const_iterator find(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000138 template<typename K>
139 iterator find(const K& x);
140 template<typename K>
141 const_iterator find(const K& x) const; // C++14
142 template<typename K>
143 size_type count(const K& x) const; // C++14
144
Howard Hinnantc51e1022010-05-11 19:42:16 +0000145 size_type count(const key_type& k) const;
146 iterator lower_bound(const key_type& k);
147 const_iterator lower_bound(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000148 template<typename K>
149 iterator lower_bound(const K& x); // C++14
150 template<typename K>
151 const_iterator lower_bound(const K& x) const; // C++14
152
Howard Hinnantc51e1022010-05-11 19:42:16 +0000153 iterator upper_bound(const key_type& k);
154 const_iterator upper_bound(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000155 template<typename K>
156 iterator upper_bound(const K& x); // C++14
157 template<typename K>
158 const_iterator upper_bound(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000159 pair<iterator,iterator> equal_range(const key_type& k);
160 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000161 template<typename K>
162 pair<iterator,iterator> equal_range(const K& x); // C++14
163 template<typename K>
164 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000165};
166
167template <class Key, class Compare, class Allocator>
168bool
169operator==(const set<Key, Compare, Allocator>& x,
170 const set<Key, Compare, Allocator>& y);
171
172template <class Key, class Compare, class Allocator>
173bool
174operator< (const set<Key, Compare, Allocator>& x,
175 const set<Key, Compare, Allocator>& y);
176
177template <class Key, class Compare, class Allocator>
178bool
179operator!=(const set<Key, Compare, Allocator>& x,
180 const set<Key, Compare, Allocator>& y);
181
182template <class Key, class Compare, class Allocator>
183bool
184operator> (const set<Key, Compare, Allocator>& x,
185 const set<Key, Compare, Allocator>& y);
186
187template <class Key, class Compare, class Allocator>
188bool
189operator>=(const set<Key, Compare, Allocator>& x,
190 const set<Key, Compare, Allocator>& y);
191
192template <class Key, class Compare, class Allocator>
193bool
194operator<=(const set<Key, Compare, Allocator>& x,
195 const set<Key, Compare, Allocator>& y);
196
197// specialized algorithms:
198template <class Key, class Compare, class Allocator>
199void
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000200swap(set<Key, Compare, Allocator>& x, set<Key, Compare, Allocator>& y)
201 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000202
Howard Hinnantc51e1022010-05-11 19:42:16 +0000203template <class Key, class Compare = less<Key>,
204 class Allocator = allocator<Key>>
205class multiset
206{
207public:
208 // types:
209 typedef Key key_type;
210 typedef key_type value_type;
211 typedef Compare key_compare;
212 typedef key_compare value_compare;
213 typedef Allocator allocator_type;
214 typedef typename allocator_type::reference reference;
215 typedef typename allocator_type::const_reference const_reference;
216 typedef typename allocator_type::size_type size_type;
217 typedef typename allocator_type::difference_type difference_type;
218 typedef typename allocator_type::pointer pointer;
219 typedef typename allocator_type::const_pointer const_pointer;
220
221 typedef implementation-defined iterator;
222 typedef implementation-defined const_iterator;
223 typedef std::reverse_iterator<iterator> reverse_iterator;
224 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
225
226 // construct/copy/destroy:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000227 multiset()
228 noexcept(
229 is_nothrow_default_constructible<allocator_type>::value &&
230 is_nothrow_default_constructible<key_compare>::value &&
231 is_nothrow_copy_constructible<key_compare>::value);
232 explicit multiset(const value_compare& comp);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000233 multiset(const value_compare& comp, const allocator_type& a);
234 template <class InputIterator>
235 multiset(InputIterator first, InputIterator last,
236 const value_compare& comp = value_compare());
237 template <class InputIterator>
238 multiset(InputIterator first, InputIterator last,
239 const value_compare& comp, const allocator_type& a);
240 multiset(const multiset& s);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000241 multiset(multiset&& s)
242 noexcept(
243 is_nothrow_move_constructible<allocator_type>::value &&
244 is_nothrow_move_constructible<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000245 explicit multiset(const allocator_type& a);
246 multiset(const multiset& s, const allocator_type& a);
247 multiset(multiset&& s, const allocator_type& a);
248 multiset(initializer_list<value_type> il, const value_compare& comp = value_compare());
249 multiset(initializer_list<value_type> il, const value_compare& comp,
250 const allocator_type& a);
Marshall Clow631788a2013-09-11 00:06:45 +0000251 template <class InputIterator>
252 multiset(InputIterator first, InputIterator last, const allocator_type& a)
253 : set(first, last, Compare(), a) {} // C++14
254 multiset(initializer_list<value_type> il, const allocator_type& a)
255 : set(il, Compare(), a) {} // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000256 ~multiset();
257
258 multiset& operator=(const multiset& s);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000259 multiset& operator=(multiset&& s)
260 noexcept(
261 allocator_type::propagate_on_container_move_assignment::value &&
262 is_nothrow_move_assignable<allocator_type>::value &&
263 is_nothrow_move_assignable<key_compare>::value);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000264 multiset& operator=(initializer_list<value_type> il);
265
266 // iterators:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000267 iterator begin() noexcept;
268 const_iterator begin() const noexcept;
269 iterator end() noexcept;
270 const_iterator end() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000271
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000272 reverse_iterator rbegin() noexcept;
273 const_reverse_iterator rbegin() const noexcept;
274 reverse_iterator rend() noexcept;
275 const_reverse_iterator rend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000276
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000277 const_iterator cbegin() const noexcept;
278 const_iterator cend() const noexcept;
279 const_reverse_iterator crbegin() const noexcept;
280 const_reverse_iterator crend() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000281
282 // capacity:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000283 bool empty() const noexcept;
284 size_type size() const noexcept;
285 size_type max_size() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000286
287 // modifiers:
288 template <class... Args>
289 iterator emplace(Args&&... args);
290 template <class... Args>
291 iterator emplace_hint(const_iterator position, Args&&... args);
292 iterator insert(const value_type& v);
293 iterator insert(value_type&& v);
294 iterator insert(const_iterator position, const value_type& v);
295 iterator insert(const_iterator position, value_type&& v);
296 template <class InputIterator>
297 void insert(InputIterator first, InputIterator last);
298 void insert(initializer_list<value_type> il);
299
300 iterator erase(const_iterator position);
Marshall Clow22ea5b82015-05-10 13:35:00 +0000301 iterator erase(iterator position); // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000302 size_type erase(const key_type& k);
303 iterator erase(const_iterator first, const_iterator last);
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000304 void clear() noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000305
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000306 void swap(multiset& s)
307 noexcept(
308 __is_nothrow_swappable<key_compare>::value &&
309 (!allocator_type::propagate_on_container_swap::value ||
310 __is_nothrow_swappable<allocator_type>::value));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000311
312 // observers:
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000313 allocator_type get_allocator() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000314 key_compare key_comp() const;
315 value_compare value_comp() const;
316
317 // set operations:
318 iterator find(const key_type& k);
319 const_iterator find(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000320 template<typename K>
321 iterator find(const K& x);
322 template<typename K>
323 const_iterator find(const K& x) const; // C++14
324
Howard Hinnantc51e1022010-05-11 19:42:16 +0000325 size_type count(const key_type& k) const;
326 iterator lower_bound(const key_type& k);
327 const_iterator lower_bound(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000328 template<typename K>
329 iterator lower_bound(const K& x); // C++14
330 template<typename K>
331 const_iterator lower_bound(const K& x) const; // C++14
332
Howard Hinnantc51e1022010-05-11 19:42:16 +0000333 iterator upper_bound(const key_type& k);
334 const_iterator upper_bound(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000335 template<typename K>
336 iterator upper_bound(const K& x); // C++14
337 template<typename K>
338 const_iterator upper_bound(const K& x) const; // C++14
339
Howard Hinnantc51e1022010-05-11 19:42:16 +0000340 pair<iterator,iterator> equal_range(const key_type& k);
341 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
Marshall Clowc0152142013-08-13 01:11:06 +0000342 template<typename K>
343 pair<iterator,iterator> equal_range(const K& x); // C++14
344 template<typename K>
345 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000346};
347
348template <class Key, class Compare, class Allocator>
349bool
350operator==(const multiset<Key, Compare, Allocator>& x,
351 const multiset<Key, Compare, Allocator>& y);
352
353template <class Key, class Compare, class Allocator>
354bool
355operator< (const multiset<Key, Compare, Allocator>& x,
356 const multiset<Key, Compare, Allocator>& y);
357
358template <class Key, class Compare, class Allocator>
359bool
360operator!=(const multiset<Key, Compare, Allocator>& x,
361 const multiset<Key, Compare, Allocator>& y);
362
363template <class Key, class Compare, class Allocator>
364bool
365operator> (const multiset<Key, Compare, Allocator>& x,
366 const multiset<Key, Compare, Allocator>& y);
367
368template <class Key, class Compare, class Allocator>
369bool
370operator>=(const multiset<Key, Compare, Allocator>& x,
371 const multiset<Key, Compare, Allocator>& y);
372
373template <class Key, class Compare, class Allocator>
374bool
375operator<=(const multiset<Key, Compare, Allocator>& x,
376 const multiset<Key, Compare, Allocator>& y);
377
378// specialized algorithms:
379template <class Key, class Compare, class Allocator>
380void
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000381swap(multiset<Key, Compare, Allocator>& x, multiset<Key, Compare, Allocator>& y)
382 noexcept(noexcept(x.swap(y)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000383
384} // std
385
386*/
387
388#include <__config>
389#include <__tree>
390#include <functional>
391
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000392#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000393#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000394#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000395
396_LIBCPP_BEGIN_NAMESPACE_STD
397
398template <class _Key, class _Compare = less<_Key>,
399 class _Allocator = allocator<_Key> >
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000400class _LIBCPP_TYPE_VIS_ONLY set
Howard Hinnantc51e1022010-05-11 19:42:16 +0000401{
402public:
403 // types:
404 typedef _Key key_type;
405 typedef key_type value_type;
406 typedef _Compare key_compare;
407 typedef key_compare value_compare;
408 typedef _Allocator allocator_type;
409 typedef value_type& reference;
410 typedef const value_type& const_reference;
411
Marshall Clow5128cf32015-11-26 01:24:04 +0000412 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
413 "Allocator::value_type must be same type as value_type");
414
Howard Hinnantc51e1022010-05-11 19:42:16 +0000415private:
416 typedef __tree<value_type, value_compare, allocator_type> __base;
417 typedef allocator_traits<allocator_type> __alloc_traits;
418 typedef typename __base::__node_holder __node_holder;
419
420 __base __tree_;
421
422public:
423 typedef typename __base::pointer pointer;
424 typedef typename __base::const_pointer const_pointer;
425 typedef typename __base::size_type size_type;
426 typedef typename __base::difference_type difference_type;
427 typedef typename __base::const_iterator iterator;
428 typedef typename __base::const_iterator const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000429 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
430 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000431
Howard Hinnant192cf032010-09-23 16:27:36 +0000432 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +0000433 set()
434 _NOEXCEPT_(
435 is_nothrow_default_constructible<allocator_type>::value &&
436 is_nothrow_default_constructible<key_compare>::value &&
437 is_nothrow_copy_constructible<key_compare>::value)
438 : __tree_(value_compare()) {}
439
440 _LIBCPP_INLINE_VISIBILITY
441 explicit set(const value_compare& __comp)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000442 _NOEXCEPT_(
443 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000444 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000445 : __tree_(__comp) {}
Marshall Clow7086a5a2014-03-10 04:50:10 +0000446
Howard Hinnant192cf032010-09-23 16:27:36 +0000447 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7ed23a72014-03-05 19:06:20 +0000448 explicit set(const value_compare& __comp, const allocator_type& __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000449 : __tree_(__comp, __a) {}
450 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000451 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000452 set(_InputIterator __f, _InputIterator __l,
453 const value_compare& __comp = value_compare())
454 : __tree_(__comp)
455 {
456 insert(__f, __l);
457 }
458
459 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000460 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000461 set(_InputIterator __f, _InputIterator __l, const value_compare& __comp,
462 const allocator_type& __a)
463 : __tree_(__comp, __a)
464 {
465 insert(__f, __l);
466 }
467
Marshall Clow631788a2013-09-11 00:06:45 +0000468#if _LIBCPP_STD_VER > 11
469 template <class _InputIterator>
470 _LIBCPP_INLINE_VISIBILITY
471 set(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
472 : set(__f, __l, key_compare(), __a) {}
473#endif
474
Howard Hinnant192cf032010-09-23 16:27:36 +0000475 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000476 set(const set& __s)
477 : __tree_(__s.__tree_)
478 {
479 insert(__s.begin(), __s.end());
480 }
481
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000482 _LIBCPP_INLINE_VISIBILITY
483 set& operator=(const set& __s)
484 {
485 __tree_ = __s.__tree_;
486 return *this;
487 }
488
Howard Hinnant74279a52010-09-04 23:28:19 +0000489#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant192cf032010-09-23 16:27:36 +0000490 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000491 set(set&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000492 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000493 : __tree_(_VSTD::move(__s.__tree_)) {}
Howard Hinnant74279a52010-09-04 23:28:19 +0000494#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000495
Howard Hinnant192cf032010-09-23 16:27:36 +0000496 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000497 explicit set(const allocator_type& __a)
498 : __tree_(__a) {}
499
Howard Hinnant192cf032010-09-23 16:27:36 +0000500 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000501 set(const set& __s, const allocator_type& __a)
502 : __tree_(__s.__tree_.value_comp(), __a)
503 {
504 insert(__s.begin(), __s.end());
505 }
506
Howard Hinnant74279a52010-09-04 23:28:19 +0000507#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000508 set(set&& __s, const allocator_type& __a);
509#endif
510
Howard Hinnant33711792011-08-12 21:56:02 +0000511#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant192cf032010-09-23 16:27:36 +0000512 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000513 set(initializer_list<value_type> __il, const value_compare& __comp = value_compare())
514 : __tree_(__comp)
515 {
516 insert(__il.begin(), __il.end());
517 }
518
Howard Hinnant192cf032010-09-23 16:27:36 +0000519 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000520 set(initializer_list<value_type> __il, const value_compare& __comp,
521 const allocator_type& __a)
522 : __tree_(__comp, __a)
523 {
524 insert(__il.begin(), __il.end());
525 }
526
Marshall Clow631788a2013-09-11 00:06:45 +0000527#if _LIBCPP_STD_VER > 11
528 _LIBCPP_INLINE_VISIBILITY
529 set(initializer_list<value_type> __il, const allocator_type& __a)
530 : set(__il, key_compare(), __a) {}
531#endif
532
Howard Hinnant192cf032010-09-23 16:27:36 +0000533 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000534 set& operator=(initializer_list<value_type> __il)
535 {
536 __tree_.__assign_unique(__il.begin(), __il.end());
537 return *this;
538 }
Howard Hinnant33711792011-08-12 21:56:02 +0000539#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000540
Howard Hinnant74279a52010-09-04 23:28:19 +0000541#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant192cf032010-09-23 16:27:36 +0000542 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000543 set& operator=(set&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000544 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000545 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000546 __tree_ = _VSTD::move(__s.__tree_);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000547 return *this;
548 }
Howard Hinnant74279a52010-09-04 23:28:19 +0000549#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000550
Howard Hinnant192cf032010-09-23 16:27:36 +0000551 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000552 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000553 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000554 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000555 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000556 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000557 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000558 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000559
Howard Hinnant192cf032010-09-23 16:27:36 +0000560 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000561 reverse_iterator rbegin() _NOEXCEPT
562 {return reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +0000563 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000564 const_reverse_iterator rbegin() const _NOEXCEPT
565 {return const_reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +0000566 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000567 reverse_iterator rend() _NOEXCEPT
568 {return reverse_iterator(begin());}
Howard Hinnant192cf032010-09-23 16:27:36 +0000569 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000570 const_reverse_iterator rend() const _NOEXCEPT
571 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000572
Howard Hinnant192cf032010-09-23 16:27:36 +0000573 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000574 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000575 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000576 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000577 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000578 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000579 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000580 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000581
Howard Hinnant192cf032010-09-23 16:27:36 +0000582 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000583 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant192cf032010-09-23 16:27:36 +0000584 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000585 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000586 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000587 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000588
589 // modifiers:
Howard Hinnant74279a52010-09-04 23:28:19 +0000590#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000591 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +0000592 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000593 pair<iterator, bool> emplace(_Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000594 {return __tree_.__emplace_unique(_VSTD::forward<_Args>(__args)...);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000595 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +0000596 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000597 iterator emplace_hint(const_iterator __p, _Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000598 {return __tree_.__emplace_hint_unique(__p, _VSTD::forward<_Args>(__args)...);}
Howard Hinnant74279a52010-09-04 23:28:19 +0000599#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnant192cf032010-09-23 16:27:36 +0000600 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000601 pair<iterator,bool> insert(const value_type& __v)
602 {return __tree_.__insert_unique(__v);}
Howard Hinnant74279a52010-09-04 23:28:19 +0000603#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant192cf032010-09-23 16:27:36 +0000604 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000605 pair<iterator,bool> insert(value_type&& __v)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000606 {return __tree_.__insert_unique(_VSTD::move(__v));}
Howard Hinnant74279a52010-09-04 23:28:19 +0000607#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant192cf032010-09-23 16:27:36 +0000608 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000609 iterator insert(const_iterator __p, const value_type& __v)
610 {return __tree_.__insert_unique(__p, __v);}
Howard Hinnant74279a52010-09-04 23:28:19 +0000611#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant192cf032010-09-23 16:27:36 +0000612 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000613 iterator insert(const_iterator __p, value_type&& __v)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000614 {return __tree_.__insert_unique(__p, _VSTD::move(__v));}
Howard Hinnant74279a52010-09-04 23:28:19 +0000615#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000616 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000617 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000618 void insert(_InputIterator __f, _InputIterator __l)
619 {
620 for (const_iterator __e = cend(); __f != __l; ++__f)
621 __tree_.__insert_unique(__e, *__f);
622 }
623
Howard Hinnant33711792011-08-12 21:56:02 +0000624#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant192cf032010-09-23 16:27:36 +0000625 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000626 void insert(initializer_list<value_type> __il)
627 {insert(__il.begin(), __il.end());}
Howard Hinnant33711792011-08-12 21:56:02 +0000628#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000629
Howard Hinnant192cf032010-09-23 16:27:36 +0000630 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000631 iterator erase(const_iterator __p) {return __tree_.erase(__p);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000632 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000633 size_type erase(const key_type& __k)
634 {return __tree_.__erase_unique(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000635 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000636 iterator erase(const_iterator __f, const_iterator __l)
637 {return __tree_.erase(__f, __l);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000638 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000639 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000640
Howard Hinnant192cf032010-09-23 16:27:36 +0000641 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000642 void swap(set& __s) _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
643 {__tree_.swap(__s.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000644
Howard Hinnant192cf032010-09-23 16:27:36 +0000645 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000646 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000647 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000648 key_compare key_comp() const {return __tree_.value_comp();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000649 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000650 value_compare value_comp() const {return __tree_.value_comp();}
651
652 // set operations:
Howard Hinnant192cf032010-09-23 16:27:36 +0000653 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000654 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000655 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000656 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000657#if _LIBCPP_STD_VER > 11
658 template <typename _K2>
659 _LIBCPP_INLINE_VISIBILITY
660 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
661 find(const _K2& __k) {return __tree_.find(__k);}
662 template <typename _K2>
663 _LIBCPP_INLINE_VISIBILITY
664 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
665 find(const _K2& __k) const {return __tree_.find(__k);}
666#endif
667
Howard Hinnant192cf032010-09-23 16:27:36 +0000668 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000669 size_type count(const key_type& __k) const
670 {return __tree_.__count_unique(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +0000671#if _LIBCPP_STD_VER > 11
672 template <typename _K2>
673 _LIBCPP_INLINE_VISIBILITY
674 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
Eric Fiselier0546e852016-12-09 12:17:31 +0000675 count(const _K2& __k) const {return __tree_.__count_unique(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +0000676#endif
Howard Hinnant192cf032010-09-23 16:27:36 +0000677 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000678 iterator lower_bound(const key_type& __k)
679 {return __tree_.lower_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000680 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000681 const_iterator lower_bound(const key_type& __k) const
682 {return __tree_.lower_bound(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000683#if _LIBCPP_STD_VER > 11
684 template <typename _K2>
685 _LIBCPP_INLINE_VISIBILITY
686 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
687 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
688
689 template <typename _K2>
690 _LIBCPP_INLINE_VISIBILITY
691 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
692 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
693#endif
694
Howard Hinnant192cf032010-09-23 16:27:36 +0000695 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000696 iterator upper_bound(const key_type& __k)
697 {return __tree_.upper_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000698 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000699 const_iterator upper_bound(const key_type& __k) const
700 {return __tree_.upper_bound(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000701#if _LIBCPP_STD_VER > 11
702 template <typename _K2>
703 _LIBCPP_INLINE_VISIBILITY
704 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
705 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
706 template <typename _K2>
707 _LIBCPP_INLINE_VISIBILITY
708 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
709 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
710#endif
711
Howard Hinnant192cf032010-09-23 16:27:36 +0000712 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000713 pair<iterator,iterator> equal_range(const key_type& __k)
714 {return __tree_.__equal_range_unique(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +0000715 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000716 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
717 {return __tree_.__equal_range_unique(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +0000718#if _LIBCPP_STD_VER > 11
719 template <typename _K2>
720 _LIBCPP_INLINE_VISIBILITY
721 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
722 equal_range(const _K2& __k) {return __tree_.__equal_range_unique(__k);}
723 template <typename _K2>
724 _LIBCPP_INLINE_VISIBILITY
725 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
726 equal_range(const _K2& __k) const {return __tree_.__equal_range_unique(__k);}
727#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000728};
729
Howard Hinnant74279a52010-09-04 23:28:19 +0000730#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000731
732template <class _Key, class _Compare, class _Allocator>
733set<_Key, _Compare, _Allocator>::set(set&& __s, const allocator_type& __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000734 : __tree_(_VSTD::move(__s.__tree_), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000735{
736 if (__a != __s.get_allocator())
737 {
738 const_iterator __e = cend();
739 while (!__s.empty())
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000740 insert(__e, _VSTD::move(__s.__tree_.remove(__s.begin())->__value_));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000741 }
742}
743
Howard Hinnant74279a52010-09-04 23:28:19 +0000744#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000745
746template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000747inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000748bool
749operator==(const set<_Key, _Compare, _Allocator>& __x,
750 const set<_Key, _Compare, _Allocator>& __y)
751{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000752 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000753}
754
755template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000756inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000757bool
758operator< (const set<_Key, _Compare, _Allocator>& __x,
759 const set<_Key, _Compare, _Allocator>& __y)
760{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000761 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +0000762}
763
764template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000765inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000766bool
767operator!=(const set<_Key, _Compare, _Allocator>& __x,
768 const set<_Key, _Compare, _Allocator>& __y)
769{
770 return !(__x == __y);
771}
772
773template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000774inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000775bool
776operator> (const set<_Key, _Compare, _Allocator>& __x,
777 const set<_Key, _Compare, _Allocator>& __y)
778{
779 return __y < __x;
780}
781
782template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000783inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000784bool
785operator>=(const set<_Key, _Compare, _Allocator>& __x,
786 const set<_Key, _Compare, _Allocator>& __y)
787{
788 return !(__x < __y);
789}
790
791template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000792inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000793bool
794operator<=(const set<_Key, _Compare, _Allocator>& __x,
795 const set<_Key, _Compare, _Allocator>& __y)
796{
797 return !(__y < __x);
798}
799
800// specialized algorithms:
801template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000802inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000803void
804swap(set<_Key, _Compare, _Allocator>& __x,
805 set<_Key, _Compare, _Allocator>& __y)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000806 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000807{
808 __x.swap(__y);
809}
810
Howard Hinnantc51e1022010-05-11 19:42:16 +0000811template <class _Key, class _Compare = less<_Key>,
812 class _Allocator = allocator<_Key> >
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000813class _LIBCPP_TYPE_VIS_ONLY multiset
Howard Hinnantc51e1022010-05-11 19:42:16 +0000814{
815public:
816 // types:
817 typedef _Key key_type;
818 typedef key_type value_type;
819 typedef _Compare key_compare;
820 typedef key_compare value_compare;
821 typedef _Allocator allocator_type;
822 typedef value_type& reference;
823 typedef const value_type& const_reference;
824
Marshall Clow5128cf32015-11-26 01:24:04 +0000825 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
826 "Allocator::value_type must be same type as value_type");
827
Howard Hinnantc51e1022010-05-11 19:42:16 +0000828private:
829 typedef __tree<value_type, value_compare, allocator_type> __base;
830 typedef allocator_traits<allocator_type> __alloc_traits;
831 typedef typename __base::__node_holder __node_holder;
832
833 __base __tree_;
834
835public:
836 typedef typename __base::pointer pointer;
837 typedef typename __base::const_pointer const_pointer;
838 typedef typename __base::size_type size_type;
839 typedef typename __base::difference_type difference_type;
840 typedef typename __base::const_iterator iterator;
841 typedef typename __base::const_iterator const_iterator;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000842 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
843 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000844
845 // construct/copy/destroy:
Howard Hinnant192cf032010-09-23 16:27:36 +0000846 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7086a5a2014-03-10 04:50:10 +0000847 multiset()
848 _NOEXCEPT_(
849 is_nothrow_default_constructible<allocator_type>::value &&
850 is_nothrow_default_constructible<key_compare>::value &&
851 is_nothrow_copy_constructible<key_compare>::value)
852 : __tree_(value_compare()) {}
853
854 _LIBCPP_INLINE_VISIBILITY
855 explicit multiset(const value_compare& __comp)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000856 _NOEXCEPT_(
857 is_nothrow_default_constructible<allocator_type>::value &&
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000858 is_nothrow_copy_constructible<key_compare>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000859 : __tree_(__comp) {}
Marshall Clow7086a5a2014-03-10 04:50:10 +0000860
Howard Hinnant192cf032010-09-23 16:27:36 +0000861 _LIBCPP_INLINE_VISIBILITY
Marshall Clow7ed23a72014-03-05 19:06:20 +0000862 explicit multiset(const value_compare& __comp, const allocator_type& __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000863 : __tree_(__comp, __a) {}
864 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000865 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000866 multiset(_InputIterator __f, _InputIterator __l,
867 const value_compare& __comp = value_compare())
868 : __tree_(__comp)
869 {
870 insert(__f, __l);
871 }
872
Marshall Clow631788a2013-09-11 00:06:45 +0000873#if _LIBCPP_STD_VER > 11
874 template <class _InputIterator>
875 _LIBCPP_INLINE_VISIBILITY
876 multiset(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
877 : multiset(__f, __l, key_compare(), __a) {}
878#endif
879
Howard Hinnantc51e1022010-05-11 19:42:16 +0000880 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +0000881 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000882 multiset(_InputIterator __f, _InputIterator __l,
883 const value_compare& __comp, const allocator_type& __a)
884 : __tree_(__comp, __a)
885 {
886 insert(__f, __l);
887 }
888
Howard Hinnant192cf032010-09-23 16:27:36 +0000889 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000890 multiset(const multiset& __s)
891 : __tree_(__s.__tree_.value_comp(),
892 __alloc_traits::select_on_container_copy_construction(__s.__tree_.__alloc()))
893 {
894 insert(__s.begin(), __s.end());
895 }
896
Howard Hinnantd3a657f2011-07-01 19:24:36 +0000897 _LIBCPP_INLINE_VISIBILITY
898 multiset& operator=(const multiset& __s)
899 {
900 __tree_ = __s.__tree_;
901 return *this;
902 }
903
Howard Hinnant74279a52010-09-04 23:28:19 +0000904#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant192cf032010-09-23 16:27:36 +0000905 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000906 multiset(multiset&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000907 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000908 : __tree_(_VSTD::move(__s.__tree_)) {}
Howard Hinnant74279a52010-09-04 23:28:19 +0000909#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant192cf032010-09-23 16:27:36 +0000910 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000911 explicit multiset(const allocator_type& __a)
912 : __tree_(__a) {}
Howard Hinnant192cf032010-09-23 16:27:36 +0000913 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000914 multiset(const multiset& __s, const allocator_type& __a)
915 : __tree_(__s.__tree_.value_comp(), __a)
916 {
917 insert(__s.begin(), __s.end());
918 }
Howard Hinnant74279a52010-09-04 23:28:19 +0000919#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000920 multiset(multiset&& __s, const allocator_type& __a);
921#endif
922
Howard Hinnant33711792011-08-12 21:56:02 +0000923#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant192cf032010-09-23 16:27:36 +0000924 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000925 multiset(initializer_list<value_type> __il, const value_compare& __comp = value_compare())
926 : __tree_(__comp)
927 {
928 insert(__il.begin(), __il.end());
929 }
930
Howard Hinnant192cf032010-09-23 16:27:36 +0000931 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000932 multiset(initializer_list<value_type> __il, const value_compare& __comp,
933 const allocator_type& __a)
934 : __tree_(__comp, __a)
935 {
936 insert(__il.begin(), __il.end());
937 }
938
Marshall Clow631788a2013-09-11 00:06:45 +0000939#if _LIBCPP_STD_VER > 11
940 _LIBCPP_INLINE_VISIBILITY
941 multiset(initializer_list<value_type> __il, const allocator_type& __a)
942 : multiset(__il, key_compare(), __a) {}
943#endif
944
Howard Hinnant192cf032010-09-23 16:27:36 +0000945 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000946 multiset& operator=(initializer_list<value_type> __il)
947 {
948 __tree_.__assign_multi(__il.begin(), __il.end());
949 return *this;
950 }
Howard Hinnant33711792011-08-12 21:56:02 +0000951#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000952
Howard Hinnant74279a52010-09-04 23:28:19 +0000953#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant192cf032010-09-23 16:27:36 +0000954 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000955 multiset& operator=(multiset&& __s)
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000956 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000957 {
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000958 __tree_ = _VSTD::move(__s.__tree_);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000959 return *this;
960 }
Howard Hinnant74279a52010-09-04 23:28:19 +0000961#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000962
Howard Hinnant192cf032010-09-23 16:27:36 +0000963 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000964 iterator begin() _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000965 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000966 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000967 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000968 iterator end() _NOEXCEPT {return __tree_.end();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000969 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000970 const_iterator end() const _NOEXCEPT {return __tree_.end();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000971
Howard Hinnant192cf032010-09-23 16:27:36 +0000972 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000973 reverse_iterator rbegin() _NOEXCEPT
974 {return reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +0000975 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000976 const_reverse_iterator rbegin() const _NOEXCEPT
977 {return const_reverse_iterator(end());}
Howard Hinnant192cf032010-09-23 16:27:36 +0000978 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000979 reverse_iterator rend() _NOEXCEPT
980 {return reverse_iterator(begin());}
Howard Hinnant192cf032010-09-23 16:27:36 +0000981 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000982 const_reverse_iterator rend() const _NOEXCEPT
983 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000984
Howard Hinnant192cf032010-09-23 16:27:36 +0000985 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000986 const_iterator cbegin() const _NOEXCEPT {return begin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000987 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000988 const_iterator cend() const _NOEXCEPT {return end();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000989 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000990 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000991 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000992 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000993
Howard Hinnant192cf032010-09-23 16:27:36 +0000994 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000995 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
Howard Hinnant192cf032010-09-23 16:27:36 +0000996 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000997 size_type size() const _NOEXCEPT {return __tree_.size();}
Howard Hinnant192cf032010-09-23 16:27:36 +0000998 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +0000999 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001000
1001 // modifiers:
Howard Hinnant74279a52010-09-04 23:28:19 +00001002#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001003 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +00001004 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001005 iterator emplace(_Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001006 {return __tree_.__emplace_multi(_VSTD::forward<_Args>(__args)...);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001007 template <class... _Args>
Howard Hinnant192cf032010-09-23 16:27:36 +00001008 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001009 iterator emplace_hint(const_iterator __p, _Args&&... __args)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001010 {return __tree_.__emplace_hint_multi(__p, _VSTD::forward<_Args>(__args)...);}
Howard Hinnant74279a52010-09-04 23:28:19 +00001011#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
Howard Hinnant192cf032010-09-23 16:27:36 +00001012 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001013 iterator insert(const value_type& __v)
1014 {return __tree_.__insert_multi(__v);}
Howard Hinnant74279a52010-09-04 23:28:19 +00001015#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant192cf032010-09-23 16:27:36 +00001016 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001017 iterator insert(value_type&& __v)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001018 {return __tree_.__insert_multi(_VSTD::move(__v));}
Howard Hinnant74279a52010-09-04 23:28:19 +00001019#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant192cf032010-09-23 16:27:36 +00001020 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001021 iterator insert(const_iterator __p, const value_type& __v)
1022 {return __tree_.__insert_multi(__p, __v);}
Howard Hinnant74279a52010-09-04 23:28:19 +00001023#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant192cf032010-09-23 16:27:36 +00001024 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001025 iterator insert(const_iterator __p, value_type&& __v)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001026 {return __tree_.__insert_multi(_VSTD::move(__v));}
Howard Hinnant74279a52010-09-04 23:28:19 +00001027#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001028 template <class _InputIterator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001029 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001030 void insert(_InputIterator __f, _InputIterator __l)
1031 {
1032 for (const_iterator __e = cend(); __f != __l; ++__f)
1033 __tree_.__insert_multi(__e, *__f);
1034 }
1035
Howard Hinnant33711792011-08-12 21:56:02 +00001036#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant192cf032010-09-23 16:27:36 +00001037 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001038 void insert(initializer_list<value_type> __il)
1039 {insert(__il.begin(), __il.end());}
Howard Hinnant33711792011-08-12 21:56:02 +00001040#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001041
Howard Hinnant192cf032010-09-23 16:27:36 +00001042 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001043 iterator erase(const_iterator __p) {return __tree_.erase(__p);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001044 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001045 size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001046 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001047 iterator erase(const_iterator __f, const_iterator __l)
1048 {return __tree_.erase(__f, __l);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001049 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001050 void clear() _NOEXCEPT {__tree_.clear();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001051
Howard Hinnant192cf032010-09-23 16:27:36 +00001052 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001053 void swap(multiset& __s)
1054 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1055 {__tree_.swap(__s.__tree_);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001056
Howard Hinnant192cf032010-09-23 16:27:36 +00001057 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001058 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001059 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001060 key_compare key_comp() const {return __tree_.value_comp();}
Howard Hinnant192cf032010-09-23 16:27:36 +00001061 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001062 value_compare value_comp() const {return __tree_.value_comp();}
1063
1064 // set operations:
Howard Hinnant192cf032010-09-23 16:27:36 +00001065 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001066 iterator find(const key_type& __k) {return __tree_.find(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001067 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001068 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +00001069#if _LIBCPP_STD_VER > 11
1070 template <typename _K2>
1071 _LIBCPP_INLINE_VISIBILITY
1072 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,iterator>::type
1073 find(const _K2& __k) {return __tree_.find(__k);}
1074 template <typename _K2>
1075 _LIBCPP_INLINE_VISIBILITY
1076 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,const_iterator>::type
1077 find(const _K2& __k) const {return __tree_.find(__k);}
1078#endif
1079
Howard Hinnant192cf032010-09-23 16:27:36 +00001080 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001081 size_type count(const key_type& __k) const
1082 {return __tree_.__count_multi(__k);}
Marshall Clowe6a5f522014-08-24 23:54:16 +00001083#if _LIBCPP_STD_VER > 11
1084 template <typename _K2>
1085 _LIBCPP_INLINE_VISIBILITY
1086 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
1087 count(const _K2& __k) {return __tree_.__count_multi(__k);}
1088#endif
Marshall Clowc0152142013-08-13 01:11:06 +00001089
Howard Hinnant192cf032010-09-23 16:27:36 +00001090 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001091 iterator lower_bound(const key_type& __k)
1092 {return __tree_.lower_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001093 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001094 const_iterator lower_bound(const key_type& __k) const
1095 {return __tree_.lower_bound(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +00001096#if _LIBCPP_STD_VER > 11
1097 template <typename _K2>
1098 _LIBCPP_INLINE_VISIBILITY
1099 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,iterator>::type
1100 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
1101
1102 template <typename _K2>
1103 _LIBCPP_INLINE_VISIBILITY
1104 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,const_iterator>::type
1105 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
1106#endif
1107
Howard Hinnant192cf032010-09-23 16:27:36 +00001108 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001109 iterator upper_bound(const key_type& __k)
1110 {return __tree_.upper_bound(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001111 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001112 const_iterator upper_bound(const key_type& __k) const
1113 {return __tree_.upper_bound(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +00001114#if _LIBCPP_STD_VER > 11
1115 template <typename _K2>
1116 _LIBCPP_INLINE_VISIBILITY
1117 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,iterator>::type
1118 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
1119 template <typename _K2>
1120 _LIBCPP_INLINE_VISIBILITY
1121 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,const_iterator>::type
1122 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
1123#endif
1124
Howard Hinnant192cf032010-09-23 16:27:36 +00001125 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001126 pair<iterator,iterator> equal_range(const key_type& __k)
1127 {return __tree_.__equal_range_multi(__k);}
Howard Hinnant192cf032010-09-23 16:27:36 +00001128 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001129 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
1130 {return __tree_.__equal_range_multi(__k);}
Marshall Clowc0152142013-08-13 01:11:06 +00001131#if _LIBCPP_STD_VER > 11
1132 template <typename _K2>
1133 _LIBCPP_INLINE_VISIBILITY
1134 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
1135 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
1136 template <typename _K2>
1137 _LIBCPP_INLINE_VISIBILITY
1138 typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
1139 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
1140#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001141};
1142
Howard Hinnant74279a52010-09-04 23:28:19 +00001143#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001144
1145template <class _Key, class _Compare, class _Allocator>
1146multiset<_Key, _Compare, _Allocator>::multiset(multiset&& __s, const allocator_type& __a)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001147 : __tree_(_VSTD::move(__s.__tree_), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001148{
1149 if (__a != __s.get_allocator())
1150 {
1151 const_iterator __e = cend();
1152 while (!__s.empty())
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001153 insert(__e, _VSTD::move(__s.__tree_.remove(__s.begin())->__value_));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001154 }
1155}
1156
Howard Hinnant74279a52010-09-04 23:28:19 +00001157#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc51e1022010-05-11 19:42:16 +00001158
1159template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001160inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001161bool
1162operator==(const multiset<_Key, _Compare, _Allocator>& __x,
1163 const multiset<_Key, _Compare, _Allocator>& __y)
1164{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001165 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001166}
1167
1168template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001169inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001170bool
1171operator< (const multiset<_Key, _Compare, _Allocator>& __x,
1172 const multiset<_Key, _Compare, _Allocator>& __y)
1173{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001174 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001175}
1176
1177template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001178inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001179bool
1180operator!=(const multiset<_Key, _Compare, _Allocator>& __x,
1181 const multiset<_Key, _Compare, _Allocator>& __y)
1182{
1183 return !(__x == __y);
1184}
1185
1186template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001187inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001188bool
1189operator> (const multiset<_Key, _Compare, _Allocator>& __x,
1190 const multiset<_Key, _Compare, _Allocator>& __y)
1191{
1192 return __y < __x;
1193}
1194
1195template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001196inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001197bool
1198operator>=(const multiset<_Key, _Compare, _Allocator>& __x,
1199 const multiset<_Key, _Compare, _Allocator>& __y)
1200{
1201 return !(__x < __y);
1202}
1203
1204template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001205inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001206bool
1207operator<=(const multiset<_Key, _Compare, _Allocator>& __x,
1208 const multiset<_Key, _Compare, _Allocator>& __y)
1209{
1210 return !(__y < __x);
1211}
1212
1213template <class _Key, class _Compare, class _Allocator>
Howard Hinnant192cf032010-09-23 16:27:36 +00001214inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001215void
1216swap(multiset<_Key, _Compare, _Allocator>& __x,
1217 multiset<_Key, _Compare, _Allocator>& __y)
Howard Hinnantf95f4f52011-06-04 15:22:34 +00001218 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001219{
1220 __x.swap(__y);
1221}
1222
Howard Hinnantc51e1022010-05-11 19:42:16 +00001223_LIBCPP_END_NAMESPACE_STD
1224
1225#endif // _LIBCPP_SET