1*38fd1498Szrj // Multiset implementation -*- C++ -*-
2*38fd1498Szrj
3*38fd1498Szrj // Copyright (C) 2001-2018 Free Software Foundation, Inc.
4*38fd1498Szrj //
5*38fd1498Szrj // This file is part of the GNU ISO C++ Library. This library is free
6*38fd1498Szrj // software; you can redistribute it and/or modify it under the
7*38fd1498Szrj // terms of the GNU General Public License as published by the
8*38fd1498Szrj // Free Software Foundation; either version 3, or (at your option)
9*38fd1498Szrj // any later version.
10*38fd1498Szrj
11*38fd1498Szrj // This library is distributed in the hope that it will be useful,
12*38fd1498Szrj // but WITHOUT ANY WARRANTY; without even the implied warranty of
13*38fd1498Szrj // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14*38fd1498Szrj // GNU General Public License for more details.
15*38fd1498Szrj
16*38fd1498Szrj // Under Section 7 of GPL version 3, you are granted additional
17*38fd1498Szrj // permissions described in the GCC Runtime Library Exception, version
18*38fd1498Szrj // 3.1, as published by the Free Software Foundation.
19*38fd1498Szrj
20*38fd1498Szrj // You should have received a copy of the GNU General Public License and
21*38fd1498Szrj // a copy of the GCC Runtime Library Exception along with this program;
22*38fd1498Szrj // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23*38fd1498Szrj // <http://www.gnu.org/licenses/>.
24*38fd1498Szrj
25*38fd1498Szrj /*
26*38fd1498Szrj *
27*38fd1498Szrj * Copyright (c) 1994
28*38fd1498Szrj * Hewlett-Packard Company
29*38fd1498Szrj *
30*38fd1498Szrj * Permission to use, copy, modify, distribute and sell this software
31*38fd1498Szrj * and its documentation for any purpose is hereby granted without fee,
32*38fd1498Szrj * provided that the above copyright notice appear in all copies and
33*38fd1498Szrj * that both that copyright notice and this permission notice appear
34*38fd1498Szrj * in supporting documentation. Hewlett-Packard Company makes no
35*38fd1498Szrj * representations about the suitability of this software for any
36*38fd1498Szrj * purpose. It is provided "as is" without express or implied warranty.
37*38fd1498Szrj *
38*38fd1498Szrj *
39*38fd1498Szrj * Copyright (c) 1996
40*38fd1498Szrj * Silicon Graphics Computer Systems, Inc.
41*38fd1498Szrj *
42*38fd1498Szrj * Permission to use, copy, modify, distribute and sell this software
43*38fd1498Szrj * and its documentation for any purpose is hereby granted without fee,
44*38fd1498Szrj * provided that the above copyright notice appear in all copies and
45*38fd1498Szrj * that both that copyright notice and this permission notice appear
46*38fd1498Szrj * in supporting documentation. Silicon Graphics makes no
47*38fd1498Szrj * representations about the suitability of this software for any
48*38fd1498Szrj * purpose. It is provided "as is" without express or implied warranty.
49*38fd1498Szrj */
50*38fd1498Szrj
51*38fd1498Szrj /** @file bits/stl_multiset.h
52*38fd1498Szrj * This is an internal header file, included by other library headers.
53*38fd1498Szrj * Do not attempt to use it directly. @headername{set}
54*38fd1498Szrj */
55*38fd1498Szrj
56*38fd1498Szrj #ifndef _STL_MULTISET_H
57*38fd1498Szrj #define _STL_MULTISET_H 1
58*38fd1498Szrj
59*38fd1498Szrj #include <bits/concept_check.h>
60*38fd1498Szrj #if __cplusplus >= 201103L
61*38fd1498Szrj #include <initializer_list>
62*38fd1498Szrj #endif
63*38fd1498Szrj
_GLIBCXX_VISIBILITY(default)64*38fd1498Szrj namespace std _GLIBCXX_VISIBILITY(default)
65*38fd1498Szrj {
66*38fd1498Szrj _GLIBCXX_BEGIN_NAMESPACE_VERSION
67*38fd1498Szrj _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
68*38fd1498Szrj
69*38fd1498Szrj template<typename _Key, typename _Compare, typename _Alloc>
70*38fd1498Szrj class set;
71*38fd1498Szrj
72*38fd1498Szrj /**
73*38fd1498Szrj * @brief A standard container made up of elements, which can be retrieved
74*38fd1498Szrj * in logarithmic time.
75*38fd1498Szrj *
76*38fd1498Szrj * @ingroup associative_containers
77*38fd1498Szrj *
78*38fd1498Szrj *
79*38fd1498Szrj * @tparam _Key Type of key objects.
80*38fd1498Szrj * @tparam _Compare Comparison function object type, defaults to less<_Key>.
81*38fd1498Szrj * @tparam _Alloc Allocator type, defaults to allocator<_Key>.
82*38fd1498Szrj *
83*38fd1498Szrj * Meets the requirements of a <a href="tables.html#65">container</a>, a
84*38fd1498Szrj * <a href="tables.html#66">reversible container</a>, and an
85*38fd1498Szrj * <a href="tables.html#69">associative container</a> (using equivalent
86*38fd1498Szrj * keys). For a @c multiset<Key> the key_type and value_type are Key.
87*38fd1498Szrj *
88*38fd1498Szrj * Multisets support bidirectional iterators.
89*38fd1498Szrj *
90*38fd1498Szrj * The private tree data is declared exactly the same way for set and
91*38fd1498Szrj * multiset; the distinction is made entirely in how the tree functions are
92*38fd1498Szrj * called (*_unique versus *_equal, same as the standard).
93*38fd1498Szrj */
94*38fd1498Szrj template <typename _Key, typename _Compare = std::less<_Key>,
95*38fd1498Szrj typename _Alloc = std::allocator<_Key> >
96*38fd1498Szrj class multiset
97*38fd1498Szrj {
98*38fd1498Szrj #ifdef _GLIBCXX_CONCEPT_CHECKS
99*38fd1498Szrj // concept requirements
100*38fd1498Szrj typedef typename _Alloc::value_type _Alloc_value_type;
101*38fd1498Szrj # if __cplusplus < 201103L
102*38fd1498Szrj __glibcxx_class_requires(_Key, _SGIAssignableConcept)
103*38fd1498Szrj # endif
104*38fd1498Szrj __glibcxx_class_requires4(_Compare, bool, _Key, _Key,
105*38fd1498Szrj _BinaryFunctionConcept)
106*38fd1498Szrj __glibcxx_class_requires2(_Key, _Alloc_value_type, _SameTypeConcept)
107*38fd1498Szrj #endif
108*38fd1498Szrj
109*38fd1498Szrj #if __cplusplus >= 201103L
110*38fd1498Szrj static_assert(is_same<typename remove_cv<_Key>::type, _Key>::value,
111*38fd1498Szrj "std::multiset must have a non-const, non-volatile value_type");
112*38fd1498Szrj # ifdef __STRICT_ANSI__
113*38fd1498Szrj static_assert(is_same<typename _Alloc::value_type, _Key>::value,
114*38fd1498Szrj "std::multiset must have the same value_type as its allocator");
115*38fd1498Szrj # endif
116*38fd1498Szrj #endif
117*38fd1498Szrj
118*38fd1498Szrj public:
119*38fd1498Szrj // typedefs:
120*38fd1498Szrj typedef _Key key_type;
121*38fd1498Szrj typedef _Key value_type;
122*38fd1498Szrj typedef _Compare key_compare;
123*38fd1498Szrj typedef _Compare value_compare;
124*38fd1498Szrj typedef _Alloc allocator_type;
125*38fd1498Szrj
126*38fd1498Szrj private:
127*38fd1498Szrj /// This turns a red-black tree into a [multi]set.
128*38fd1498Szrj typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template
129*38fd1498Szrj rebind<_Key>::other _Key_alloc_type;
130*38fd1498Szrj
131*38fd1498Szrj typedef _Rb_tree<key_type, value_type, _Identity<value_type>,
132*38fd1498Szrj key_compare, _Key_alloc_type> _Rep_type;
133*38fd1498Szrj /// The actual tree structure.
134*38fd1498Szrj _Rep_type _M_t;
135*38fd1498Szrj
136*38fd1498Szrj typedef __gnu_cxx::__alloc_traits<_Key_alloc_type> _Alloc_traits;
137*38fd1498Szrj
138*38fd1498Szrj public:
139*38fd1498Szrj typedef typename _Alloc_traits::pointer pointer;
140*38fd1498Szrj typedef typename _Alloc_traits::const_pointer const_pointer;
141*38fd1498Szrj typedef typename _Alloc_traits::reference reference;
142*38fd1498Szrj typedef typename _Alloc_traits::const_reference const_reference;
143*38fd1498Szrj // _GLIBCXX_RESOLVE_LIB_DEFECTS
144*38fd1498Szrj // DR 103. set::iterator is required to be modifiable,
145*38fd1498Szrj // but this allows modification of keys.
146*38fd1498Szrj typedef typename _Rep_type::const_iterator iterator;
147*38fd1498Szrj typedef typename _Rep_type::const_iterator const_iterator;
148*38fd1498Szrj typedef typename _Rep_type::const_reverse_iterator reverse_iterator;
149*38fd1498Szrj typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
150*38fd1498Szrj typedef typename _Rep_type::size_type size_type;
151*38fd1498Szrj typedef typename _Rep_type::difference_type difference_type;
152*38fd1498Szrj
153*38fd1498Szrj #if __cplusplus > 201402L
154*38fd1498Szrj using node_type = typename _Rep_type::node_type;
155*38fd1498Szrj #endif
156*38fd1498Szrj
157*38fd1498Szrj // allocation/deallocation
158*38fd1498Szrj /**
159*38fd1498Szrj * @brief Default constructor creates no elements.
160*38fd1498Szrj */
161*38fd1498Szrj #if __cplusplus < 201103L
162*38fd1498Szrj multiset() : _M_t() { }
163*38fd1498Szrj #else
164*38fd1498Szrj multiset() = default;
165*38fd1498Szrj #endif
166*38fd1498Szrj
167*38fd1498Szrj /**
168*38fd1498Szrj * @brief Creates a %multiset with no elements.
169*38fd1498Szrj * @param __comp Comparator to use.
170*38fd1498Szrj * @param __a An allocator object.
171*38fd1498Szrj */
172*38fd1498Szrj explicit
173*38fd1498Szrj multiset(const _Compare& __comp,
174*38fd1498Szrj const allocator_type& __a = allocator_type())
175*38fd1498Szrj : _M_t(__comp, _Key_alloc_type(__a)) { }
176*38fd1498Szrj
177*38fd1498Szrj /**
178*38fd1498Szrj * @brief Builds a %multiset from a range.
179*38fd1498Szrj * @param __first An input iterator.
180*38fd1498Szrj * @param __last An input iterator.
181*38fd1498Szrj *
182*38fd1498Szrj * Create a %multiset consisting of copies of the elements from
183*38fd1498Szrj * [first,last). This is linear in N if the range is already sorted,
184*38fd1498Szrj * and NlogN otherwise (where N is distance(__first,__last)).
185*38fd1498Szrj */
186*38fd1498Szrj template<typename _InputIterator>
187*38fd1498Szrj multiset(_InputIterator __first, _InputIterator __last)
188*38fd1498Szrj : _M_t()
189*38fd1498Szrj { _M_t._M_insert_equal(__first, __last); }
190*38fd1498Szrj
191*38fd1498Szrj /**
192*38fd1498Szrj * @brief Builds a %multiset from a range.
193*38fd1498Szrj * @param __first An input iterator.
194*38fd1498Szrj * @param __last An input iterator.
195*38fd1498Szrj * @param __comp A comparison functor.
196*38fd1498Szrj * @param __a An allocator object.
197*38fd1498Szrj *
198*38fd1498Szrj * Create a %multiset consisting of copies of the elements from
199*38fd1498Szrj * [__first,__last). This is linear in N if the range is already sorted,
200*38fd1498Szrj * and NlogN otherwise (where N is distance(__first,__last)).
201*38fd1498Szrj */
202*38fd1498Szrj template<typename _InputIterator>
203*38fd1498Szrj multiset(_InputIterator __first, _InputIterator __last,
204*38fd1498Szrj const _Compare& __comp,
205*38fd1498Szrj const allocator_type& __a = allocator_type())
206*38fd1498Szrj : _M_t(__comp, _Key_alloc_type(__a))
207*38fd1498Szrj { _M_t._M_insert_equal(__first, __last); }
208*38fd1498Szrj
209*38fd1498Szrj /**
210*38fd1498Szrj * @brief %Multiset copy constructor.
211*38fd1498Szrj *
212*38fd1498Szrj * Whether the allocator is copied depends on the allocator traits.
213*38fd1498Szrj */
214*38fd1498Szrj #if __cplusplus < 201103L
215*38fd1498Szrj multiset(const multiset& __x)
216*38fd1498Szrj : _M_t(__x._M_t) { }
217*38fd1498Szrj #else
218*38fd1498Szrj multiset(const multiset&) = default;
219*38fd1498Szrj
220*38fd1498Szrj /**
221*38fd1498Szrj * @brief %Multiset move constructor.
222*38fd1498Szrj *
223*38fd1498Szrj * The newly-created %multiset contains the exact contents of the
224*38fd1498Szrj * moved instance. The moved instance is a valid, but unspecified
225*38fd1498Szrj * %multiset.
226*38fd1498Szrj */
227*38fd1498Szrj multiset(multiset&&) = default;
228*38fd1498Szrj
229*38fd1498Szrj /**
230*38fd1498Szrj * @brief Builds a %multiset from an initializer_list.
231*38fd1498Szrj * @param __l An initializer_list.
232*38fd1498Szrj * @param __comp A comparison functor.
233*38fd1498Szrj * @param __a An allocator object.
234*38fd1498Szrj *
235*38fd1498Szrj * Create a %multiset consisting of copies of the elements from
236*38fd1498Szrj * the list. This is linear in N if the list is already sorted,
237*38fd1498Szrj * and NlogN otherwise (where N is @a __l.size()).
238*38fd1498Szrj */
239*38fd1498Szrj multiset(initializer_list<value_type> __l,
240*38fd1498Szrj const _Compare& __comp = _Compare(),
241*38fd1498Szrj const allocator_type& __a = allocator_type())
242*38fd1498Szrj : _M_t(__comp, _Key_alloc_type(__a))
243*38fd1498Szrj { _M_t._M_insert_equal(__l.begin(), __l.end()); }
244*38fd1498Szrj
245*38fd1498Szrj /// Allocator-extended default constructor.
246*38fd1498Szrj explicit
247*38fd1498Szrj multiset(const allocator_type& __a)
248*38fd1498Szrj : _M_t(_Compare(), _Key_alloc_type(__a)) { }
249*38fd1498Szrj
250*38fd1498Szrj /// Allocator-extended copy constructor.
251*38fd1498Szrj multiset(const multiset& __m, const allocator_type& __a)
252*38fd1498Szrj : _M_t(__m._M_t, _Key_alloc_type(__a)) { }
253*38fd1498Szrj
254*38fd1498Szrj /// Allocator-extended move constructor.
255*38fd1498Szrj multiset(multiset&& __m, const allocator_type& __a)
256*38fd1498Szrj noexcept(is_nothrow_copy_constructible<_Compare>::value
257*38fd1498Szrj && _Alloc_traits::_S_always_equal())
258*38fd1498Szrj : _M_t(std::move(__m._M_t), _Key_alloc_type(__a)) { }
259*38fd1498Szrj
260*38fd1498Szrj /// Allocator-extended initialier-list constructor.
261*38fd1498Szrj multiset(initializer_list<value_type> __l, const allocator_type& __a)
262*38fd1498Szrj : _M_t(_Compare(), _Key_alloc_type(__a))
263*38fd1498Szrj { _M_t._M_insert_equal(__l.begin(), __l.end()); }
264*38fd1498Szrj
265*38fd1498Szrj /// Allocator-extended range constructor.
266*38fd1498Szrj template<typename _InputIterator>
267*38fd1498Szrj multiset(_InputIterator __first, _InputIterator __last,
268*38fd1498Szrj const allocator_type& __a)
269*38fd1498Szrj : _M_t(_Compare(), _Key_alloc_type(__a))
270*38fd1498Szrj { _M_t._M_insert_equal(__first, __last); }
271*38fd1498Szrj
272*38fd1498Szrj /**
273*38fd1498Szrj * The dtor only erases the elements, and note that if the elements
274*38fd1498Szrj * themselves are pointers, the pointed-to memory is not touched in any
275*38fd1498Szrj * way. Managing the pointer is the user's responsibility.
276*38fd1498Szrj */
277*38fd1498Szrj ~multiset() = default;
278*38fd1498Szrj #endif
279*38fd1498Szrj
280*38fd1498Szrj /**
281*38fd1498Szrj * @brief %Multiset assignment operator.
282*38fd1498Szrj *
283*38fd1498Szrj * Whether the allocator is copied depends on the allocator traits.
284*38fd1498Szrj */
285*38fd1498Szrj #if __cplusplus < 201103L
286*38fd1498Szrj multiset&
287*38fd1498Szrj operator=(const multiset& __x)
288*38fd1498Szrj {
289*38fd1498Szrj _M_t = __x._M_t;
290*38fd1498Szrj return *this;
291*38fd1498Szrj }
292*38fd1498Szrj #else
293*38fd1498Szrj multiset&
294*38fd1498Szrj operator=(const multiset&) = default;
295*38fd1498Szrj
296*38fd1498Szrj /// Move assignment operator.
297*38fd1498Szrj multiset&
298*38fd1498Szrj operator=(multiset&&) = default;
299*38fd1498Szrj
300*38fd1498Szrj /**
301*38fd1498Szrj * @brief %Multiset list assignment operator.
302*38fd1498Szrj * @param __l An initializer_list.
303*38fd1498Szrj *
304*38fd1498Szrj * This function fills a %multiset with copies of the elements in the
305*38fd1498Szrj * initializer list @a __l.
306*38fd1498Szrj *
307*38fd1498Szrj * Note that the assignment completely changes the %multiset and
308*38fd1498Szrj * that the resulting %multiset's size is the same as the number
309*38fd1498Szrj * of elements assigned.
310*38fd1498Szrj */
311*38fd1498Szrj multiset&
312*38fd1498Szrj operator=(initializer_list<value_type> __l)
313*38fd1498Szrj {
314*38fd1498Szrj _M_t._M_assign_equal(__l.begin(), __l.end());
315*38fd1498Szrj return *this;
316*38fd1498Szrj }
317*38fd1498Szrj #endif
318*38fd1498Szrj
319*38fd1498Szrj // accessors:
320*38fd1498Szrj
321*38fd1498Szrj /// Returns the comparison object.
322*38fd1498Szrj key_compare
323*38fd1498Szrj key_comp() const
324*38fd1498Szrj { return _M_t.key_comp(); }
325*38fd1498Szrj /// Returns the comparison object.
326*38fd1498Szrj value_compare
327*38fd1498Szrj value_comp() const
328*38fd1498Szrj { return _M_t.key_comp(); }
329*38fd1498Szrj /// Returns the memory allocation object.
330*38fd1498Szrj allocator_type
331*38fd1498Szrj get_allocator() const _GLIBCXX_NOEXCEPT
332*38fd1498Szrj { return allocator_type(_M_t.get_allocator()); }
333*38fd1498Szrj
334*38fd1498Szrj /**
335*38fd1498Szrj * Returns a read-only (constant) iterator that points to the first
336*38fd1498Szrj * element in the %multiset. Iteration is done in ascending order
337*38fd1498Szrj * according to the keys.
338*38fd1498Szrj */
339*38fd1498Szrj iterator
340*38fd1498Szrj begin() const _GLIBCXX_NOEXCEPT
341*38fd1498Szrj { return _M_t.begin(); }
342*38fd1498Szrj
343*38fd1498Szrj /**
344*38fd1498Szrj * Returns a read-only (constant) iterator that points one past the last
345*38fd1498Szrj * element in the %multiset. Iteration is done in ascending order
346*38fd1498Szrj * according to the keys.
347*38fd1498Szrj */
348*38fd1498Szrj iterator
349*38fd1498Szrj end() const _GLIBCXX_NOEXCEPT
350*38fd1498Szrj { return _M_t.end(); }
351*38fd1498Szrj
352*38fd1498Szrj /**
353*38fd1498Szrj * Returns a read-only (constant) reverse iterator that points to the
354*38fd1498Szrj * last element in the %multiset. Iteration is done in descending order
355*38fd1498Szrj * according to the keys.
356*38fd1498Szrj */
357*38fd1498Szrj reverse_iterator
358*38fd1498Szrj rbegin() const _GLIBCXX_NOEXCEPT
359*38fd1498Szrj { return _M_t.rbegin(); }
360*38fd1498Szrj
361*38fd1498Szrj /**
362*38fd1498Szrj * Returns a read-only (constant) reverse iterator that points to the
363*38fd1498Szrj * last element in the %multiset. Iteration is done in descending order
364*38fd1498Szrj * according to the keys.
365*38fd1498Szrj */
366*38fd1498Szrj reverse_iterator
367*38fd1498Szrj rend() const _GLIBCXX_NOEXCEPT
368*38fd1498Szrj { return _M_t.rend(); }
369*38fd1498Szrj
370*38fd1498Szrj #if __cplusplus >= 201103L
371*38fd1498Szrj /**
372*38fd1498Szrj * Returns a read-only (constant) iterator that points to the first
373*38fd1498Szrj * element in the %multiset. Iteration is done in ascending order
374*38fd1498Szrj * according to the keys.
375*38fd1498Szrj */
376*38fd1498Szrj iterator
377*38fd1498Szrj cbegin() const noexcept
378*38fd1498Szrj { return _M_t.begin(); }
379*38fd1498Szrj
380*38fd1498Szrj /**
381*38fd1498Szrj * Returns a read-only (constant) iterator that points one past the last
382*38fd1498Szrj * element in the %multiset. Iteration is done in ascending order
383*38fd1498Szrj * according to the keys.
384*38fd1498Szrj */
385*38fd1498Szrj iterator
386*38fd1498Szrj cend() const noexcept
387*38fd1498Szrj { return _M_t.end(); }
388*38fd1498Szrj
389*38fd1498Szrj /**
390*38fd1498Szrj * Returns a read-only (constant) reverse iterator that points to the
391*38fd1498Szrj * last element in the %multiset. Iteration is done in descending order
392*38fd1498Szrj * according to the keys.
393*38fd1498Szrj */
394*38fd1498Szrj reverse_iterator
395*38fd1498Szrj crbegin() const noexcept
396*38fd1498Szrj { return _M_t.rbegin(); }
397*38fd1498Szrj
398*38fd1498Szrj /**
399*38fd1498Szrj * Returns a read-only (constant) reverse iterator that points to the
400*38fd1498Szrj * last element in the %multiset. Iteration is done in descending order
401*38fd1498Szrj * according to the keys.
402*38fd1498Szrj */
403*38fd1498Szrj reverse_iterator
404*38fd1498Szrj crend() const noexcept
405*38fd1498Szrj { return _M_t.rend(); }
406*38fd1498Szrj #endif
407*38fd1498Szrj
408*38fd1498Szrj /// Returns true if the %set is empty.
409*38fd1498Szrj bool
410*38fd1498Szrj empty() const _GLIBCXX_NOEXCEPT
411*38fd1498Szrj { return _M_t.empty(); }
412*38fd1498Szrj
413*38fd1498Szrj /// Returns the size of the %set.
414*38fd1498Szrj size_type
415*38fd1498Szrj size() const _GLIBCXX_NOEXCEPT
416*38fd1498Szrj { return _M_t.size(); }
417*38fd1498Szrj
418*38fd1498Szrj /// Returns the maximum size of the %set.
419*38fd1498Szrj size_type
420*38fd1498Szrj max_size() const _GLIBCXX_NOEXCEPT
421*38fd1498Szrj { return _M_t.max_size(); }
422*38fd1498Szrj
423*38fd1498Szrj /**
424*38fd1498Szrj * @brief Swaps data with another %multiset.
425*38fd1498Szrj * @param __x A %multiset of the same element and allocator types.
426*38fd1498Szrj *
427*38fd1498Szrj * This exchanges the elements between two multisets in constant time.
428*38fd1498Szrj * (It is only swapping a pointer, an integer, and an instance of the @c
429*38fd1498Szrj * Compare type (which itself is often stateless and empty), so it should
430*38fd1498Szrj * be quite fast.)
431*38fd1498Szrj * Note that the global std::swap() function is specialized such that
432*38fd1498Szrj * std::swap(s1,s2) will feed to this function.
433*38fd1498Szrj *
434*38fd1498Szrj * Whether the allocators are swapped depends on the allocator traits.
435*38fd1498Szrj */
436*38fd1498Szrj void
437*38fd1498Szrj swap(multiset& __x)
438*38fd1498Szrj _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value)
439*38fd1498Szrj { _M_t.swap(__x._M_t); }
440*38fd1498Szrj
441*38fd1498Szrj // insert/erase
442*38fd1498Szrj #if __cplusplus >= 201103L
443*38fd1498Szrj /**
444*38fd1498Szrj * @brief Builds and inserts an element into the %multiset.
445*38fd1498Szrj * @param __args Arguments used to generate the element instance to be
446*38fd1498Szrj * inserted.
447*38fd1498Szrj * @return An iterator that points to the inserted element.
448*38fd1498Szrj *
449*38fd1498Szrj * This function inserts an element into the %multiset. Contrary
450*38fd1498Szrj * to a std::set the %multiset does not rely on unique keys and thus
451*38fd1498Szrj * multiple copies of the same element can be inserted.
452*38fd1498Szrj *
453*38fd1498Szrj * Insertion requires logarithmic time.
454*38fd1498Szrj */
455*38fd1498Szrj template<typename... _Args>
456*38fd1498Szrj iterator
457*38fd1498Szrj emplace(_Args&&... __args)
458*38fd1498Szrj { return _M_t._M_emplace_equal(std::forward<_Args>(__args)...); }
459*38fd1498Szrj
460*38fd1498Szrj /**
461*38fd1498Szrj * @brief Builds and inserts an element into the %multiset.
462*38fd1498Szrj * @param __pos An iterator that serves as a hint as to where the
463*38fd1498Szrj * element should be inserted.
464*38fd1498Szrj * @param __args Arguments used to generate the element instance to be
465*38fd1498Szrj * inserted.
466*38fd1498Szrj * @return An iterator that points to the inserted element.
467*38fd1498Szrj *
468*38fd1498Szrj * This function inserts an element into the %multiset. Contrary
469*38fd1498Szrj * to a std::set the %multiset does not rely on unique keys and thus
470*38fd1498Szrj * multiple copies of the same element can be inserted.
471*38fd1498Szrj *
472*38fd1498Szrj * Note that the first parameter is only a hint and can potentially
473*38fd1498Szrj * improve the performance of the insertion process. A bad hint would
474*38fd1498Szrj * cause no gains in efficiency.
475*38fd1498Szrj *
476*38fd1498Szrj * See https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints
477*38fd1498Szrj * for more on @a hinting.
478*38fd1498Szrj *
479*38fd1498Szrj * Insertion requires logarithmic time (if the hint is not taken).
480*38fd1498Szrj */
481*38fd1498Szrj template<typename... _Args>
482*38fd1498Szrj iterator
483*38fd1498Szrj emplace_hint(const_iterator __pos, _Args&&... __args)
484*38fd1498Szrj {
485*38fd1498Szrj return _M_t._M_emplace_hint_equal(__pos,
486*38fd1498Szrj std::forward<_Args>(__args)...);
487*38fd1498Szrj }
488*38fd1498Szrj #endif
489*38fd1498Szrj
490*38fd1498Szrj /**
491*38fd1498Szrj * @brief Inserts an element into the %multiset.
492*38fd1498Szrj * @param __x Element to be inserted.
493*38fd1498Szrj * @return An iterator that points to the inserted element.
494*38fd1498Szrj *
495*38fd1498Szrj * This function inserts an element into the %multiset. Contrary
496*38fd1498Szrj * to a std::set the %multiset does not rely on unique keys and thus
497*38fd1498Szrj * multiple copies of the same element can be inserted.
498*38fd1498Szrj *
499*38fd1498Szrj * Insertion requires logarithmic time.
500*38fd1498Szrj */
501*38fd1498Szrj iterator
502*38fd1498Szrj insert(const value_type& __x)
503*38fd1498Szrj { return _M_t._M_insert_equal(__x); }
504*38fd1498Szrj
505*38fd1498Szrj #if __cplusplus >= 201103L
506*38fd1498Szrj iterator
507*38fd1498Szrj insert(value_type&& __x)
508*38fd1498Szrj { return _M_t._M_insert_equal(std::move(__x)); }
509*38fd1498Szrj #endif
510*38fd1498Szrj
511*38fd1498Szrj /**
512*38fd1498Szrj * @brief Inserts an element into the %multiset.
513*38fd1498Szrj * @param __position An iterator that serves as a hint as to where the
514*38fd1498Szrj * element should be inserted.
515*38fd1498Szrj * @param __x Element to be inserted.
516*38fd1498Szrj * @return An iterator that points to the inserted element.
517*38fd1498Szrj *
518*38fd1498Szrj * This function inserts an element into the %multiset. Contrary
519*38fd1498Szrj * to a std::set the %multiset does not rely on unique keys and thus
520*38fd1498Szrj * multiple copies of the same element can be inserted.
521*38fd1498Szrj *
522*38fd1498Szrj * Note that the first parameter is only a hint and can potentially
523*38fd1498Szrj * improve the performance of the insertion process. A bad hint would
524*38fd1498Szrj * cause no gains in efficiency.
525*38fd1498Szrj *
526*38fd1498Szrj * See https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints
527*38fd1498Szrj * for more on @a hinting.
528*38fd1498Szrj *
529*38fd1498Szrj * Insertion requires logarithmic time (if the hint is not taken).
530*38fd1498Szrj */
531*38fd1498Szrj iterator
532*38fd1498Szrj insert(const_iterator __position, const value_type& __x)
533*38fd1498Szrj { return _M_t._M_insert_equal_(__position, __x); }
534*38fd1498Szrj
535*38fd1498Szrj #if __cplusplus >= 201103L
536*38fd1498Szrj iterator
537*38fd1498Szrj insert(const_iterator __position, value_type&& __x)
538*38fd1498Szrj { return _M_t._M_insert_equal_(__position, std::move(__x)); }
539*38fd1498Szrj #endif
540*38fd1498Szrj
541*38fd1498Szrj /**
542*38fd1498Szrj * @brief A template function that tries to insert a range of elements.
543*38fd1498Szrj * @param __first Iterator pointing to the start of the range to be
544*38fd1498Szrj * inserted.
545*38fd1498Szrj * @param __last Iterator pointing to the end of the range.
546*38fd1498Szrj *
547*38fd1498Szrj * Complexity similar to that of the range constructor.
548*38fd1498Szrj */
549*38fd1498Szrj template<typename _InputIterator>
550*38fd1498Szrj void
551*38fd1498Szrj insert(_InputIterator __first, _InputIterator __last)
552*38fd1498Szrj { _M_t._M_insert_equal(__first, __last); }
553*38fd1498Szrj
554*38fd1498Szrj #if __cplusplus >= 201103L
555*38fd1498Szrj /**
556*38fd1498Szrj * @brief Attempts to insert a list of elements into the %multiset.
557*38fd1498Szrj * @param __l A std::initializer_list<value_type> of elements
558*38fd1498Szrj * to be inserted.
559*38fd1498Szrj *
560*38fd1498Szrj * Complexity similar to that of the range constructor.
561*38fd1498Szrj */
562*38fd1498Szrj void
563*38fd1498Szrj insert(initializer_list<value_type> __l)
564*38fd1498Szrj { this->insert(__l.begin(), __l.end()); }
565*38fd1498Szrj #endif
566*38fd1498Szrj
567*38fd1498Szrj #if __cplusplus > 201402L
568*38fd1498Szrj /// Extract a node.
569*38fd1498Szrj node_type
570*38fd1498Szrj extract(const_iterator __pos)
571*38fd1498Szrj {
572*38fd1498Szrj __glibcxx_assert(__pos != end());
573*38fd1498Szrj return _M_t.extract(__pos);
574*38fd1498Szrj }
575*38fd1498Szrj
576*38fd1498Szrj /// Extract a node.
577*38fd1498Szrj node_type
578*38fd1498Szrj extract(const key_type& __x)
579*38fd1498Szrj { return _M_t.extract(__x); }
580*38fd1498Szrj
581*38fd1498Szrj /// Re-insert an extracted node.
582*38fd1498Szrj iterator
583*38fd1498Szrj insert(node_type&& __nh)
584*38fd1498Szrj { return _M_t._M_reinsert_node_equal(std::move(__nh)); }
585*38fd1498Szrj
586*38fd1498Szrj /// Re-insert an extracted node.
587*38fd1498Szrj iterator
588*38fd1498Szrj insert(const_iterator __hint, node_type&& __nh)
589*38fd1498Szrj { return _M_t._M_reinsert_node_hint_equal(__hint, std::move(__nh)); }
590*38fd1498Szrj
591*38fd1498Szrj template<typename, typename>
592*38fd1498Szrj friend class std::_Rb_tree_merge_helper;
593*38fd1498Szrj
594*38fd1498Szrj template<typename _Compare1>
595*38fd1498Szrj void
596*38fd1498Szrj merge(multiset<_Key, _Compare1, _Alloc>& __source)
597*38fd1498Szrj {
598*38fd1498Szrj using _Merge_helper = _Rb_tree_merge_helper<multiset, _Compare1>;
599*38fd1498Szrj _M_t._M_merge_equal(_Merge_helper::_S_get_tree(__source));
600*38fd1498Szrj }
601*38fd1498Szrj
602*38fd1498Szrj template<typename _Compare1>
603*38fd1498Szrj void
604*38fd1498Szrj merge(multiset<_Key, _Compare1, _Alloc>&& __source)
605*38fd1498Szrj { merge(__source); }
606*38fd1498Szrj
607*38fd1498Szrj template<typename _Compare1>
608*38fd1498Szrj void
609*38fd1498Szrj merge(set<_Key, _Compare1, _Alloc>& __source)
610*38fd1498Szrj {
611*38fd1498Szrj using _Merge_helper = _Rb_tree_merge_helper<multiset, _Compare1>;
612*38fd1498Szrj _M_t._M_merge_equal(_Merge_helper::_S_get_tree(__source));
613*38fd1498Szrj }
614*38fd1498Szrj
615*38fd1498Szrj template<typename _Compare1>
616*38fd1498Szrj void
617*38fd1498Szrj merge(set<_Key, _Compare1, _Alloc>&& __source)
618*38fd1498Szrj { merge(__source); }
619*38fd1498Szrj #endif // C++17
620*38fd1498Szrj
621*38fd1498Szrj #if __cplusplus >= 201103L
622*38fd1498Szrj // _GLIBCXX_RESOLVE_LIB_DEFECTS
623*38fd1498Szrj // DR 130. Associative erase should return an iterator.
624*38fd1498Szrj /**
625*38fd1498Szrj * @brief Erases an element from a %multiset.
626*38fd1498Szrj * @param __position An iterator pointing to the element to be erased.
627*38fd1498Szrj * @return An iterator pointing to the element immediately following
628*38fd1498Szrj * @a position prior to the element being erased. If no such
629*38fd1498Szrj * element exists, end() is returned.
630*38fd1498Szrj *
631*38fd1498Szrj * This function erases an element, pointed to by the given iterator,
632*38fd1498Szrj * from a %multiset. Note that this function only erases the element,
633*38fd1498Szrj * and that if the element is itself a pointer, the pointed-to memory is
634*38fd1498Szrj * not touched in any way. Managing the pointer is the user's
635*38fd1498Szrj * responsibility.
636*38fd1498Szrj */
637*38fd1498Szrj _GLIBCXX_ABI_TAG_CXX11
638*38fd1498Szrj iterator
639*38fd1498Szrj erase(const_iterator __position)
640*38fd1498Szrj { return _M_t.erase(__position); }
641*38fd1498Szrj #else
642*38fd1498Szrj /**
643*38fd1498Szrj * @brief Erases an element from a %multiset.
644*38fd1498Szrj * @param __position An iterator pointing to the element to be erased.
645*38fd1498Szrj *
646*38fd1498Szrj * This function erases an element, pointed to by the given iterator,
647*38fd1498Szrj * from a %multiset. Note that this function only erases the element,
648*38fd1498Szrj * and that if the element is itself a pointer, the pointed-to memory is
649*38fd1498Szrj * not touched in any way. Managing the pointer is the user's
650*38fd1498Szrj * responsibility.
651*38fd1498Szrj */
652*38fd1498Szrj void
653*38fd1498Szrj erase(iterator __position)
654*38fd1498Szrj { _M_t.erase(__position); }
655*38fd1498Szrj #endif
656*38fd1498Szrj
657*38fd1498Szrj /**
658*38fd1498Szrj * @brief Erases elements according to the provided key.
659*38fd1498Szrj * @param __x Key of element to be erased.
660*38fd1498Szrj * @return The number of elements erased.
661*38fd1498Szrj *
662*38fd1498Szrj * This function erases all elements located by the given key from a
663*38fd1498Szrj * %multiset.
664*38fd1498Szrj * Note that this function only erases the element, and that if
665*38fd1498Szrj * the element is itself a pointer, the pointed-to memory is not touched
666*38fd1498Szrj * in any way. Managing the pointer is the user's responsibility.
667*38fd1498Szrj */
668*38fd1498Szrj size_type
669*38fd1498Szrj erase(const key_type& __x)
670*38fd1498Szrj { return _M_t.erase(__x); }
671*38fd1498Szrj
672*38fd1498Szrj #if __cplusplus >= 201103L
673*38fd1498Szrj // _GLIBCXX_RESOLVE_LIB_DEFECTS
674*38fd1498Szrj // DR 130. Associative erase should return an iterator.
675*38fd1498Szrj /**
676*38fd1498Szrj * @brief Erases a [first,last) range of elements from a %multiset.
677*38fd1498Szrj * @param __first Iterator pointing to the start of the range to be
678*38fd1498Szrj * erased.
679*38fd1498Szrj * @param __last Iterator pointing to the end of the range to
680*38fd1498Szrj * be erased.
681*38fd1498Szrj * @return The iterator @a last.
682*38fd1498Szrj *
683*38fd1498Szrj * This function erases a sequence of elements from a %multiset.
684*38fd1498Szrj * Note that this function only erases the elements, and that if
685*38fd1498Szrj * the elements themselves are pointers, the pointed-to memory is not
686*38fd1498Szrj * touched in any way. Managing the pointer is the user's
687*38fd1498Szrj * responsibility.
688*38fd1498Szrj */
689*38fd1498Szrj _GLIBCXX_ABI_TAG_CXX11
690*38fd1498Szrj iterator
691*38fd1498Szrj erase(const_iterator __first, const_iterator __last)
692*38fd1498Szrj { return _M_t.erase(__first, __last); }
693*38fd1498Szrj #else
694*38fd1498Szrj /**
695*38fd1498Szrj * @brief Erases a [first,last) range of elements from a %multiset.
696*38fd1498Szrj * @param first Iterator pointing to the start of the range to be
697*38fd1498Szrj * erased.
698*38fd1498Szrj * @param last Iterator pointing to the end of the range to be erased.
699*38fd1498Szrj *
700*38fd1498Szrj * This function erases a sequence of elements from a %multiset.
701*38fd1498Szrj * Note that this function only erases the elements, and that if
702*38fd1498Szrj * the elements themselves are pointers, the pointed-to memory is not
703*38fd1498Szrj * touched in any way. Managing the pointer is the user's
704*38fd1498Szrj * responsibility.
705*38fd1498Szrj */
706*38fd1498Szrj void
707*38fd1498Szrj erase(iterator __first, iterator __last)
708*38fd1498Szrj { _M_t.erase(__first, __last); }
709*38fd1498Szrj #endif
710*38fd1498Szrj
711*38fd1498Szrj /**
712*38fd1498Szrj * Erases all elements in a %multiset. Note that this function only
713*38fd1498Szrj * erases the elements, and that if the elements themselves are pointers,
714*38fd1498Szrj * the pointed-to memory is not touched in any way. Managing the pointer
715*38fd1498Szrj * is the user's responsibility.
716*38fd1498Szrj */
717*38fd1498Szrj void
718*38fd1498Szrj clear() _GLIBCXX_NOEXCEPT
719*38fd1498Szrj { _M_t.clear(); }
720*38fd1498Szrj
721*38fd1498Szrj // multiset operations:
722*38fd1498Szrj
723*38fd1498Szrj //@{
724*38fd1498Szrj /**
725*38fd1498Szrj * @brief Finds the number of elements with given key.
726*38fd1498Szrj * @param __x Key of elements to be located.
727*38fd1498Szrj * @return Number of elements with specified key.
728*38fd1498Szrj */
729*38fd1498Szrj size_type
730*38fd1498Szrj count(const key_type& __x) const
731*38fd1498Szrj { return _M_t.count(__x); }
732*38fd1498Szrj
733*38fd1498Szrj #if __cplusplus > 201103L
734*38fd1498Szrj template<typename _Kt>
735*38fd1498Szrj auto
736*38fd1498Szrj count(const _Kt& __x) const -> decltype(_M_t._M_count_tr(__x))
737*38fd1498Szrj { return _M_t._M_count_tr(__x); }
738*38fd1498Szrj #endif
739*38fd1498Szrj //@}
740*38fd1498Szrj
741*38fd1498Szrj // _GLIBCXX_RESOLVE_LIB_DEFECTS
742*38fd1498Szrj // 214. set::find() missing const overload
743*38fd1498Szrj //@{
744*38fd1498Szrj /**
745*38fd1498Szrj * @brief Tries to locate an element in a %set.
746*38fd1498Szrj * @param __x Element to be located.
747*38fd1498Szrj * @return Iterator pointing to sought-after element, or end() if not
748*38fd1498Szrj * found.
749*38fd1498Szrj *
750*38fd1498Szrj * This function takes a key and tries to locate the element with which
751*38fd1498Szrj * the key matches. If successful the function returns an iterator
752*38fd1498Szrj * pointing to the sought after element. If unsuccessful it returns the
753*38fd1498Szrj * past-the-end ( @c end() ) iterator.
754*38fd1498Szrj */
755*38fd1498Szrj iterator
756*38fd1498Szrj find(const key_type& __x)
757*38fd1498Szrj { return _M_t.find(__x); }
758*38fd1498Szrj
759*38fd1498Szrj const_iterator
760*38fd1498Szrj find(const key_type& __x) const
761*38fd1498Szrj { return _M_t.find(__x); }
762*38fd1498Szrj
763*38fd1498Szrj #if __cplusplus > 201103L
764*38fd1498Szrj template<typename _Kt>
765*38fd1498Szrj auto
766*38fd1498Szrj find(const _Kt& __x)
767*38fd1498Szrj -> decltype(iterator{_M_t._M_find_tr(__x)})
768*38fd1498Szrj { return iterator{_M_t._M_find_tr(__x)}; }
769*38fd1498Szrj
770*38fd1498Szrj template<typename _Kt>
771*38fd1498Szrj auto
772*38fd1498Szrj find(const _Kt& __x) const
773*38fd1498Szrj -> decltype(const_iterator{_M_t._M_find_tr(__x)})
774*38fd1498Szrj { return const_iterator{_M_t._M_find_tr(__x)}; }
775*38fd1498Szrj #endif
776*38fd1498Szrj //@}
777*38fd1498Szrj
778*38fd1498Szrj //@{
779*38fd1498Szrj /**
780*38fd1498Szrj * @brief Finds the beginning of a subsequence matching given key.
781*38fd1498Szrj * @param __x Key to be located.
782*38fd1498Szrj * @return Iterator pointing to first element equal to or greater
783*38fd1498Szrj * than key, or end().
784*38fd1498Szrj *
785*38fd1498Szrj * This function returns the first element of a subsequence of elements
786*38fd1498Szrj * that matches the given key. If unsuccessful it returns an iterator
787*38fd1498Szrj * pointing to the first element that has a greater value than given key
788*38fd1498Szrj * or end() if no such element exists.
789*38fd1498Szrj */
790*38fd1498Szrj iterator
791*38fd1498Szrj lower_bound(const key_type& __x)
792*38fd1498Szrj { return _M_t.lower_bound(__x); }
793*38fd1498Szrj
794*38fd1498Szrj const_iterator
795*38fd1498Szrj lower_bound(const key_type& __x) const
796*38fd1498Szrj { return _M_t.lower_bound(__x); }
797*38fd1498Szrj
798*38fd1498Szrj #if __cplusplus > 201103L
799*38fd1498Szrj template<typename _Kt>
800*38fd1498Szrj auto
801*38fd1498Szrj lower_bound(const _Kt& __x)
802*38fd1498Szrj -> decltype(iterator(_M_t._M_lower_bound_tr(__x)))
803*38fd1498Szrj { return iterator(_M_t._M_lower_bound_tr(__x)); }
804*38fd1498Szrj
805*38fd1498Szrj template<typename _Kt>
806*38fd1498Szrj auto
807*38fd1498Szrj lower_bound(const _Kt& __x) const
808*38fd1498Szrj -> decltype(iterator(_M_t._M_lower_bound_tr(__x)))
809*38fd1498Szrj { return iterator(_M_t._M_lower_bound_tr(__x)); }
810*38fd1498Szrj #endif
811*38fd1498Szrj //@}
812*38fd1498Szrj
813*38fd1498Szrj //@{
814*38fd1498Szrj /**
815*38fd1498Szrj * @brief Finds the end of a subsequence matching given key.
816*38fd1498Szrj * @param __x Key to be located.
817*38fd1498Szrj * @return Iterator pointing to the first element
818*38fd1498Szrj * greater than key, or end().
819*38fd1498Szrj */
820*38fd1498Szrj iterator
821*38fd1498Szrj upper_bound(const key_type& __x)
822*38fd1498Szrj { return _M_t.upper_bound(__x); }
823*38fd1498Szrj
824*38fd1498Szrj const_iterator
825*38fd1498Szrj upper_bound(const key_type& __x) const
826*38fd1498Szrj { return _M_t.upper_bound(__x); }
827*38fd1498Szrj
828*38fd1498Szrj #if __cplusplus > 201103L
829*38fd1498Szrj template<typename _Kt>
830*38fd1498Szrj auto
831*38fd1498Szrj upper_bound(const _Kt& __x)
832*38fd1498Szrj -> decltype(iterator(_M_t._M_upper_bound_tr(__x)))
833*38fd1498Szrj { return iterator(_M_t._M_upper_bound_tr(__x)); }
834*38fd1498Szrj
835*38fd1498Szrj template<typename _Kt>
836*38fd1498Szrj auto
837*38fd1498Szrj upper_bound(const _Kt& __x) const
838*38fd1498Szrj -> decltype(iterator(_M_t._M_upper_bound_tr(__x)))
839*38fd1498Szrj { return iterator(_M_t._M_upper_bound_tr(__x)); }
840*38fd1498Szrj #endif
841*38fd1498Szrj //@}
842*38fd1498Szrj
843*38fd1498Szrj //@{
844*38fd1498Szrj /**
845*38fd1498Szrj * @brief Finds a subsequence matching given key.
846*38fd1498Szrj * @param __x Key to be located.
847*38fd1498Szrj * @return Pair of iterators that possibly points to the subsequence
848*38fd1498Szrj * matching given key.
849*38fd1498Szrj *
850*38fd1498Szrj * This function is equivalent to
851*38fd1498Szrj * @code
852*38fd1498Szrj * std::make_pair(c.lower_bound(val),
853*38fd1498Szrj * c.upper_bound(val))
854*38fd1498Szrj * @endcode
855*38fd1498Szrj * (but is faster than making the calls separately).
856*38fd1498Szrj *
857*38fd1498Szrj * This function probably only makes sense for multisets.
858*38fd1498Szrj */
859*38fd1498Szrj std::pair<iterator, iterator>
860*38fd1498Szrj equal_range(const key_type& __x)
861*38fd1498Szrj { return _M_t.equal_range(__x); }
862*38fd1498Szrj
863*38fd1498Szrj std::pair<const_iterator, const_iterator>
864*38fd1498Szrj equal_range(const key_type& __x) const
865*38fd1498Szrj { return _M_t.equal_range(__x); }
866*38fd1498Szrj
867*38fd1498Szrj #if __cplusplus > 201103L
868*38fd1498Szrj template<typename _Kt>
869*38fd1498Szrj auto
870*38fd1498Szrj equal_range(const _Kt& __x)
871*38fd1498Szrj -> decltype(pair<iterator, iterator>(_M_t._M_equal_range_tr(__x)))
872*38fd1498Szrj { return pair<iterator, iterator>(_M_t._M_equal_range_tr(__x)); }
873*38fd1498Szrj
874*38fd1498Szrj template<typename _Kt>
875*38fd1498Szrj auto
876*38fd1498Szrj equal_range(const _Kt& __x) const
877*38fd1498Szrj -> decltype(pair<iterator, iterator>(_M_t._M_equal_range_tr(__x)))
878*38fd1498Szrj { return pair<iterator, iterator>(_M_t._M_equal_range_tr(__x)); }
879*38fd1498Szrj #endif
880*38fd1498Szrj //@}
881*38fd1498Szrj
882*38fd1498Szrj template<typename _K1, typename _C1, typename _A1>
883*38fd1498Szrj friend bool
884*38fd1498Szrj operator==(const multiset<_K1, _C1, _A1>&,
885*38fd1498Szrj const multiset<_K1, _C1, _A1>&);
886*38fd1498Szrj
887*38fd1498Szrj template<typename _K1, typename _C1, typename _A1>
888*38fd1498Szrj friend bool
889*38fd1498Szrj operator< (const multiset<_K1, _C1, _A1>&,
890*38fd1498Szrj const multiset<_K1, _C1, _A1>&);
891*38fd1498Szrj };
892*38fd1498Szrj
893*38fd1498Szrj #if __cpp_deduction_guides >= 201606
894*38fd1498Szrj
895*38fd1498Szrj template<typename _InputIterator,
896*38fd1498Szrj typename _Compare =
897*38fd1498Szrj less<typename iterator_traits<_InputIterator>::value_type>,
898*38fd1498Szrj typename _Allocator =
899*38fd1498Szrj allocator<typename iterator_traits<_InputIterator>::value_type>,
900*38fd1498Szrj typename = _RequireInputIter<_InputIterator>,
901*38fd1498Szrj typename = _RequireAllocator<_Allocator>>
902*38fd1498Szrj multiset(_InputIterator, _InputIterator,
903*38fd1498Szrj _Compare = _Compare(), _Allocator = _Allocator())
904*38fd1498Szrj -> multiset<typename iterator_traits<_InputIterator>::value_type,
905*38fd1498Szrj _Compare, _Allocator>;
906*38fd1498Szrj
907*38fd1498Szrj template<typename _Key,
908*38fd1498Szrj typename _Compare = less<_Key>,
909*38fd1498Szrj typename _Allocator = allocator<_Key>,
910*38fd1498Szrj typename = _RequireAllocator<_Allocator>>
911*38fd1498Szrj multiset(initializer_list<_Key>,
912*38fd1498Szrj _Compare = _Compare(), _Allocator = _Allocator())
913*38fd1498Szrj -> multiset<_Key, _Compare, _Allocator>;
914*38fd1498Szrj
915*38fd1498Szrj template<typename _InputIterator, typename _Allocator,
916*38fd1498Szrj typename = _RequireInputIter<_InputIterator>,
917*38fd1498Szrj typename = _RequireAllocator<_Allocator>>
918*38fd1498Szrj multiset(_InputIterator, _InputIterator, _Allocator)
919*38fd1498Szrj -> multiset<typename iterator_traits<_InputIterator>::value_type,
920*38fd1498Szrj less<typename iterator_traits<_InputIterator>::value_type>,
921*38fd1498Szrj _Allocator>;
922*38fd1498Szrj
923*38fd1498Szrj template<typename _Key, typename _Allocator,
924*38fd1498Szrj typename = _RequireAllocator<_Allocator>>
925*38fd1498Szrj multiset(initializer_list<_Key>, _Allocator)
926*38fd1498Szrj -> multiset<_Key, less<_Key>, _Allocator>;
927*38fd1498Szrj
928*38fd1498Szrj #endif
929*38fd1498Szrj
930*38fd1498Szrj /**
931*38fd1498Szrj * @brief Multiset equality comparison.
932*38fd1498Szrj * @param __x A %multiset.
933*38fd1498Szrj * @param __y A %multiset of the same type as @a __x.
934*38fd1498Szrj * @return True iff the size and elements of the multisets are equal.
935*38fd1498Szrj *
936*38fd1498Szrj * This is an equivalence relation. It is linear in the size of the
937*38fd1498Szrj * multisets.
938*38fd1498Szrj * Multisets are considered equivalent if their sizes are equal, and if
939*38fd1498Szrj * corresponding elements compare equal.
940*38fd1498Szrj */
941*38fd1498Szrj template<typename _Key, typename _Compare, typename _Alloc>
942*38fd1498Szrj inline bool
943*38fd1498Szrj operator==(const multiset<_Key, _Compare, _Alloc>& __x,
944*38fd1498Szrj const multiset<_Key, _Compare, _Alloc>& __y)
945*38fd1498Szrj { return __x._M_t == __y._M_t; }
946*38fd1498Szrj
947*38fd1498Szrj /**
948*38fd1498Szrj * @brief Multiset ordering relation.
949*38fd1498Szrj * @param __x A %multiset.
950*38fd1498Szrj * @param __y A %multiset of the same type as @a __x.
951*38fd1498Szrj * @return True iff @a __x is lexicographically less than @a __y.
952*38fd1498Szrj *
953*38fd1498Szrj * This is a total ordering relation. It is linear in the size of the
954*38fd1498Szrj * sets. The elements must be comparable with @c <.
955*38fd1498Szrj *
956*38fd1498Szrj * See std::lexicographical_compare() for how the determination is made.
957*38fd1498Szrj */
958*38fd1498Szrj template<typename _Key, typename _Compare, typename _Alloc>
959*38fd1498Szrj inline bool
960*38fd1498Szrj operator<(const multiset<_Key, _Compare, _Alloc>& __x,
961*38fd1498Szrj const multiset<_Key, _Compare, _Alloc>& __y)
962*38fd1498Szrj { return __x._M_t < __y._M_t; }
963*38fd1498Szrj
964*38fd1498Szrj /// Returns !(x == y).
965*38fd1498Szrj template<typename _Key, typename _Compare, typename _Alloc>
966*38fd1498Szrj inline bool
967*38fd1498Szrj operator!=(const multiset<_Key, _Compare, _Alloc>& __x,
968*38fd1498Szrj const multiset<_Key, _Compare, _Alloc>& __y)
969*38fd1498Szrj { return !(__x == __y); }
970*38fd1498Szrj
971*38fd1498Szrj /// Returns y < x.
972*38fd1498Szrj template<typename _Key, typename _Compare, typename _Alloc>
973*38fd1498Szrj inline bool
974*38fd1498Szrj operator>(const multiset<_Key,_Compare,_Alloc>& __x,
975*38fd1498Szrj const multiset<_Key,_Compare,_Alloc>& __y)
976*38fd1498Szrj { return __y < __x; }
977*38fd1498Szrj
978*38fd1498Szrj /// Returns !(y < x)
979*38fd1498Szrj template<typename _Key, typename _Compare, typename _Alloc>
980*38fd1498Szrj inline bool
981*38fd1498Szrj operator<=(const multiset<_Key, _Compare, _Alloc>& __x,
982*38fd1498Szrj const multiset<_Key, _Compare, _Alloc>& __y)
983*38fd1498Szrj { return !(__y < __x); }
984*38fd1498Szrj
985*38fd1498Szrj /// Returns !(x < y)
986*38fd1498Szrj template<typename _Key, typename _Compare, typename _Alloc>
987*38fd1498Szrj inline bool
988*38fd1498Szrj operator>=(const multiset<_Key, _Compare, _Alloc>& __x,
989*38fd1498Szrj const multiset<_Key, _Compare, _Alloc>& __y)
990*38fd1498Szrj { return !(__x < __y); }
991*38fd1498Szrj
992*38fd1498Szrj /// See std::multiset::swap().
993*38fd1498Szrj template<typename _Key, typename _Compare, typename _Alloc>
994*38fd1498Szrj inline void
995*38fd1498Szrj swap(multiset<_Key, _Compare, _Alloc>& __x,
996*38fd1498Szrj multiset<_Key, _Compare, _Alloc>& __y)
997*38fd1498Szrj _GLIBCXX_NOEXCEPT_IF(noexcept(__x.swap(__y)))
998*38fd1498Szrj { __x.swap(__y); }
999*38fd1498Szrj
1000*38fd1498Szrj _GLIBCXX_END_NAMESPACE_CONTAINER
1001*38fd1498Szrj
1002*38fd1498Szrj #if __cplusplus > 201402L
1003*38fd1498Szrj // Allow std::multiset access to internals of compatible sets.
1004*38fd1498Szrj template<typename _Val, typename _Cmp1, typename _Alloc, typename _Cmp2>
1005*38fd1498Szrj struct
1006*38fd1498Szrj _Rb_tree_merge_helper<_GLIBCXX_STD_C::multiset<_Val, _Cmp1, _Alloc>,
1007*38fd1498Szrj _Cmp2>
1008*38fd1498Szrj {
1009*38fd1498Szrj private:
1010*38fd1498Szrj friend class _GLIBCXX_STD_C::multiset<_Val, _Cmp1, _Alloc>;
1011*38fd1498Szrj
1012*38fd1498Szrj static auto&
1013*38fd1498Szrj _S_get_tree(_GLIBCXX_STD_C::set<_Val, _Cmp2, _Alloc>& __set)
1014*38fd1498Szrj { return __set._M_t; }
1015*38fd1498Szrj
1016*38fd1498Szrj static auto&
1017*38fd1498Szrj _S_get_tree(_GLIBCXX_STD_C::multiset<_Val, _Cmp2, _Alloc>& __set)
1018*38fd1498Szrj { return __set._M_t; }
1019*38fd1498Szrj };
1020*38fd1498Szrj
1021*38fd1498Szrj #endif // C++17
1022*38fd1498Szrj
1023*38fd1498Szrj _GLIBCXX_END_NAMESPACE_VERSION
1024*38fd1498Szrj } // namespace std
1025*38fd1498Szrj
1026*38fd1498Szrj #endif /* _STL_MULTISET_H */
1027