xref: /openbsd-src/gnu/gcc/libstdc++-v3/include/bits/stl_multiset.h (revision 404b540a9034ac75a6199ad1a32d1bbc7a0d4210)
1*404b540aSrobert // Multiset implementation -*- C++ -*-
2*404b540aSrobert 
3*404b540aSrobert // Copyright (C) 2001, 2002, 2004, 2005, 2006 Free Software Foundation, Inc.
4*404b540aSrobert //
5*404b540aSrobert // This file is part of the GNU ISO C++ Library.  This library is free
6*404b540aSrobert // software; you can redistribute it and/or modify it under the
7*404b540aSrobert // terms of the GNU General Public License as published by the
8*404b540aSrobert // Free Software Foundation; either version 2, or (at your option)
9*404b540aSrobert // any later version.
10*404b540aSrobert 
11*404b540aSrobert // This library is distributed in the hope that it will be useful,
12*404b540aSrobert // but WITHOUT ANY WARRANTY; without even the implied warranty of
13*404b540aSrobert // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14*404b540aSrobert // GNU General Public License for more details.
15*404b540aSrobert 
16*404b540aSrobert // You should have received a copy of the GNU General Public License along
17*404b540aSrobert // with this library; see the file COPYING.  If not, write to the Free
18*404b540aSrobert // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19*404b540aSrobert // USA.
20*404b540aSrobert 
21*404b540aSrobert // As a special exception, you may use this file as part of a free software
22*404b540aSrobert // library without restriction.  Specifically, if other files instantiate
23*404b540aSrobert // templates or use macros or inline functions from this file, or you compile
24*404b540aSrobert // this file and link it with other files to produce an executable, this
25*404b540aSrobert // file does not by itself cause the resulting executable to be covered by
26*404b540aSrobert // the GNU General Public License.  This exception does not however
27*404b540aSrobert // invalidate any other reasons why the executable file might be covered by
28*404b540aSrobert // the GNU General Public License.
29*404b540aSrobert 
30*404b540aSrobert /*
31*404b540aSrobert  *
32*404b540aSrobert  * Copyright (c) 1994
33*404b540aSrobert  * Hewlett-Packard Company
34*404b540aSrobert  *
35*404b540aSrobert  * Permission to use, copy, modify, distribute and sell this software
36*404b540aSrobert  * and its documentation for any purpose is hereby granted without fee,
37*404b540aSrobert  * provided that the above copyright notice appear in all copies and
38*404b540aSrobert  * that both that copyright notice and this permission notice appear
39*404b540aSrobert  * in supporting documentation.  Hewlett-Packard Company makes no
40*404b540aSrobert  * representations about the suitability of this software for any
41*404b540aSrobert  * purpose.  It is provided "as is" without express or implied warranty.
42*404b540aSrobert  *
43*404b540aSrobert  *
44*404b540aSrobert  * Copyright (c) 1996
45*404b540aSrobert  * Silicon Graphics Computer Systems, Inc.
46*404b540aSrobert  *
47*404b540aSrobert  * Permission to use, copy, modify, distribute and sell this software
48*404b540aSrobert  * and its documentation for any purpose is hereby granted without fee,
49*404b540aSrobert  * provided that the above copyright notice appear in all copies and
50*404b540aSrobert  * that both that copyright notice and this permission notice appear
51*404b540aSrobert  * in supporting documentation.  Silicon Graphics makes no
52*404b540aSrobert  * representations about the suitability of this software for any
53*404b540aSrobert  * purpose.  It is provided "as is" without express or implied warranty.
54*404b540aSrobert  */
55*404b540aSrobert 
56*404b540aSrobert /** @file stl_multiset.h
57*404b540aSrobert  *  This is an internal header file, included by other library headers.
58*404b540aSrobert  *  You should not attempt to use it directly.
59*404b540aSrobert  */
60*404b540aSrobert 
61*404b540aSrobert #ifndef _MULTISET_H
62*404b540aSrobert #define _MULTISET_H 1
63*404b540aSrobert 
64*404b540aSrobert #include <bits/concept_check.h>
65*404b540aSrobert 
_GLIBCXX_BEGIN_NESTED_NAMESPACE(std,_GLIBCXX_STD)66*404b540aSrobert _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD)
67*404b540aSrobert 
68*404b540aSrobert   /**
69*404b540aSrobert    *  @brief A standard container made up of elements, which can be retrieved
70*404b540aSrobert    *  in logarithmic time.
71*404b540aSrobert    *
72*404b540aSrobert    *  @ingroup Containers
73*404b540aSrobert    *  @ingroup Assoc_containers
74*404b540aSrobert    *
75*404b540aSrobert    *  Meets the requirements of a <a href="tables.html#65">container</a>, a
76*404b540aSrobert    *  <a href="tables.html#66">reversible container</a>, and an
77*404b540aSrobert    *  <a href="tables.html#69">associative container</a> (using equivalent
78*404b540aSrobert    *  keys).  For a @c multiset<Key> the key_type and value_type are Key.
79*404b540aSrobert    *
80*404b540aSrobert    *  Multisets support bidirectional iterators.
81*404b540aSrobert    *
82*404b540aSrobert    *  @if maint
83*404b540aSrobert    *  The private tree data is declared exactly the same way for set and
84*404b540aSrobert    *  multiset; the distinction is made entirely in how the tree functions are
85*404b540aSrobert    *  called (*_unique versus *_equal, same as the standard).
86*404b540aSrobert    *  @endif
87*404b540aSrobert   */
88*404b540aSrobert   template <class _Key, class _Compare = std::less<_Key>,
89*404b540aSrobert 	    class _Alloc = std::allocator<_Key> >
90*404b540aSrobert     class multiset
91*404b540aSrobert     {
92*404b540aSrobert       // concept requirements
93*404b540aSrobert       typedef typename _Alloc::value_type                   _Alloc_value_type;
94*404b540aSrobert       __glibcxx_class_requires(_Key, _SGIAssignableConcept)
95*404b540aSrobert       __glibcxx_class_requires4(_Compare, bool, _Key, _Key,
96*404b540aSrobert 				_BinaryFunctionConcept)
97*404b540aSrobert       __glibcxx_class_requires2(_Key, _Alloc_value_type, _SameTypeConcept)
98*404b540aSrobert 
99*404b540aSrobert     public:
100*404b540aSrobert       // typedefs:
101*404b540aSrobert       typedef _Key     key_type;
102*404b540aSrobert       typedef _Key     value_type;
103*404b540aSrobert       typedef _Compare key_compare;
104*404b540aSrobert       typedef _Compare value_compare;
105*404b540aSrobert       typedef _Alloc   allocator_type;
106*404b540aSrobert 
107*404b540aSrobert     private:
108*404b540aSrobert       /// @if maint  This turns a red-black tree into a [multi]set.  @endif
109*404b540aSrobert       typedef typename _Alloc::template rebind<_Key>::other _Key_alloc_type;
110*404b540aSrobert 
111*404b540aSrobert       typedef _Rb_tree<key_type, value_type, _Identity<value_type>,
112*404b540aSrobert 		       key_compare, _Key_alloc_type> _Rep_type;
113*404b540aSrobert       /// @if maint  The actual tree structure.  @endif
114*404b540aSrobert       _Rep_type _M_t;
115*404b540aSrobert 
116*404b540aSrobert     public:
117*404b540aSrobert       typedef typename _Key_alloc_type::pointer             pointer;
118*404b540aSrobert       typedef typename _Key_alloc_type::const_pointer       const_pointer;
119*404b540aSrobert       typedef typename _Key_alloc_type::reference           reference;
120*404b540aSrobert       typedef typename _Key_alloc_type::const_reference     const_reference;
121*404b540aSrobert       // _GLIBCXX_RESOLVE_LIB_DEFECTS
122*404b540aSrobert       // DR 103. set::iterator is required to be modifiable,
123*404b540aSrobert       // but this allows modification of keys.
124*404b540aSrobert       typedef typename _Rep_type::const_iterator            iterator;
125*404b540aSrobert       typedef typename _Rep_type::const_iterator            const_iterator;
126*404b540aSrobert       typedef typename _Rep_type::const_reverse_iterator    reverse_iterator;
127*404b540aSrobert       typedef typename _Rep_type::const_reverse_iterator    const_reverse_iterator;
128*404b540aSrobert       typedef typename _Rep_type::size_type                 size_type;
129*404b540aSrobert       typedef typename _Rep_type::difference_type           difference_type;
130*404b540aSrobert 
131*404b540aSrobert       // allocation/deallocation
132*404b540aSrobert 
133*404b540aSrobert       /**
134*404b540aSrobert        *  @brief  Default constructor creates no elements.
135*404b540aSrobert        */
136*404b540aSrobert       multiset()
137*404b540aSrobert       : _M_t(_Compare(), allocator_type()) { }
138*404b540aSrobert 
139*404b540aSrobert       explicit
140*404b540aSrobert       multiset(const _Compare& __comp,
141*404b540aSrobert 	       const allocator_type& __a = allocator_type())
142*404b540aSrobert       : _M_t(__comp, __a) { }
143*404b540aSrobert 
144*404b540aSrobert       /**
145*404b540aSrobert        *  @brief  Builds a %multiset from a range.
146*404b540aSrobert        *  @param  first  An input iterator.
147*404b540aSrobert        *  @param  last  An input iterator.
148*404b540aSrobert        *
149*404b540aSrobert        *  Create a %multiset consisting of copies of the elements from
150*404b540aSrobert        *  [first,last).  This is linear in N if the range is already sorted,
151*404b540aSrobert        *  and NlogN otherwise (where N is distance(first,last)).
152*404b540aSrobert        */
153*404b540aSrobert       template <class _InputIterator>
154*404b540aSrobert         multiset(_InputIterator __first, _InputIterator __last)
155*404b540aSrobert 	: _M_t(_Compare(), allocator_type())
156*404b540aSrobert         { _M_t._M_insert_equal(__first, __last); }
157*404b540aSrobert 
158*404b540aSrobert       /**
159*404b540aSrobert        *  @brief  Builds a %multiset from a range.
160*404b540aSrobert        *  @param  first  An input iterator.
161*404b540aSrobert        *  @param  last  An input iterator.
162*404b540aSrobert        *  @param  comp  A comparison functor.
163*404b540aSrobert        *  @param  a  An allocator object.
164*404b540aSrobert        *
165*404b540aSrobert        *  Create a %multiset consisting of copies of the elements from
166*404b540aSrobert        *  [first,last).  This is linear in N if the range is already sorted,
167*404b540aSrobert        *  and NlogN otherwise (where N is distance(first,last)).
168*404b540aSrobert        */
169*404b540aSrobert       template <class _InputIterator>
170*404b540aSrobert         multiset(_InputIterator __first, _InputIterator __last,
171*404b540aSrobert 		 const _Compare& __comp,
172*404b540aSrobert 		 const allocator_type& __a = allocator_type())
173*404b540aSrobert 	: _M_t(__comp, __a)
174*404b540aSrobert         { _M_t._M_insert_equal(__first, __last); }
175*404b540aSrobert 
176*404b540aSrobert       /**
177*404b540aSrobert        *  @brief  %Multiset copy constructor.
178*404b540aSrobert        *  @param  x  A %multiset of identical element and allocator types.
179*404b540aSrobert        *
180*404b540aSrobert        *  The newly-created %multiset uses a copy of the allocation object used
181*404b540aSrobert        *  by @a x.
182*404b540aSrobert        */
183*404b540aSrobert       multiset(const multiset<_Key,_Compare,_Alloc>& __x)
184*404b540aSrobert       : _M_t(__x._M_t) { }
185*404b540aSrobert 
186*404b540aSrobert       /**
187*404b540aSrobert        *  @brief  %Multiset assignment operator.
188*404b540aSrobert        *  @param  x  A %multiset of identical element and allocator types.
189*404b540aSrobert        *
190*404b540aSrobert        *  All the elements of @a x are copied, but unlike the copy constructor,
191*404b540aSrobert        *  the allocator object is not copied.
192*404b540aSrobert        */
193*404b540aSrobert       multiset<_Key,_Compare,_Alloc>&
194*404b540aSrobert       operator=(const multiset<_Key,_Compare,_Alloc>& __x)
195*404b540aSrobert       {
196*404b540aSrobert 	_M_t = __x._M_t;
197*404b540aSrobert 	return *this;
198*404b540aSrobert       }
199*404b540aSrobert 
200*404b540aSrobert       // accessors:
201*404b540aSrobert 
202*404b540aSrobert       ///  Returns the comparison object.
203*404b540aSrobert       key_compare
204*404b540aSrobert       key_comp() const
205*404b540aSrobert       { return _M_t.key_comp(); }
206*404b540aSrobert       ///  Returns the comparison object.
207*404b540aSrobert       value_compare
208*404b540aSrobert       value_comp() const
209*404b540aSrobert       { return _M_t.key_comp(); }
210*404b540aSrobert       ///  Returns the memory allocation object.
211*404b540aSrobert       allocator_type
212*404b540aSrobert       get_allocator() const
213*404b540aSrobert       { return _M_t.get_allocator(); }
214*404b540aSrobert 
215*404b540aSrobert       /**
216*404b540aSrobert        *  Returns a read/write iterator that points to the first element in the
217*404b540aSrobert        *  %multiset.  Iteration is done in ascending order according to the
218*404b540aSrobert        *  keys.
219*404b540aSrobert        */
220*404b540aSrobert       iterator
221*404b540aSrobert       begin() const
222*404b540aSrobert       { return _M_t.begin(); }
223*404b540aSrobert 
224*404b540aSrobert       /**
225*404b540aSrobert        *  Returns a read/write iterator that points one past the last element in
226*404b540aSrobert        *  the %multiset.  Iteration is done in ascending order according to the
227*404b540aSrobert        *  keys.
228*404b540aSrobert        */
229*404b540aSrobert       iterator
230*404b540aSrobert       end() const
231*404b540aSrobert       { return _M_t.end(); }
232*404b540aSrobert 
233*404b540aSrobert       /**
234*404b540aSrobert        *  Returns a read/write reverse iterator that points to the last element
235*404b540aSrobert        *  in the %multiset.  Iteration is done in descending order according to
236*404b540aSrobert        *  the keys.
237*404b540aSrobert        */
238*404b540aSrobert       reverse_iterator
239*404b540aSrobert       rbegin() const
240*404b540aSrobert       { return _M_t.rbegin(); }
241*404b540aSrobert 
242*404b540aSrobert       /**
243*404b540aSrobert        *  Returns a read/write reverse iterator that points to the last element
244*404b540aSrobert        *  in the %multiset.  Iteration is done in descending order according to
245*404b540aSrobert        *  the keys.
246*404b540aSrobert        */
247*404b540aSrobert       reverse_iterator
248*404b540aSrobert       rend() const
249*404b540aSrobert       { return _M_t.rend(); }
250*404b540aSrobert 
251*404b540aSrobert       ///  Returns true if the %set is empty.
252*404b540aSrobert       bool
253*404b540aSrobert       empty() const
254*404b540aSrobert       { return _M_t.empty(); }
255*404b540aSrobert 
256*404b540aSrobert       ///  Returns the size of the %set.
257*404b540aSrobert       size_type
258*404b540aSrobert       size() const
259*404b540aSrobert       { return _M_t.size(); }
260*404b540aSrobert 
261*404b540aSrobert       ///  Returns the maximum size of the %set.
262*404b540aSrobert       size_type
263*404b540aSrobert       max_size() const
264*404b540aSrobert       { return _M_t.max_size(); }
265*404b540aSrobert 
266*404b540aSrobert       /**
267*404b540aSrobert        *  @brief  Swaps data with another %multiset.
268*404b540aSrobert        *  @param  x  A %multiset of the same element and allocator types.
269*404b540aSrobert        *
270*404b540aSrobert        *  This exchanges the elements between two multisets in constant time.
271*404b540aSrobert        *  (It is only swapping a pointer, an integer, and an instance of the @c
272*404b540aSrobert        *  Compare type (which itself is often stateless and empty), so it should
273*404b540aSrobert        *  be quite fast.)
274*404b540aSrobert        *  Note that the global std::swap() function is specialized such that
275*404b540aSrobert        *  std::swap(s1,s2) will feed to this function.
276*404b540aSrobert        */
277*404b540aSrobert       void
278*404b540aSrobert       swap(multiset<_Key, _Compare, _Alloc>& __x)
279*404b540aSrobert       { _M_t.swap(__x._M_t); }
280*404b540aSrobert 
281*404b540aSrobert       // insert/erase
282*404b540aSrobert       /**
283*404b540aSrobert        *  @brief Inserts an element into the %multiset.
284*404b540aSrobert        *  @param  x  Element to be inserted.
285*404b540aSrobert        *  @return An iterator that points to the inserted element.
286*404b540aSrobert        *
287*404b540aSrobert        *  This function inserts an element into the %multiset.  Contrary
288*404b540aSrobert        *  to a std::set the %multiset does not rely on unique keys and thus
289*404b540aSrobert        *  multiple copies of the same element can be inserted.
290*404b540aSrobert        *
291*404b540aSrobert        *  Insertion requires logarithmic time.
292*404b540aSrobert        */
293*404b540aSrobert       iterator
294*404b540aSrobert       insert(const value_type& __x)
295*404b540aSrobert       { return _M_t._M_insert_equal(__x); }
296*404b540aSrobert 
297*404b540aSrobert       /**
298*404b540aSrobert        *  @brief Inserts an element into the %multiset.
299*404b540aSrobert        *  @param  position  An iterator that serves as a hint as to where the
300*404b540aSrobert        *                    element should be inserted.
301*404b540aSrobert        *  @param  x  Element to be inserted.
302*404b540aSrobert        *  @return An iterator that points to the inserted element.
303*404b540aSrobert        *
304*404b540aSrobert        *  This function inserts an element into the %multiset.  Contrary
305*404b540aSrobert        *  to a std::set the %multiset does not rely on unique keys and thus
306*404b540aSrobert        *  multiple copies of the same element can be inserted.
307*404b540aSrobert        *
308*404b540aSrobert        *  Note that the first parameter is only a hint and can potentially
309*404b540aSrobert        *  improve the performance of the insertion process.  A bad hint would
310*404b540aSrobert        *  cause no gains in efficiency.
311*404b540aSrobert        *
312*404b540aSrobert        *  See http://gcc.gnu.org/onlinedocs/libstdc++/23_containers/howto.html#4
313*404b540aSrobert        *  for more on "hinting".
314*404b540aSrobert        *
315*404b540aSrobert        *  Insertion requires logarithmic time (if the hint is not taken).
316*404b540aSrobert        */
317*404b540aSrobert       iterator
318*404b540aSrobert       insert(iterator __position, const value_type& __x)
319*404b540aSrobert       { return _M_t._M_insert_equal(__position, __x); }
320*404b540aSrobert 
321*404b540aSrobert       /**
322*404b540aSrobert        *  @brief A template function that attemps to insert a range of elements.
323*404b540aSrobert        *  @param  first  Iterator pointing to the start of the range to be
324*404b540aSrobert        *                 inserted.
325*404b540aSrobert        *  @param  last  Iterator pointing to the end of the range.
326*404b540aSrobert        *
327*404b540aSrobert        *  Complexity similar to that of the range constructor.
328*404b540aSrobert        */
329*404b540aSrobert       template <class _InputIterator>
330*404b540aSrobert         void
331*404b540aSrobert         insert(_InputIterator __first, _InputIterator __last)
332*404b540aSrobert         { _M_t._M_insert_equal(__first, __last); }
333*404b540aSrobert 
334*404b540aSrobert       /**
335*404b540aSrobert        *  @brief Erases an element from a %multiset.
336*404b540aSrobert        *  @param  position  An iterator pointing to the element to be erased.
337*404b540aSrobert        *
338*404b540aSrobert        *  This function erases an element, pointed to by the given iterator,
339*404b540aSrobert        *  from a %multiset.  Note that this function only erases the element,
340*404b540aSrobert        *  and that if the element is itself a pointer, the pointed-to memory is
341*404b540aSrobert        *  not touched in any way.  Managing the pointer is the user's
342*404b540aSrobert        *  responsibilty.
343*404b540aSrobert        */
344*404b540aSrobert       void
345*404b540aSrobert       erase(iterator __position)
346*404b540aSrobert       { _M_t.erase(__position); }
347*404b540aSrobert 
348*404b540aSrobert       /**
349*404b540aSrobert        *  @brief Erases elements according to the provided key.
350*404b540aSrobert        *  @param  x  Key of element to be erased.
351*404b540aSrobert        *  @return  The number of elements erased.
352*404b540aSrobert        *
353*404b540aSrobert        *  This function erases all elements located by the given key from a
354*404b540aSrobert        *  %multiset.
355*404b540aSrobert        *  Note that this function only erases the element, and that if
356*404b540aSrobert        *  the element is itself a pointer, the pointed-to memory is not touched
357*404b540aSrobert        *  in any way.  Managing the pointer is the user's responsibilty.
358*404b540aSrobert        */
359*404b540aSrobert       size_type
360*404b540aSrobert       erase(const key_type& __x)
361*404b540aSrobert       { return _M_t.erase(__x); }
362*404b540aSrobert 
363*404b540aSrobert       /**
364*404b540aSrobert        *  @brief Erases a [first,last) range of elements from a %multiset.
365*404b540aSrobert        *  @param  first  Iterator pointing to the start of the range to be
366*404b540aSrobert        *                 erased.
367*404b540aSrobert        *  @param  last  Iterator pointing to the end of the range to be erased.
368*404b540aSrobert        *
369*404b540aSrobert        *  This function erases a sequence of elements from a %multiset.
370*404b540aSrobert        *  Note that this function only erases the elements, and that if
371*404b540aSrobert        *  the elements themselves are pointers, the pointed-to memory is not
372*404b540aSrobert        *  touched in any way.  Managing the pointer is the user's responsibilty.
373*404b540aSrobert        */
374*404b540aSrobert       void
375*404b540aSrobert       erase(iterator __first, iterator __last)
376*404b540aSrobert       { _M_t.erase(__first, __last); }
377*404b540aSrobert 
378*404b540aSrobert       /**
379*404b540aSrobert        *  Erases all elements in a %multiset.  Note that this function only
380*404b540aSrobert        *  erases the elements, and that if the elements themselves are pointers,
381*404b540aSrobert        *  the pointed-to memory is not touched in any way.  Managing the pointer
382*404b540aSrobert        *  is the user's responsibilty.
383*404b540aSrobert        */
384*404b540aSrobert       void
385*404b540aSrobert       clear()
386*404b540aSrobert       { _M_t.clear(); }
387*404b540aSrobert 
388*404b540aSrobert       // multiset operations:
389*404b540aSrobert 
390*404b540aSrobert       /**
391*404b540aSrobert        *  @brief Finds the number of elements with given key.
392*404b540aSrobert        *  @param  x  Key of elements to be located.
393*404b540aSrobert        *  @return Number of elements with specified key.
394*404b540aSrobert        */
395*404b540aSrobert       size_type
396*404b540aSrobert       count(const key_type& __x) const
397*404b540aSrobert       { return _M_t.count(__x); }
398*404b540aSrobert 
399*404b540aSrobert       // _GLIBCXX_RESOLVE_LIB_DEFECTS
400*404b540aSrobert       // 214.  set::find() missing const overload
401*404b540aSrobert       //@{
402*404b540aSrobert       /**
403*404b540aSrobert        *  @brief Tries to locate an element in a %set.
404*404b540aSrobert        *  @param  x  Element to be located.
405*404b540aSrobert        *  @return  Iterator pointing to sought-after element, or end() if not
406*404b540aSrobert        *           found.
407*404b540aSrobert        *
408*404b540aSrobert        *  This function takes a key and tries to locate the element with which
409*404b540aSrobert        *  the key matches.  If successful the function returns an iterator
410*404b540aSrobert        *  pointing to the sought after element.  If unsuccessful it returns the
411*404b540aSrobert        *  past-the-end ( @c end() ) iterator.
412*404b540aSrobert        */
413*404b540aSrobert       iterator
414*404b540aSrobert       find(const key_type& __x)
415*404b540aSrobert       { return _M_t.find(__x); }
416*404b540aSrobert 
417*404b540aSrobert       const_iterator
418*404b540aSrobert       find(const key_type& __x) const
419*404b540aSrobert       { return _M_t.find(__x); }
420*404b540aSrobert       //@}
421*404b540aSrobert 
422*404b540aSrobert       //@{
423*404b540aSrobert       /**
424*404b540aSrobert        *  @brief Finds the beginning of a subsequence matching given key.
425*404b540aSrobert        *  @param  x  Key to be located.
426*404b540aSrobert        *  @return  Iterator pointing to first element equal to or greater
427*404b540aSrobert        *           than key, or end().
428*404b540aSrobert        *
429*404b540aSrobert        *  This function returns the first element of a subsequence of elements
430*404b540aSrobert        *  that matches the given key.  If unsuccessful it returns an iterator
431*404b540aSrobert        *  pointing to the first element that has a greater value than given key
432*404b540aSrobert        *  or end() if no such element exists.
433*404b540aSrobert        */
434*404b540aSrobert       iterator
435*404b540aSrobert       lower_bound(const key_type& __x)
436*404b540aSrobert       { return _M_t.lower_bound(__x); }
437*404b540aSrobert 
438*404b540aSrobert       const_iterator
439*404b540aSrobert       lower_bound(const key_type& __x) const
440*404b540aSrobert       { return _M_t.lower_bound(__x); }
441*404b540aSrobert       //@}
442*404b540aSrobert 
443*404b540aSrobert       //@{
444*404b540aSrobert       /**
445*404b540aSrobert        *  @brief Finds the end of a subsequence matching given key.
446*404b540aSrobert        *  @param  x  Key to be located.
447*404b540aSrobert        *  @return Iterator pointing to the first element
448*404b540aSrobert        *          greater than key, or end().
449*404b540aSrobert        */
450*404b540aSrobert       iterator
451*404b540aSrobert       upper_bound(const key_type& __x)
452*404b540aSrobert       { return _M_t.upper_bound(__x); }
453*404b540aSrobert 
454*404b540aSrobert       const_iterator
455*404b540aSrobert       upper_bound(const key_type& __x) const
456*404b540aSrobert       { return _M_t.upper_bound(__x); }
457*404b540aSrobert       //@}
458*404b540aSrobert 
459*404b540aSrobert       //@{
460*404b540aSrobert       /**
461*404b540aSrobert        *  @brief Finds a subsequence matching given key.
462*404b540aSrobert        *  @param  x  Key to be located.
463*404b540aSrobert        *  @return  Pair of iterators that possibly points to the subsequence
464*404b540aSrobert        *           matching given key.
465*404b540aSrobert        *
466*404b540aSrobert        *  This function is equivalent to
467*404b540aSrobert        *  @code
468*404b540aSrobert        *    std::make_pair(c.lower_bound(val),
469*404b540aSrobert        *                   c.upper_bound(val))
470*404b540aSrobert        *  @endcode
471*404b540aSrobert        *  (but is faster than making the calls separately).
472*404b540aSrobert        *
473*404b540aSrobert        *  This function probably only makes sense for multisets.
474*404b540aSrobert        */
475*404b540aSrobert       std::pair<iterator, iterator>
476*404b540aSrobert       equal_range(const key_type& __x)
477*404b540aSrobert       { return _M_t.equal_range(__x); }
478*404b540aSrobert 
479*404b540aSrobert       std::pair<const_iterator, const_iterator>
480*404b540aSrobert       equal_range(const key_type& __x) const
481*404b540aSrobert       { return _M_t.equal_range(__x); }
482*404b540aSrobert 
483*404b540aSrobert       template <class _K1, class _C1, class _A1>
484*404b540aSrobert         friend bool
485*404b540aSrobert         operator== (const multiset<_K1, _C1, _A1>&,
486*404b540aSrobert 		    const multiset<_K1, _C1, _A1>&);
487*404b540aSrobert 
488*404b540aSrobert       template <class _K1, class _C1, class _A1>
489*404b540aSrobert         friend bool
490*404b540aSrobert         operator< (const multiset<_K1, _C1, _A1>&,
491*404b540aSrobert 		   const multiset<_K1, _C1, _A1>&);
492*404b540aSrobert     };
493*404b540aSrobert 
494*404b540aSrobert   /**
495*404b540aSrobert    *  @brief  Multiset equality comparison.
496*404b540aSrobert    *  @param  x  A %multiset.
497*404b540aSrobert    *  @param  y  A %multiset of the same type as @a x.
498*404b540aSrobert    *  @return  True iff the size and elements of the multisets are equal.
499*404b540aSrobert    *
500*404b540aSrobert    *  This is an equivalence relation.  It is linear in the size of the
501*404b540aSrobert    *  multisets.
502*404b540aSrobert    *  Multisets are considered equivalent if their sizes are equal, and if
503*404b540aSrobert    *  corresponding elements compare equal.
504*404b540aSrobert   */
505*404b540aSrobert   template <class _Key, class _Compare, class _Alloc>
506*404b540aSrobert     inline bool
507*404b540aSrobert     operator==(const multiset<_Key, _Compare, _Alloc>& __x,
508*404b540aSrobert 	       const multiset<_Key, _Compare, _Alloc>& __y)
509*404b540aSrobert     { return __x._M_t == __y._M_t; }
510*404b540aSrobert 
511*404b540aSrobert   /**
512*404b540aSrobert    *  @brief  Multiset ordering relation.
513*404b540aSrobert    *  @param  x  A %multiset.
514*404b540aSrobert    *  @param  y  A %multiset of the same type as @a x.
515*404b540aSrobert    *  @return  True iff @a x is lexicographically less than @a y.
516*404b540aSrobert    *
517*404b540aSrobert    *  This is a total ordering relation.  It is linear in the size of the
518*404b540aSrobert    *  maps.  The elements must be comparable with @c <.
519*404b540aSrobert    *
520*404b540aSrobert    *  See std::lexicographical_compare() for how the determination is made.
521*404b540aSrobert   */
522*404b540aSrobert   template <class _Key, class _Compare, class _Alloc>
523*404b540aSrobert     inline bool
524*404b540aSrobert     operator<(const multiset<_Key, _Compare, _Alloc>& __x,
525*404b540aSrobert 	      const multiset<_Key, _Compare, _Alloc>& __y)
526*404b540aSrobert     { return __x._M_t < __y._M_t; }
527*404b540aSrobert 
528*404b540aSrobert   ///  Returns !(x == y).
529*404b540aSrobert   template <class _Key, class _Compare, class _Alloc>
530*404b540aSrobert     inline bool
531*404b540aSrobert     operator!=(const multiset<_Key, _Compare, _Alloc>& __x,
532*404b540aSrobert 	       const multiset<_Key, _Compare, _Alloc>& __y)
533*404b540aSrobert     { return !(__x == __y); }
534*404b540aSrobert 
535*404b540aSrobert   ///  Returns y < x.
536*404b540aSrobert   template <class _Key, class _Compare, class _Alloc>
537*404b540aSrobert     inline bool
538*404b540aSrobert     operator>(const multiset<_Key,_Compare,_Alloc>& __x,
539*404b540aSrobert 	      const multiset<_Key,_Compare,_Alloc>& __y)
540*404b540aSrobert     { return __y < __x; }
541*404b540aSrobert 
542*404b540aSrobert   ///  Returns !(y < x)
543*404b540aSrobert   template <class _Key, class _Compare, class _Alloc>
544*404b540aSrobert     inline bool
545*404b540aSrobert     operator<=(const multiset<_Key, _Compare, _Alloc>& __x,
546*404b540aSrobert 	       const multiset<_Key, _Compare, _Alloc>& __y)
547*404b540aSrobert     { return !(__y < __x); }
548*404b540aSrobert 
549*404b540aSrobert   ///  Returns !(x < y)
550*404b540aSrobert   template <class _Key, class _Compare, class _Alloc>
551*404b540aSrobert     inline bool
552*404b540aSrobert     operator>=(const multiset<_Key, _Compare, _Alloc>& __x,
553*404b540aSrobert 	       const multiset<_Key, _Compare, _Alloc>& __y)
554*404b540aSrobert     { return !(__x < __y); }
555*404b540aSrobert 
556*404b540aSrobert   /// See std::multiset::swap().
557*404b540aSrobert   template <class _Key, class _Compare, class _Alloc>
558*404b540aSrobert     inline void
swap(multiset<_Key,_Compare,_Alloc> & __x,multiset<_Key,_Compare,_Alloc> & __y)559*404b540aSrobert     swap(multiset<_Key, _Compare, _Alloc>& __x,
560*404b540aSrobert 	 multiset<_Key, _Compare, _Alloc>& __y)
561*404b540aSrobert     { __x.swap(__y); }
562*404b540aSrobert 
563*404b540aSrobert _GLIBCXX_END_NESTED_NAMESPACE
564*404b540aSrobert 
565*404b540aSrobert #endif /* _MULTISET_H */
566