2 //===----------------------------------------------------------------------===//
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
20 template <class Key, class Compare = less<Key>,
21 class Allocator = allocator<Key>>
27 typedef key_type value_type;
28 typedef Compare key_compare;
29 typedef key_compare value_compare;
30 typedef Allocator allocator_type;
31 typedef typename allocator_type::reference reference;
32 typedef typename allocator_type::const_reference const_reference;
33 typedef typename allocator_type::size_type size_type;
34 typedef typename allocator_type::difference_type difference_type;
35 typedef typename allocator_type::pointer pointer;
36 typedef typename allocator_type::const_pointer const_pointer;
38 typedef implementation-defined iterator;
39 typedef implementation-defined const_iterator;
40 typedef std::reverse_iterator<iterator> reverse_iterator;
41 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
42 typedef unspecified node_type; // C++17
43 typedef INSERT_RETURN_TYPE<iterator, node_type> insert_return_type; // C++17
45 // construct/copy/destroy:
48 is_nothrow_default_constructible<allocator_type>::value &&
49 is_nothrow_default_constructible<key_compare>::value &&
50 is_nothrow_copy_constructible<key_compare>::value);
51 explicit set(const value_compare& comp);
52 set(const value_compare& comp, const allocator_type& a);
53 template <class InputIterator>
54 set(InputIterator first, InputIterator last,
55 const value_compare& comp = value_compare());
56 template <class InputIterator>
57 set(InputIterator first, InputIterator last, const value_compare& comp,
58 const allocator_type& a);
62 is_nothrow_move_constructible<allocator_type>::value &&
63 is_nothrow_move_constructible<key_compare>::value);
64 explicit set(const allocator_type& a);
65 set(const set& s, const allocator_type& a);
66 set(set&& s, const allocator_type& a);
67 set(initializer_list<value_type> il, const value_compare& comp = value_compare());
68 set(initializer_list<value_type> il, const value_compare& comp,
69 const allocator_type& a);
70 template <class InputIterator>
71 set(InputIterator first, InputIterator last, const allocator_type& a)
72 : set(first, last, Compare(), a) {} // C++14
73 set(initializer_list<value_type> il, const allocator_type& a)
74 : set(il, Compare(), a) {} // C++14
77 set& operator=(const set& s);
78 set& operator=(set&& s)
80 allocator_type::propagate_on_container_move_assignment::value &&
81 is_nothrow_move_assignable<allocator_type>::value &&
82 is_nothrow_move_assignable<key_compare>::value);
83 set& operator=(initializer_list<value_type> il);
86 iterator begin() noexcept;
87 const_iterator begin() const noexcept;
88 iterator end() noexcept;
89 const_iterator end() const noexcept;
91 reverse_iterator rbegin() noexcept;
92 const_reverse_iterator rbegin() const noexcept;
93 reverse_iterator rend() noexcept;
94 const_reverse_iterator rend() const noexcept;
96 const_iterator cbegin() const noexcept;
97 const_iterator cend() const noexcept;
98 const_reverse_iterator crbegin() const noexcept;
99 const_reverse_iterator crend() const noexcept;
102 bool empty() const noexcept;
103 size_type size() const noexcept;
104 size_type max_size() const noexcept;
107 template <class... Args>
108 pair<iterator, bool> emplace(Args&&... args);
109 template <class... Args>
110 iterator emplace_hint(const_iterator position, Args&&... args);
111 pair<iterator,bool> insert(const value_type& v);
112 pair<iterator,bool> insert(value_type&& v);
113 iterator insert(const_iterator position, const value_type& v);
114 iterator insert(const_iterator position, value_type&& v);
115 template <class InputIterator>
116 void insert(InputIterator first, InputIterator last);
117 void insert(initializer_list<value_type> il);
119 node_type extract(const_iterator position); // C++17
120 node_type extract(const key_type& x); // C++17
121 insert_return_type insert(node_type&& nh); // C++17
122 iterator insert(const_iterator hint, node_type&& nh); // C++17
124 iterator erase(const_iterator position);
125 iterator erase(iterator position); // C++14
126 size_type erase(const key_type& k);
127 iterator erase(const_iterator first, const_iterator last);
128 void clear() noexcept;
131 void merge(set<Key, C2, Allocator>& source); // C++17
133 void merge(set<Key, C2, Allocator>&& source); // C++17
135 void merge(multiset<Key, C2, Allocator>& source); // C++17
137 void merge(multiset<Key, C2, Allocator>&& source); // C++17
141 __is_nothrow_swappable<key_compare>::value &&
142 (!allocator_type::propagate_on_container_swap::value ||
143 __is_nothrow_swappable<allocator_type>::value));
146 allocator_type get_allocator() const noexcept;
147 key_compare key_comp() const;
148 value_compare value_comp() const;
151 iterator find(const key_type& k);
152 const_iterator find(const key_type& k) const;
154 iterator find(const K& x);
156 const_iterator find(const K& x) const; // C++14
159 size_type count(const K& x) const; // C++14
160 size_type count(const key_type& k) const;
162 bool contains(const key_type& x) const; // C++20
163 template<class K> bool contains(const K& x) const; // C++20
165 iterator lower_bound(const key_type& k);
166 const_iterator lower_bound(const key_type& k) const;
168 iterator lower_bound(const K& x); // C++14
170 const_iterator lower_bound(const K& x) const; // C++14
172 iterator upper_bound(const key_type& k);
173 const_iterator upper_bound(const key_type& k) const;
175 iterator upper_bound(const K& x); // C++14
177 const_iterator upper_bound(const K& x) const; // C++14
178 pair<iterator,iterator> equal_range(const key_type& k);
179 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
181 pair<iterator,iterator> equal_range(const K& x); // C++14
183 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
186 template <class InputIterator,
187 class Compare = less<typename iterator_traits<InputIterator>::value_type>,
188 class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
189 set(InputIterator, InputIterator,
190 Compare = Compare(), Allocator = Allocator())
191 -> set<typename iterator_traits<InputIterator>::value_type, Compare, Allocator>; // C++17
193 template<class Key, class Compare = less<Key>, class Allocator = allocator<Key>>
194 set(initializer_list<Key>, Compare = Compare(), Allocator = Allocator())
195 -> set<Key, Compare, Allocator>; // C++17
197 template<class InputIterator, class Allocator>
198 set(InputIterator, InputIterator, Allocator)
199 -> set<typename iterator_traits<InputIterator>::value_type,
200 less<typename iterator_traits<InputIterator>::value_type>, Allocator>; // C++17
202 template<class Key, class Allocator>
203 set(initializer_list<Key>, Allocator) -> set<Key, less<Key>, Allocator>; // C++17
205 template <class Key, class Compare, class Allocator>
207 operator==(const set<Key, Compare, Allocator>& x,
208 const set<Key, Compare, Allocator>& y);
210 template <class Key, class Compare, class Allocator>
212 operator< (const set<Key, Compare, Allocator>& x,
213 const set<Key, Compare, Allocator>& y);
215 template <class Key, class Compare, class Allocator>
217 operator!=(const set<Key, Compare, Allocator>& x,
218 const set<Key, Compare, Allocator>& y);
220 template <class Key, class Compare, class Allocator>
222 operator> (const set<Key, Compare, Allocator>& x,
223 const set<Key, Compare, Allocator>& y);
225 template <class Key, class Compare, class Allocator>
227 operator>=(const set<Key, Compare, Allocator>& x,
228 const set<Key, Compare, Allocator>& y);
230 template <class Key, class Compare, class Allocator>
232 operator<=(const set<Key, Compare, Allocator>& x,
233 const set<Key, Compare, Allocator>& y);
235 // specialized algorithms:
236 template <class Key, class Compare, class Allocator>
238 swap(set<Key, Compare, Allocator>& x, set<Key, Compare, Allocator>& y)
239 noexcept(noexcept(x.swap(y)));
241 template <class Key, class Compare, class Allocator, class Predicate>
242 typename set<Key, Compare, Allocator>::size_type
243 erase_if(set<Key, Compare, Allocator>& c, Predicate pred); // C++20
245 template <class Key, class Compare = less<Key>,
246 class Allocator = allocator<Key>>
251 typedef Key key_type;
252 typedef key_type value_type;
253 typedef Compare key_compare;
254 typedef key_compare value_compare;
255 typedef Allocator allocator_type;
256 typedef typename allocator_type::reference reference;
257 typedef typename allocator_type::const_reference const_reference;
258 typedef typename allocator_type::size_type size_type;
259 typedef typename allocator_type::difference_type difference_type;
260 typedef typename allocator_type::pointer pointer;
261 typedef typename allocator_type::const_pointer const_pointer;
263 typedef implementation-defined iterator;
264 typedef implementation-defined const_iterator;
265 typedef std::reverse_iterator<iterator> reverse_iterator;
266 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
267 typedef unspecified node_type; // C++17
269 // construct/copy/destroy:
272 is_nothrow_default_constructible<allocator_type>::value &&
273 is_nothrow_default_constructible<key_compare>::value &&
274 is_nothrow_copy_constructible<key_compare>::value);
275 explicit multiset(const value_compare& comp);
276 multiset(const value_compare& comp, const allocator_type& a);
277 template <class InputIterator>
278 multiset(InputIterator first, InputIterator last,
279 const value_compare& comp = value_compare());
280 template <class InputIterator>
281 multiset(InputIterator first, InputIterator last,
282 const value_compare& comp, const allocator_type& a);
283 multiset(const multiset& s);
284 multiset(multiset&& s)
286 is_nothrow_move_constructible<allocator_type>::value &&
287 is_nothrow_move_constructible<key_compare>::value);
288 explicit multiset(const allocator_type& a);
289 multiset(const multiset& s, const allocator_type& a);
290 multiset(multiset&& s, const allocator_type& a);
291 multiset(initializer_list<value_type> il, const value_compare& comp = value_compare());
292 multiset(initializer_list<value_type> il, const value_compare& comp,
293 const allocator_type& a);
294 template <class InputIterator>
295 multiset(InputIterator first, InputIterator last, const allocator_type& a)
296 : set(first, last, Compare(), a) {} // C++14
297 multiset(initializer_list<value_type> il, const allocator_type& a)
298 : set(il, Compare(), a) {} // C++14
301 multiset& operator=(const multiset& s);
302 multiset& operator=(multiset&& s)
304 allocator_type::propagate_on_container_move_assignment::value &&
305 is_nothrow_move_assignable<allocator_type>::value &&
306 is_nothrow_move_assignable<key_compare>::value);
307 multiset& operator=(initializer_list<value_type> il);
310 iterator begin() noexcept;
311 const_iterator begin() const noexcept;
312 iterator end() noexcept;
313 const_iterator end() const noexcept;
315 reverse_iterator rbegin() noexcept;
316 const_reverse_iterator rbegin() const noexcept;
317 reverse_iterator rend() noexcept;
318 const_reverse_iterator rend() const noexcept;
320 const_iterator cbegin() const noexcept;
321 const_iterator cend() const noexcept;
322 const_reverse_iterator crbegin() const noexcept;
323 const_reverse_iterator crend() const noexcept;
326 bool empty() const noexcept;
327 size_type size() const noexcept;
328 size_type max_size() const noexcept;
331 template <class... Args>
332 iterator emplace(Args&&... args);
333 template <class... Args>
334 iterator emplace_hint(const_iterator position, Args&&... args);
335 iterator insert(const value_type& v);
336 iterator insert(value_type&& v);
337 iterator insert(const_iterator position, const value_type& v);
338 iterator insert(const_iterator position, value_type&& v);
339 template <class InputIterator>
340 void insert(InputIterator first, InputIterator last);
341 void insert(initializer_list<value_type> il);
343 node_type extract(const_iterator position); // C++17
344 node_type extract(const key_type& x); // C++17
345 iterator insert(node_type&& nh); // C++17
346 iterator insert(const_iterator hint, node_type&& nh); // C++17
348 iterator erase(const_iterator position);
349 iterator erase(iterator position); // C++14
350 size_type erase(const key_type& k);
351 iterator erase(const_iterator first, const_iterator last);
352 void clear() noexcept;
355 void merge(multiset<Key, C2, Allocator>& source); // C++17
357 void merge(multiset<Key, C2, Allocator>&& source); // C++17
359 void merge(set<Key, C2, Allocator>& source); // C++17
361 void merge(set<Key, C2, Allocator>&& source); // C++17
363 void swap(multiset& s)
365 __is_nothrow_swappable<key_compare>::value &&
366 (!allocator_type::propagate_on_container_swap::value ||
367 __is_nothrow_swappable<allocator_type>::value));
370 allocator_type get_allocator() const noexcept;
371 key_compare key_comp() const;
372 value_compare value_comp() const;
375 iterator find(const key_type& k);
376 const_iterator find(const key_type& k) const;
378 iterator find(const K& x);
380 const_iterator find(const K& x) const; // C++14
383 size_type count(const K& x) const; // C++14
384 size_type count(const key_type& k) const;
386 bool contains(const key_type& x) const; // C++20
387 template<class K> bool contains(const K& x) const; // C++20
389 iterator lower_bound(const key_type& k);
390 const_iterator lower_bound(const key_type& k) const;
392 iterator lower_bound(const K& x); // C++14
394 const_iterator lower_bound(const K& x) const; // C++14
396 iterator upper_bound(const key_type& k);
397 const_iterator upper_bound(const key_type& k) const;
399 iterator upper_bound(const K& x); // C++14
401 const_iterator upper_bound(const K& x) const; // C++14
403 pair<iterator,iterator> equal_range(const key_type& k);
404 pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
406 pair<iterator,iterator> equal_range(const K& x); // C++14
408 pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
411 template <class InputIterator,
412 class Compare = less<typename iterator_traits<InputIterator>::value_type>,
413 class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
414 multiset(InputIterator, InputIterator,
415 Compare = Compare(), Allocator = Allocator())
416 -> multiset<typename iterator_traits<InputIterator>::value_type, Compare, Allocator>; // C++17
418 template<class Key, class Compare = less<Key>, class Allocator = allocator<Key>>
419 multiset(initializer_list<Key>, Compare = Compare(), Allocator = Allocator())
420 -> multiset<Key, Compare, Allocator>; // C++17
422 template<class InputIterator, class Allocator>
423 multiset(InputIterator, InputIterator, Allocator)
424 -> multiset<typename iterator_traits<InputIterator>::value_type,
425 less<typename iterator_traits<InputIterator>::value_type>, Allocator>; // C++17
427 template<class Key, class Allocator>
428 multiset(initializer_list<Key>, Allocator) -> multiset<Key, less<Key>, Allocator>; // C++17
430 template <class Key, class Compare, class Allocator>
432 operator==(const multiset<Key, Compare, Allocator>& x,
433 const multiset<Key, Compare, Allocator>& y);
435 template <class Key, class Compare, class Allocator>
437 operator< (const multiset<Key, Compare, Allocator>& x,
438 const multiset<Key, Compare, Allocator>& y);
440 template <class Key, class Compare, class Allocator>
442 operator!=(const multiset<Key, Compare, Allocator>& x,
443 const multiset<Key, Compare, Allocator>& y);
445 template <class Key, class Compare, class Allocator>
447 operator> (const multiset<Key, Compare, Allocator>& x,
448 const multiset<Key, Compare, Allocator>& y);
450 template <class Key, class Compare, class Allocator>
452 operator>=(const multiset<Key, Compare, Allocator>& x,
453 const multiset<Key, Compare, Allocator>& y);
455 template <class Key, class Compare, class Allocator>
457 operator<=(const multiset<Key, Compare, Allocator>& x,
458 const multiset<Key, Compare, Allocator>& y);
460 // specialized algorithms:
461 template <class Key, class Compare, class Allocator>
463 swap(multiset<Key, Compare, Allocator>& x, multiset<Key, Compare, Allocator>& y)
464 noexcept(noexcept(x.swap(y)));
466 template <class Key, class Compare, class Allocator, class Predicate>
467 typename multiset<Key, Compare, Allocator>::size_type
468 erase_if(multiset<Key, Compare, Allocator>& c, Predicate pred); // C++20
474 #include <__algorithm/equal.h>
475 #include <__algorithm/lexicographical_compare.h>
476 #include <__assert> // all public C++ headers provide the assertion handler
478 #include <__functional/is_transparent.h>
479 #include <__functional/operations.h>
480 #include <__iterator/erase_if_container.h>
481 #include <__iterator/iterator_traits.h>
482 #include <__iterator/reverse_iterator.h>
483 #include <__node_handle>
485 #include <__utility/forward.h>
488 #ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
489 # include <functional>
493 // standard-mandated includes
496 #include <__iterator/access.h>
497 #include <__iterator/data.h>
498 #include <__iterator/empty.h>
499 #include <__iterator/reverse_access.h>
500 #include <__iterator/size.h>
502 // [associative.set.syn]
504 #include <initializer_list>
506 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
507 # pragma GCC system_header
510 _LIBCPP_BEGIN_NAMESPACE_STD
512 template <class _Key, class _Compare, class _Allocator>
515 template <class _Key, class _Compare = less<_Key>,
516 class _Allocator = allocator<_Key> >
517 class _LIBCPP_TEMPLATE_VIS set
521 typedef _Key key_type;
522 typedef key_type value_type;
523 typedef __type_identity_t<_Compare> key_compare;
524 typedef key_compare value_compare;
525 typedef __type_identity_t<_Allocator> allocator_type;
526 typedef value_type& reference;
527 typedef const value_type& const_reference;
529 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
530 "Allocator::value_type must be same type as value_type");
533 typedef __tree<value_type, value_compare, allocator_type> __base;
534 typedef allocator_traits<allocator_type> __alloc_traits;
539 typedef typename __base::pointer pointer;
540 typedef typename __base::const_pointer const_pointer;
541 typedef typename __base::size_type size_type;
542 typedef typename __base::difference_type difference_type;
543 typedef typename __base::const_iterator iterator;
544 typedef typename __base::const_iterator const_iterator;
545 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
546 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
548 #if _LIBCPP_STD_VER > 14
549 typedef __set_node_handle<typename __base::__node, allocator_type> node_type;
550 typedef __insert_return_type<iterator, node_type> insert_return_type;
553 template <class _Key2, class _Compare2, class _Alloc2>
554 friend class _LIBCPP_TEMPLATE_VIS set;
555 template <class _Key2, class _Compare2, class _Alloc2>
556 friend class _LIBCPP_TEMPLATE_VIS multiset;
558 _LIBCPP_INLINE_VISIBILITY
561 is_nothrow_default_constructible<allocator_type>::value &&
562 is_nothrow_default_constructible<key_compare>::value &&
563 is_nothrow_copy_constructible<key_compare>::value)
564 : __tree_(value_compare()) {}
566 _LIBCPP_INLINE_VISIBILITY
567 explicit set(const value_compare& __comp)
569 is_nothrow_default_constructible<allocator_type>::value &&
570 is_nothrow_copy_constructible<key_compare>::value)
573 _LIBCPP_INLINE_VISIBILITY
574 explicit set(const value_compare& __comp, const allocator_type& __a)
575 : __tree_(__comp, __a) {}
576 template <class _InputIterator>
577 _LIBCPP_INLINE_VISIBILITY
578 set(_InputIterator __f, _InputIterator __l,
579 const value_compare& __comp = value_compare())
585 template <class _InputIterator>
586 _LIBCPP_INLINE_VISIBILITY
587 set(_InputIterator __f, _InputIterator __l, const value_compare& __comp,
588 const allocator_type& __a)
589 : __tree_(__comp, __a)
594 #if _LIBCPP_STD_VER > 11
595 template <class _InputIterator>
596 _LIBCPP_INLINE_VISIBILITY
597 set(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
598 : set(__f, __l, key_compare(), __a) {}
601 _LIBCPP_INLINE_VISIBILITY
603 : __tree_(__s.__tree_)
605 insert(__s.begin(), __s.end());
608 _LIBCPP_INLINE_VISIBILITY
609 set& operator=(const set& __s)
611 __tree_ = __s.__tree_;
615 #ifndef _LIBCPP_CXX03_LANG
616 _LIBCPP_INLINE_VISIBILITY
618 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
619 : __tree_(_VSTD::move(__s.__tree_)) {}
620 #endif // _LIBCPP_CXX03_LANG
622 _LIBCPP_INLINE_VISIBILITY
623 explicit set(const allocator_type& __a)
626 _LIBCPP_INLINE_VISIBILITY
627 set(const set& __s, const allocator_type& __a)
628 : __tree_(__s.__tree_.value_comp(), __a)
630 insert(__s.begin(), __s.end());
633 #ifndef _LIBCPP_CXX03_LANG
634 set(set&& __s, const allocator_type& __a);
636 _LIBCPP_INLINE_VISIBILITY
637 set(initializer_list<value_type> __il, const value_compare& __comp = value_compare())
640 insert(__il.begin(), __il.end());
643 _LIBCPP_INLINE_VISIBILITY
644 set(initializer_list<value_type> __il, const value_compare& __comp,
645 const allocator_type& __a)
646 : __tree_(__comp, __a)
648 insert(__il.begin(), __il.end());
651 #if _LIBCPP_STD_VER > 11
652 _LIBCPP_INLINE_VISIBILITY
653 set(initializer_list<value_type> __il, const allocator_type& __a)
654 : set(__il, key_compare(), __a) {}
657 _LIBCPP_INLINE_VISIBILITY
658 set& operator=(initializer_list<value_type> __il)
660 __tree_.__assign_unique(__il.begin(), __il.end());
664 _LIBCPP_INLINE_VISIBILITY
665 set& operator=(set&& __s)
666 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
668 __tree_ = _VSTD::move(__s.__tree_);
671 #endif // _LIBCPP_CXX03_LANG
673 _LIBCPP_INLINE_VISIBILITY
675 static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), "");
678 _LIBCPP_INLINE_VISIBILITY
679 iterator begin() _NOEXCEPT {return __tree_.begin();}
680 _LIBCPP_INLINE_VISIBILITY
681 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
682 _LIBCPP_INLINE_VISIBILITY
683 iterator end() _NOEXCEPT {return __tree_.end();}
684 _LIBCPP_INLINE_VISIBILITY
685 const_iterator end() const _NOEXCEPT {return __tree_.end();}
687 _LIBCPP_INLINE_VISIBILITY
688 reverse_iterator rbegin() _NOEXCEPT
689 {return reverse_iterator(end());}
690 _LIBCPP_INLINE_VISIBILITY
691 const_reverse_iterator rbegin() const _NOEXCEPT
692 {return const_reverse_iterator(end());}
693 _LIBCPP_INLINE_VISIBILITY
694 reverse_iterator rend() _NOEXCEPT
695 {return reverse_iterator(begin());}
696 _LIBCPP_INLINE_VISIBILITY
697 const_reverse_iterator rend() const _NOEXCEPT
698 {return const_reverse_iterator(begin());}
700 _LIBCPP_INLINE_VISIBILITY
701 const_iterator cbegin() const _NOEXCEPT {return begin();}
702 _LIBCPP_INLINE_VISIBILITY
703 const_iterator cend() const _NOEXCEPT {return end();}
704 _LIBCPP_INLINE_VISIBILITY
705 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
706 _LIBCPP_INLINE_VISIBILITY
707 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
709 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
710 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
711 _LIBCPP_INLINE_VISIBILITY
712 size_type size() const _NOEXCEPT {return __tree_.size();}
713 _LIBCPP_INLINE_VISIBILITY
714 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
717 #ifndef _LIBCPP_CXX03_LANG
718 template <class... _Args>
719 _LIBCPP_INLINE_VISIBILITY
720 pair<iterator, bool> emplace(_Args&&... __args)
721 {return __tree_.__emplace_unique(_VSTD::forward<_Args>(__args)...);}
722 template <class... _Args>
723 _LIBCPP_INLINE_VISIBILITY
724 iterator emplace_hint(const_iterator __p, _Args&&... __args)
725 {return __tree_.__emplace_hint_unique(__p, _VSTD::forward<_Args>(__args)...);}
726 #endif // _LIBCPP_CXX03_LANG
728 _LIBCPP_INLINE_VISIBILITY
729 pair<iterator,bool> insert(const value_type& __v)
730 {return __tree_.__insert_unique(__v);}
731 _LIBCPP_INLINE_VISIBILITY
732 iterator insert(const_iterator __p, const value_type& __v)
733 {return __tree_.__insert_unique(__p, __v);}
735 template <class _InputIterator>
736 _LIBCPP_INLINE_VISIBILITY
737 void insert(_InputIterator __f, _InputIterator __l)
739 for (const_iterator __e = cend(); __f != __l; ++__f)
740 __tree_.__insert_unique(__e, *__f);
743 #ifndef _LIBCPP_CXX03_LANG
744 _LIBCPP_INLINE_VISIBILITY
745 pair<iterator,bool> insert(value_type&& __v)
746 {return __tree_.__insert_unique(_VSTD::move(__v));}
748 _LIBCPP_INLINE_VISIBILITY
749 iterator insert(const_iterator __p, value_type&& __v)
750 {return __tree_.__insert_unique(__p, _VSTD::move(__v));}
752 _LIBCPP_INLINE_VISIBILITY
753 void insert(initializer_list<value_type> __il)
754 {insert(__il.begin(), __il.end());}
755 #endif // _LIBCPP_CXX03_LANG
757 _LIBCPP_INLINE_VISIBILITY
758 iterator erase(const_iterator __p) {return __tree_.erase(__p);}
759 _LIBCPP_INLINE_VISIBILITY
760 size_type erase(const key_type& __k)
761 {return __tree_.__erase_unique(__k);}
762 _LIBCPP_INLINE_VISIBILITY
763 iterator erase(const_iterator __f, const_iterator __l)
764 {return __tree_.erase(__f, __l);}
765 _LIBCPP_INLINE_VISIBILITY
766 void clear() _NOEXCEPT {__tree_.clear();}
768 #if _LIBCPP_STD_VER > 14
769 _LIBCPP_INLINE_VISIBILITY
770 insert_return_type insert(node_type&& __nh)
772 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
773 "node_type with incompatible allocator passed to set::insert()");
774 return __tree_.template __node_handle_insert_unique<
775 node_type, insert_return_type>(_VSTD::move(__nh));
777 _LIBCPP_INLINE_VISIBILITY
778 iterator insert(const_iterator __hint, node_type&& __nh)
780 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
781 "node_type with incompatible allocator passed to set::insert()");
782 return __tree_.template __node_handle_insert_unique<node_type>(
783 __hint, _VSTD::move(__nh));
785 _LIBCPP_INLINE_VISIBILITY
786 node_type extract(key_type const& __key)
788 return __tree_.template __node_handle_extract<node_type>(__key);
790 _LIBCPP_INLINE_VISIBILITY
791 node_type extract(const_iterator __it)
793 return __tree_.template __node_handle_extract<node_type>(__it);
795 template <class _Compare2>
796 _LIBCPP_INLINE_VISIBILITY
797 void merge(set<key_type, _Compare2, allocator_type>& __source)
799 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
800 "merging container with incompatible allocator");
801 __tree_.__node_handle_merge_unique(__source.__tree_);
803 template <class _Compare2>
804 _LIBCPP_INLINE_VISIBILITY
805 void merge(set<key_type, _Compare2, allocator_type>&& __source)
807 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
808 "merging container with incompatible allocator");
809 __tree_.__node_handle_merge_unique(__source.__tree_);
811 template <class _Compare2>
812 _LIBCPP_INLINE_VISIBILITY
813 void merge(multiset<key_type, _Compare2, allocator_type>& __source)
815 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
816 "merging container with incompatible allocator");
817 __tree_.__node_handle_merge_unique(__source.__tree_);
819 template <class _Compare2>
820 _LIBCPP_INLINE_VISIBILITY
821 void merge(multiset<key_type, _Compare2, allocator_type>&& __source)
823 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
824 "merging container with incompatible allocator");
825 __tree_.__node_handle_merge_unique(__source.__tree_);
829 _LIBCPP_INLINE_VISIBILITY
830 void swap(set& __s) _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
831 {__tree_.swap(__s.__tree_);}
833 _LIBCPP_INLINE_VISIBILITY
834 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
835 _LIBCPP_INLINE_VISIBILITY
836 key_compare key_comp() const {return __tree_.value_comp();}
837 _LIBCPP_INLINE_VISIBILITY
838 value_compare value_comp() const {return __tree_.value_comp();}
841 _LIBCPP_INLINE_VISIBILITY
842 iterator find(const key_type& __k) {return __tree_.find(__k);}
843 _LIBCPP_INLINE_VISIBILITY
844 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
845 #if _LIBCPP_STD_VER > 11
846 template <typename _K2>
847 _LIBCPP_INLINE_VISIBILITY
848 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
849 find(const _K2& __k) {return __tree_.find(__k);}
850 template <typename _K2>
851 _LIBCPP_INLINE_VISIBILITY
852 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
853 find(const _K2& __k) const {return __tree_.find(__k);}
856 _LIBCPP_INLINE_VISIBILITY
857 size_type count(const key_type& __k) const
858 {return __tree_.__count_unique(__k);}
859 #if _LIBCPP_STD_VER > 11
860 template <typename _K2>
861 _LIBCPP_INLINE_VISIBILITY
862 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
863 count(const _K2& __k) const {return __tree_.__count_multi(__k);}
866 #if _LIBCPP_STD_VER > 17
867 _LIBCPP_INLINE_VISIBILITY
868 bool contains(const key_type& __k) const {return find(__k) != end();}
869 template <typename _K2>
870 _LIBCPP_INLINE_VISIBILITY
871 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
872 contains(const _K2& __k) const { return find(__k) != end(); }
873 #endif // _LIBCPP_STD_VER > 17
875 _LIBCPP_INLINE_VISIBILITY
876 iterator lower_bound(const key_type& __k)
877 {return __tree_.lower_bound(__k);}
878 _LIBCPP_INLINE_VISIBILITY
879 const_iterator lower_bound(const key_type& __k) const
880 {return __tree_.lower_bound(__k);}
881 #if _LIBCPP_STD_VER > 11
882 template <typename _K2>
883 _LIBCPP_INLINE_VISIBILITY
884 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
885 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
887 template <typename _K2>
888 _LIBCPP_INLINE_VISIBILITY
889 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
890 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
893 _LIBCPP_INLINE_VISIBILITY
894 iterator upper_bound(const key_type& __k)
895 {return __tree_.upper_bound(__k);}
896 _LIBCPP_INLINE_VISIBILITY
897 const_iterator upper_bound(const key_type& __k) const
898 {return __tree_.upper_bound(__k);}
899 #if _LIBCPP_STD_VER > 11
900 template <typename _K2>
901 _LIBCPP_INLINE_VISIBILITY
902 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
903 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
904 template <typename _K2>
905 _LIBCPP_INLINE_VISIBILITY
906 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
907 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
910 _LIBCPP_INLINE_VISIBILITY
911 pair<iterator,iterator> equal_range(const key_type& __k)
912 {return __tree_.__equal_range_unique(__k);}
913 _LIBCPP_INLINE_VISIBILITY
914 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
915 {return __tree_.__equal_range_unique(__k);}
916 #if _LIBCPP_STD_VER > 11
917 template <typename _K2>
918 _LIBCPP_INLINE_VISIBILITY
919 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
920 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
921 template <typename _K2>
922 _LIBCPP_INLINE_VISIBILITY
923 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
924 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
928 #if _LIBCPP_STD_VER >= 17
929 template<class _InputIterator,
930 class _Compare = less<__iter_value_type<_InputIterator>>,
931 class _Allocator = allocator<__iter_value_type<_InputIterator>>,
932 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value, void>,
933 class = enable_if_t<__is_allocator<_Allocator>::value, void>,
934 class = enable_if_t<!__is_allocator<_Compare>::value, void>>
935 set(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
936 -> set<__iter_value_type<_InputIterator>, _Compare, _Allocator>;
938 template<class _Key, class _Compare = less<_Key>,
939 class _Allocator = allocator<_Key>,
940 class = enable_if_t<!__is_allocator<_Compare>::value, void>,
941 class = enable_if_t<__is_allocator<_Allocator>::value, void>>
942 set(initializer_list<_Key>, _Compare = _Compare(), _Allocator = _Allocator())
943 -> set<_Key, _Compare, _Allocator>;
945 template<class _InputIterator, class _Allocator,
946 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value, void>,
947 class = enable_if_t<__is_allocator<_Allocator>::value, void>>
948 set(_InputIterator, _InputIterator, _Allocator)
949 -> set<__iter_value_type<_InputIterator>,
950 less<__iter_value_type<_InputIterator>>, _Allocator>;
952 template<class _Key, class _Allocator,
953 class = enable_if_t<__is_allocator<_Allocator>::value, void>>
954 set(initializer_list<_Key>, _Allocator)
955 -> set<_Key, less<_Key>, _Allocator>;
958 #ifndef _LIBCPP_CXX03_LANG
960 template <class _Key, class _Compare, class _Allocator>
961 set<_Key, _Compare, _Allocator>::set(set&& __s, const allocator_type& __a)
962 : __tree_(_VSTD::move(__s.__tree_), __a)
964 if (__a != __s.get_allocator())
966 const_iterator __e = cend();
968 insert(__e, _VSTD::move(__s.__tree_.remove(__s.begin())->__value_));
972 #endif // _LIBCPP_CXX03_LANG
974 template <class _Key, class _Compare, class _Allocator>
975 inline _LIBCPP_INLINE_VISIBILITY
977 operator==(const set<_Key, _Compare, _Allocator>& __x,
978 const set<_Key, _Compare, _Allocator>& __y)
980 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
983 template <class _Key, class _Compare, class _Allocator>
984 inline _LIBCPP_INLINE_VISIBILITY
986 operator< (const set<_Key, _Compare, _Allocator>& __x,
987 const set<_Key, _Compare, _Allocator>& __y)
989 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
992 template <class _Key, class _Compare, class _Allocator>
993 inline _LIBCPP_INLINE_VISIBILITY
995 operator!=(const set<_Key, _Compare, _Allocator>& __x,
996 const set<_Key, _Compare, _Allocator>& __y)
998 return !(__x == __y);
1001 template <class _Key, class _Compare, class _Allocator>
1002 inline _LIBCPP_INLINE_VISIBILITY
1004 operator> (const set<_Key, _Compare, _Allocator>& __x,
1005 const set<_Key, _Compare, _Allocator>& __y)
1010 template <class _Key, class _Compare, class _Allocator>
1011 inline _LIBCPP_INLINE_VISIBILITY
1013 operator>=(const set<_Key, _Compare, _Allocator>& __x,
1014 const set<_Key, _Compare, _Allocator>& __y)
1016 return !(__x < __y);
1019 template <class _Key, class _Compare, class _Allocator>
1020 inline _LIBCPP_INLINE_VISIBILITY
1022 operator<=(const set<_Key, _Compare, _Allocator>& __x,
1023 const set<_Key, _Compare, _Allocator>& __y)
1025 return !(__y < __x);
1028 // specialized algorithms:
1029 template <class _Key, class _Compare, class _Allocator>
1030 inline _LIBCPP_INLINE_VISIBILITY
1032 swap(set<_Key, _Compare, _Allocator>& __x,
1033 set<_Key, _Compare, _Allocator>& __y)
1034 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
1039 #if _LIBCPP_STD_VER > 17
1040 template <class _Key, class _Compare, class _Allocator, class _Predicate>
1041 inline _LIBCPP_INLINE_VISIBILITY
1042 typename set<_Key, _Compare, _Allocator>::size_type
1043 erase_if(set<_Key, _Compare, _Allocator>& __c, _Predicate __pred) {
1044 return _VSTD::__libcpp_erase_if_container(__c, __pred);
1048 template <class _Key, class _Compare = less<_Key>,
1049 class _Allocator = allocator<_Key> >
1050 class _LIBCPP_TEMPLATE_VIS multiset
1054 typedef _Key key_type;
1055 typedef key_type value_type;
1056 typedef __type_identity_t<_Compare> key_compare;
1057 typedef key_compare value_compare;
1058 typedef __type_identity_t<_Allocator> allocator_type;
1059 typedef value_type& reference;
1060 typedef const value_type& const_reference;
1062 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
1063 "Allocator::value_type must be same type as value_type");
1066 typedef __tree<value_type, value_compare, allocator_type> __base;
1067 typedef allocator_traits<allocator_type> __alloc_traits;
1072 typedef typename __base::pointer pointer;
1073 typedef typename __base::const_pointer const_pointer;
1074 typedef typename __base::size_type size_type;
1075 typedef typename __base::difference_type difference_type;
1076 typedef typename __base::const_iterator iterator;
1077 typedef typename __base::const_iterator const_iterator;
1078 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1079 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
1081 #if _LIBCPP_STD_VER > 14
1082 typedef __set_node_handle<typename __base::__node, allocator_type> node_type;
1085 template <class _Key2, class _Compare2, class _Alloc2>
1086 friend class _LIBCPP_TEMPLATE_VIS set;
1087 template <class _Key2, class _Compare2, class _Alloc2>
1088 friend class _LIBCPP_TEMPLATE_VIS multiset;
1090 // construct/copy/destroy:
1091 _LIBCPP_INLINE_VISIBILITY
1094 is_nothrow_default_constructible<allocator_type>::value &&
1095 is_nothrow_default_constructible<key_compare>::value &&
1096 is_nothrow_copy_constructible<key_compare>::value)
1097 : __tree_(value_compare()) {}
1099 _LIBCPP_INLINE_VISIBILITY
1100 explicit multiset(const value_compare& __comp)
1102 is_nothrow_default_constructible<allocator_type>::value &&
1103 is_nothrow_copy_constructible<key_compare>::value)
1104 : __tree_(__comp) {}
1106 _LIBCPP_INLINE_VISIBILITY
1107 explicit multiset(const value_compare& __comp, const allocator_type& __a)
1108 : __tree_(__comp, __a) {}
1109 template <class _InputIterator>
1110 _LIBCPP_INLINE_VISIBILITY
1111 multiset(_InputIterator __f, _InputIterator __l,
1112 const value_compare& __comp = value_compare())
1118 #if _LIBCPP_STD_VER > 11
1119 template <class _InputIterator>
1120 _LIBCPP_INLINE_VISIBILITY
1121 multiset(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
1122 : multiset(__f, __l, key_compare(), __a) {}
1125 template <class _InputIterator>
1126 _LIBCPP_INLINE_VISIBILITY
1127 multiset(_InputIterator __f, _InputIterator __l,
1128 const value_compare& __comp, const allocator_type& __a)
1129 : __tree_(__comp, __a)
1134 _LIBCPP_INLINE_VISIBILITY
1135 multiset(const multiset& __s)
1136 : __tree_(__s.__tree_.value_comp(),
1137 __alloc_traits::select_on_container_copy_construction(__s.__tree_.__alloc()))
1139 insert(__s.begin(), __s.end());
1142 _LIBCPP_INLINE_VISIBILITY
1143 multiset& operator=(const multiset& __s)
1145 __tree_ = __s.__tree_;
1149 #ifndef _LIBCPP_CXX03_LANG
1150 _LIBCPP_INLINE_VISIBILITY
1151 multiset(multiset&& __s)
1152 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
1153 : __tree_(_VSTD::move(__s.__tree_)) {}
1155 multiset(multiset&& __s, const allocator_type& __a);
1156 #endif // _LIBCPP_CXX03_LANG
1157 _LIBCPP_INLINE_VISIBILITY
1158 explicit multiset(const allocator_type& __a)
1160 _LIBCPP_INLINE_VISIBILITY
1161 multiset(const multiset& __s, const allocator_type& __a)
1162 : __tree_(__s.__tree_.value_comp(), __a)
1164 insert(__s.begin(), __s.end());
1167 #ifndef _LIBCPP_CXX03_LANG
1168 _LIBCPP_INLINE_VISIBILITY
1169 multiset(initializer_list<value_type> __il, const value_compare& __comp = value_compare())
1172 insert(__il.begin(), __il.end());
1175 _LIBCPP_INLINE_VISIBILITY
1176 multiset(initializer_list<value_type> __il, const value_compare& __comp,
1177 const allocator_type& __a)
1178 : __tree_(__comp, __a)
1180 insert(__il.begin(), __il.end());
1183 #if _LIBCPP_STD_VER > 11
1184 _LIBCPP_INLINE_VISIBILITY
1185 multiset(initializer_list<value_type> __il, const allocator_type& __a)
1186 : multiset(__il, key_compare(), __a) {}
1189 _LIBCPP_INLINE_VISIBILITY
1190 multiset& operator=(initializer_list<value_type> __il)
1192 __tree_.__assign_multi(__il.begin(), __il.end());
1196 _LIBCPP_INLINE_VISIBILITY
1197 multiset& operator=(multiset&& __s)
1198 _NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
1200 __tree_ = _VSTD::move(__s.__tree_);
1203 #endif // _LIBCPP_CXX03_LANG
1205 _LIBCPP_INLINE_VISIBILITY
1207 static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), "");
1210 _LIBCPP_INLINE_VISIBILITY
1211 iterator begin() _NOEXCEPT {return __tree_.begin();}
1212 _LIBCPP_INLINE_VISIBILITY
1213 const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
1214 _LIBCPP_INLINE_VISIBILITY
1215 iterator end() _NOEXCEPT {return __tree_.end();}
1216 _LIBCPP_INLINE_VISIBILITY
1217 const_iterator end() const _NOEXCEPT {return __tree_.end();}
1219 _LIBCPP_INLINE_VISIBILITY
1220 reverse_iterator rbegin() _NOEXCEPT
1221 {return reverse_iterator(end());}
1222 _LIBCPP_INLINE_VISIBILITY
1223 const_reverse_iterator rbegin() const _NOEXCEPT
1224 {return const_reverse_iterator(end());}
1225 _LIBCPP_INLINE_VISIBILITY
1226 reverse_iterator rend() _NOEXCEPT
1227 {return reverse_iterator(begin());}
1228 _LIBCPP_INLINE_VISIBILITY
1229 const_reverse_iterator rend() const _NOEXCEPT
1230 {return const_reverse_iterator(begin());}
1232 _LIBCPP_INLINE_VISIBILITY
1233 const_iterator cbegin() const _NOEXCEPT {return begin();}
1234 _LIBCPP_INLINE_VISIBILITY
1235 const_iterator cend() const _NOEXCEPT {return end();}
1236 _LIBCPP_INLINE_VISIBILITY
1237 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
1238 _LIBCPP_INLINE_VISIBILITY
1239 const_reverse_iterator crend() const _NOEXCEPT {return rend();}
1241 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
1242 bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
1243 _LIBCPP_INLINE_VISIBILITY
1244 size_type size() const _NOEXCEPT {return __tree_.size();}
1245 _LIBCPP_INLINE_VISIBILITY
1246 size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
1249 #ifndef _LIBCPP_CXX03_LANG
1250 template <class... _Args>
1251 _LIBCPP_INLINE_VISIBILITY
1252 iterator emplace(_Args&&... __args)
1253 {return __tree_.__emplace_multi(_VSTD::forward<_Args>(__args)...);}
1254 template <class... _Args>
1255 _LIBCPP_INLINE_VISIBILITY
1256 iterator emplace_hint(const_iterator __p, _Args&&... __args)
1257 {return __tree_.__emplace_hint_multi(__p, _VSTD::forward<_Args>(__args)...);}
1258 #endif // _LIBCPP_CXX03_LANG
1260 _LIBCPP_INLINE_VISIBILITY
1261 iterator insert(const value_type& __v)
1262 {return __tree_.__insert_multi(__v);}
1263 _LIBCPP_INLINE_VISIBILITY
1264 iterator insert(const_iterator __p, const value_type& __v)
1265 {return __tree_.__insert_multi(__p, __v);}
1267 template <class _InputIterator>
1268 _LIBCPP_INLINE_VISIBILITY
1269 void insert(_InputIterator __f, _InputIterator __l)
1271 for (const_iterator __e = cend(); __f != __l; ++__f)
1272 __tree_.__insert_multi(__e, *__f);
1275 #ifndef _LIBCPP_CXX03_LANG
1276 _LIBCPP_INLINE_VISIBILITY
1277 iterator insert(value_type&& __v)
1278 {return __tree_.__insert_multi(_VSTD::move(__v));}
1280 _LIBCPP_INLINE_VISIBILITY
1281 iterator insert(const_iterator __p, value_type&& __v)
1282 {return __tree_.__insert_multi(__p, _VSTD::move(__v));}
1284 _LIBCPP_INLINE_VISIBILITY
1285 void insert(initializer_list<value_type> __il)
1286 {insert(__il.begin(), __il.end());}
1287 #endif // _LIBCPP_CXX03_LANG
1289 _LIBCPP_INLINE_VISIBILITY
1290 iterator erase(const_iterator __p) {return __tree_.erase(__p);}
1291 _LIBCPP_INLINE_VISIBILITY
1292 size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);}
1293 _LIBCPP_INLINE_VISIBILITY
1294 iterator erase(const_iterator __f, const_iterator __l)
1295 {return __tree_.erase(__f, __l);}
1296 _LIBCPP_INLINE_VISIBILITY
1297 void clear() _NOEXCEPT {__tree_.clear();}
1299 #if _LIBCPP_STD_VER > 14
1300 _LIBCPP_INLINE_VISIBILITY
1301 iterator insert(node_type&& __nh)
1303 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1304 "node_type with incompatible allocator passed to multiset::insert()");
1305 return __tree_.template __node_handle_insert_multi<node_type>(
1308 _LIBCPP_INLINE_VISIBILITY
1309 iterator insert(const_iterator __hint, node_type&& __nh)
1311 _LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
1312 "node_type with incompatible allocator passed to multiset::insert()");
1313 return __tree_.template __node_handle_insert_multi<node_type>(
1314 __hint, _VSTD::move(__nh));
1316 _LIBCPP_INLINE_VISIBILITY
1317 node_type extract(key_type const& __key)
1319 return __tree_.template __node_handle_extract<node_type>(__key);
1321 _LIBCPP_INLINE_VISIBILITY
1322 node_type extract(const_iterator __it)
1324 return __tree_.template __node_handle_extract<node_type>(__it);
1326 template <class _Compare2>
1327 _LIBCPP_INLINE_VISIBILITY
1328 void merge(multiset<key_type, _Compare2, allocator_type>& __source)
1330 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1331 "merging container with incompatible allocator");
1332 __tree_.__node_handle_merge_multi(__source.__tree_);
1334 template <class _Compare2>
1335 _LIBCPP_INLINE_VISIBILITY
1336 void merge(multiset<key_type, _Compare2, allocator_type>&& __source)
1338 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1339 "merging container with incompatible allocator");
1340 __tree_.__node_handle_merge_multi(__source.__tree_);
1342 template <class _Compare2>
1343 _LIBCPP_INLINE_VISIBILITY
1344 void merge(set<key_type, _Compare2, allocator_type>& __source)
1346 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1347 "merging container with incompatible allocator");
1348 __tree_.__node_handle_merge_multi(__source.__tree_);
1350 template <class _Compare2>
1351 _LIBCPP_INLINE_VISIBILITY
1352 void merge(set<key_type, _Compare2, allocator_type>&& __source)
1354 _LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
1355 "merging container with incompatible allocator");
1356 __tree_.__node_handle_merge_multi(__source.__tree_);
1360 _LIBCPP_INLINE_VISIBILITY
1361 void swap(multiset& __s)
1362 _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
1363 {__tree_.swap(__s.__tree_);}
1365 _LIBCPP_INLINE_VISIBILITY
1366 allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
1367 _LIBCPP_INLINE_VISIBILITY
1368 key_compare key_comp() const {return __tree_.value_comp();}
1369 _LIBCPP_INLINE_VISIBILITY
1370 value_compare value_comp() const {return __tree_.value_comp();}
1373 _LIBCPP_INLINE_VISIBILITY
1374 iterator find(const key_type& __k) {return __tree_.find(__k);}
1375 _LIBCPP_INLINE_VISIBILITY
1376 const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
1377 #if _LIBCPP_STD_VER > 11
1378 template <typename _K2>
1379 _LIBCPP_INLINE_VISIBILITY
1380 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1381 find(const _K2& __k) {return __tree_.find(__k);}
1382 template <typename _K2>
1383 _LIBCPP_INLINE_VISIBILITY
1384 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1385 find(const _K2& __k) const {return __tree_.find(__k);}
1388 _LIBCPP_INLINE_VISIBILITY
1389 size_type count(const key_type& __k) const
1390 {return __tree_.__count_multi(__k);}
1391 #if _LIBCPP_STD_VER > 11
1392 template <typename _K2>
1393 _LIBCPP_INLINE_VISIBILITY
1394 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
1395 count(const _K2& __k) const {return __tree_.__count_multi(__k);}
1398 #if _LIBCPP_STD_VER > 17
1399 _LIBCPP_INLINE_VISIBILITY
1400 bool contains(const key_type& __k) const {return find(__k) != end();}
1401 template <typename _K2>
1402 _LIBCPP_INLINE_VISIBILITY
1403 typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
1404 contains(const _K2& __k) const { return find(__k) != end(); }
1405 #endif // _LIBCPP_STD_VER > 17
1407 _LIBCPP_INLINE_VISIBILITY
1408 iterator lower_bound(const key_type& __k)
1409 {return __tree_.lower_bound(__k);}
1410 _LIBCPP_INLINE_VISIBILITY
1411 const_iterator lower_bound(const key_type& __k) const
1412 {return __tree_.lower_bound(__k);}
1413 #if _LIBCPP_STD_VER > 11
1414 template <typename _K2>
1415 _LIBCPP_INLINE_VISIBILITY
1416 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1417 lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
1419 template <typename _K2>
1420 _LIBCPP_INLINE_VISIBILITY
1421 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1422 lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
1425 _LIBCPP_INLINE_VISIBILITY
1426 iterator upper_bound(const key_type& __k)
1427 {return __tree_.upper_bound(__k);}
1428 _LIBCPP_INLINE_VISIBILITY
1429 const_iterator upper_bound(const key_type& __k) const
1430 {return __tree_.upper_bound(__k);}
1431 #if _LIBCPP_STD_VER > 11
1432 template <typename _K2>
1433 _LIBCPP_INLINE_VISIBILITY
1434 typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
1435 upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
1436 template <typename _K2>
1437 _LIBCPP_INLINE_VISIBILITY
1438 typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
1439 upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
1442 _LIBCPP_INLINE_VISIBILITY
1443 pair<iterator,iterator> equal_range(const key_type& __k)
1444 {return __tree_.__equal_range_multi(__k);}
1445 _LIBCPP_INLINE_VISIBILITY
1446 pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
1447 {return __tree_.__equal_range_multi(__k);}
1448 #if _LIBCPP_STD_VER > 11
1449 template <typename _K2>
1450 _LIBCPP_INLINE_VISIBILITY
1451 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
1452 equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
1453 template <typename _K2>
1454 _LIBCPP_INLINE_VISIBILITY
1455 typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
1456 equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
1460 #if _LIBCPP_STD_VER >= 17
1461 template<class _InputIterator,
1462 class _Compare = less<__iter_value_type<_InputIterator>>,
1463 class _Allocator = allocator<__iter_value_type<_InputIterator>>,
1464 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value, void>,
1465 class = enable_if_t<__is_allocator<_Allocator>::value, void>,
1466 class = enable_if_t<!__is_allocator<_Compare>::value, void>>
1467 multiset(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
1468 -> multiset<__iter_value_type<_InputIterator>, _Compare, _Allocator>;
1470 template<class _Key, class _Compare = less<_Key>,
1471 class _Allocator = allocator<_Key>,
1472 class = enable_if_t<__is_allocator<_Allocator>::value, void>,
1473 class = enable_if_t<!__is_allocator<_Compare>::value, void>>
1474 multiset(initializer_list<_Key>, _Compare = _Compare(), _Allocator = _Allocator())
1475 -> multiset<_Key, _Compare, _Allocator>;
1477 template<class _InputIterator, class _Allocator,
1478 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value, void>,
1479 class = enable_if_t<__is_allocator<_Allocator>::value, void>>
1480 multiset(_InputIterator, _InputIterator, _Allocator)
1481 -> multiset<__iter_value_type<_InputIterator>,
1482 less<__iter_value_type<_InputIterator>>, _Allocator>;
1484 template<class _Key, class _Allocator,
1485 class = enable_if_t<__is_allocator<_Allocator>::value, void>>
1486 multiset(initializer_list<_Key>, _Allocator)
1487 -> multiset<_Key, less<_Key>, _Allocator>;
1490 #ifndef _LIBCPP_CXX03_LANG
1492 template <class _Key, class _Compare, class _Allocator>
1493 multiset<_Key, _Compare, _Allocator>::multiset(multiset&& __s, const allocator_type& __a)
1494 : __tree_(_VSTD::move(__s.__tree_), __a)
1496 if (__a != __s.get_allocator())
1498 const_iterator __e = cend();
1499 while (!__s.empty())
1500 insert(__e, _VSTD::move(__s.__tree_.remove(__s.begin())->__value_));
1504 #endif // _LIBCPP_CXX03_LANG
1506 template <class _Key, class _Compare, class _Allocator>
1507 inline _LIBCPP_INLINE_VISIBILITY
1509 operator==(const multiset<_Key, _Compare, _Allocator>& __x,
1510 const multiset<_Key, _Compare, _Allocator>& __y)
1512 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
1515 template <class _Key, class _Compare, class _Allocator>
1516 inline _LIBCPP_INLINE_VISIBILITY
1518 operator< (const multiset<_Key, _Compare, _Allocator>& __x,
1519 const multiset<_Key, _Compare, _Allocator>& __y)
1521 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
1524 template <class _Key, class _Compare, class _Allocator>
1525 inline _LIBCPP_INLINE_VISIBILITY
1527 operator!=(const multiset<_Key, _Compare, _Allocator>& __x,
1528 const multiset<_Key, _Compare, _Allocator>& __y)
1530 return !(__x == __y);
1533 template <class _Key, class _Compare, class _Allocator>
1534 inline _LIBCPP_INLINE_VISIBILITY
1536 operator> (const multiset<_Key, _Compare, _Allocator>& __x,
1537 const multiset<_Key, _Compare, _Allocator>& __y)
1542 template <class _Key, class _Compare, class _Allocator>
1543 inline _LIBCPP_INLINE_VISIBILITY
1545 operator>=(const multiset<_Key, _Compare, _Allocator>& __x,
1546 const multiset<_Key, _Compare, _Allocator>& __y)
1548 return !(__x < __y);
1551 template <class _Key, class _Compare, class _Allocator>
1552 inline _LIBCPP_INLINE_VISIBILITY
1554 operator<=(const multiset<_Key, _Compare, _Allocator>& __x,
1555 const multiset<_Key, _Compare, _Allocator>& __y)
1557 return !(__y < __x);
1560 template <class _Key, class _Compare, class _Allocator>
1561 inline _LIBCPP_INLINE_VISIBILITY
1563 swap(multiset<_Key, _Compare, _Allocator>& __x,
1564 multiset<_Key, _Compare, _Allocator>& __y)
1565 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
1570 #if _LIBCPP_STD_VER > 17
1571 template <class _Key, class _Compare, class _Allocator, class _Predicate>
1572 inline _LIBCPP_INLINE_VISIBILITY
1573 typename multiset<_Key, _Compare, _Allocator>::size_type
1574 erase_if(multiset<_Key, _Compare, _Allocator>& __c, _Predicate __pred) {
1575 return _VSTD::__libcpp_erase_if_container(__c, __pred);
1579 _LIBCPP_END_NAMESPACE_STD
1581 #endif // _LIBCPP_SET