xref: /openbsd-src/gnu/gcc/libstdc++-v3/include/bits/stl_multimap.h (revision 404b540a9034ac75a6199ad1a32d1bbc7a0d4210)
1*404b540aSrobert // Multimap 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,1997
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_multimap.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 _MULTIMAP_H
62*404b540aSrobert #define _MULTIMAP_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 (key,value) pairs, which can be
70*404b540aSrobert    *  retrieved based on a key, 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 multimap<Key,T> the key_type is Key, the mapped_type
79*404b540aSrobert    *  is T, and the value_type is std::pair<const Key,T>.
80*404b540aSrobert    *
81*404b540aSrobert    *  Multimaps support bidirectional iterators.
82*404b540aSrobert    *
83*404b540aSrobert    *  @if maint
84*404b540aSrobert    *  The private tree data is declared exactly the same way for map and
85*404b540aSrobert    *  multimap; the distinction is made entirely in how the tree functions are
86*404b540aSrobert    *  called (*_unique versus *_equal, same as the standard).
87*404b540aSrobert    *  @endif
88*404b540aSrobert   */
89*404b540aSrobert   template <typename _Key, typename _Tp,
90*404b540aSrobert 	    typename _Compare = std::less<_Key>,
91*404b540aSrobert 	    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> > >
92*404b540aSrobert     class multimap
93*404b540aSrobert     {
94*404b540aSrobert     public:
95*404b540aSrobert       typedef _Key                                          key_type;
96*404b540aSrobert       typedef _Tp                                           mapped_type;
97*404b540aSrobert       typedef std::pair<const _Key, _Tp>                    value_type;
98*404b540aSrobert       typedef _Compare                                      key_compare;
99*404b540aSrobert       typedef _Alloc                                        allocator_type;
100*404b540aSrobert 
101*404b540aSrobert     private:
102*404b540aSrobert       // concept requirements
103*404b540aSrobert       typedef typename _Alloc::value_type                   _Alloc_value_type;
104*404b540aSrobert       __glibcxx_class_requires(_Tp, _SGIAssignableConcept)
105*404b540aSrobert       __glibcxx_class_requires4(_Compare, bool, _Key, _Key,
106*404b540aSrobert 				_BinaryFunctionConcept)
107*404b540aSrobert       __glibcxx_class_requires2(value_type, _Alloc_value_type, _SameTypeConcept)
108*404b540aSrobert 
109*404b540aSrobert     public:
110*404b540aSrobert       class value_compare
111*404b540aSrobert       : public std::binary_function<value_type, value_type, bool>
112*404b540aSrobert       {
113*404b540aSrobert 	friend class multimap<_Key, _Tp, _Compare, _Alloc>;
114*404b540aSrobert       protected:
115*404b540aSrobert 	_Compare comp;
116*404b540aSrobert 
117*404b540aSrobert 	value_compare(_Compare __c)
118*404b540aSrobert 	: comp(__c) { }
119*404b540aSrobert 
120*404b540aSrobert       public:
121*404b540aSrobert 	bool operator()(const value_type& __x, const value_type& __y) const
122*404b540aSrobert 	{ return comp(__x.first, __y.first); }
123*404b540aSrobert       };
124*404b540aSrobert 
125*404b540aSrobert     private:
126*404b540aSrobert       /// @if maint  This turns a red-black tree into a [multi]map.  @endif
127*404b540aSrobert       typedef typename _Alloc::template rebind<value_type>::other
128*404b540aSrobert         _Pair_alloc_type;
129*404b540aSrobert 
130*404b540aSrobert       typedef _Rb_tree<key_type, value_type, _Select1st<value_type>,
131*404b540aSrobert 		       key_compare, _Pair_alloc_type> _Rep_type;
132*404b540aSrobert       /// @if maint  The actual tree structure.  @endif
133*404b540aSrobert       _Rep_type _M_t;
134*404b540aSrobert 
135*404b540aSrobert     public:
136*404b540aSrobert       // many of these are specified differently in ISO, but the following are
137*404b540aSrobert       // "functionally equivalent"
138*404b540aSrobert       typedef typename _Pair_alloc_type::pointer         pointer;
139*404b540aSrobert       typedef typename _Pair_alloc_type::const_pointer   const_pointer;
140*404b540aSrobert       typedef typename _Pair_alloc_type::reference       reference;
141*404b540aSrobert       typedef typename _Pair_alloc_type::const_reference const_reference;
142*404b540aSrobert       typedef typename _Rep_type::iterator               iterator;
143*404b540aSrobert       typedef typename _Rep_type::const_iterator         const_iterator;
144*404b540aSrobert       typedef typename _Rep_type::size_type              size_type;
145*404b540aSrobert       typedef typename _Rep_type::difference_type        difference_type;
146*404b540aSrobert       typedef typename _Rep_type::reverse_iterator       reverse_iterator;
147*404b540aSrobert       typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
148*404b540aSrobert 
149*404b540aSrobert       // [23.3.2] construct/copy/destroy
150*404b540aSrobert       // (get_allocator() is also listed in this section)
151*404b540aSrobert       /**
152*404b540aSrobert        *  @brief  Default constructor creates no elements.
153*404b540aSrobert        */
154*404b540aSrobert       multimap()
155*404b540aSrobert       : _M_t(_Compare(), allocator_type()) { }
156*404b540aSrobert 
157*404b540aSrobert       // for some reason this was made a separate function
158*404b540aSrobert       /**
159*404b540aSrobert        *  @brief  Default constructor creates no elements.
160*404b540aSrobert        */
161*404b540aSrobert       explicit
162*404b540aSrobert       multimap(const _Compare& __comp,
163*404b540aSrobert 	       const allocator_type& __a = allocator_type())
164*404b540aSrobert       : _M_t(__comp, __a) { }
165*404b540aSrobert 
166*404b540aSrobert       /**
167*404b540aSrobert        *  @brief  %Multimap copy constructor.
168*404b540aSrobert        *  @param  x  A %multimap of identical element and allocator types.
169*404b540aSrobert        *
170*404b540aSrobert        *  The newly-created %multimap uses a copy of the allocation object used
171*404b540aSrobert        *  by @a x.
172*404b540aSrobert        */
173*404b540aSrobert       multimap(const multimap& __x)
174*404b540aSrobert       : _M_t(__x._M_t) { }
175*404b540aSrobert 
176*404b540aSrobert       /**
177*404b540aSrobert        *  @brief  Builds a %multimap from a range.
178*404b540aSrobert        *  @param  first  An input iterator.
179*404b540aSrobert        *  @param  last  An input iterator.
180*404b540aSrobert        *
181*404b540aSrobert        *  Create a %multimap consisting of copies of the elements from
182*404b540aSrobert        *  [first,last).  This is linear in N if the range is already sorted,
183*404b540aSrobert        *  and NlogN otherwise (where N is distance(first,last)).
184*404b540aSrobert        */
185*404b540aSrobert       template <typename _InputIterator>
186*404b540aSrobert         multimap(_InputIterator __first, _InputIterator __last)
187*404b540aSrobert 	: _M_t(_Compare(), allocator_type())
188*404b540aSrobert         { _M_t._M_insert_equal(__first, __last); }
189*404b540aSrobert 
190*404b540aSrobert       /**
191*404b540aSrobert        *  @brief  Builds a %multimap from a range.
192*404b540aSrobert        *  @param  first  An input iterator.
193*404b540aSrobert        *  @param  last  An input iterator.
194*404b540aSrobert        *  @param  comp  A comparison functor.
195*404b540aSrobert        *  @param  a  An allocator object.
196*404b540aSrobert        *
197*404b540aSrobert        *  Create a %multimap consisting of copies of the elements from
198*404b540aSrobert        *  [first,last).  This is linear in N if the range is already sorted,
199*404b540aSrobert        *  and NlogN otherwise (where N is distance(first,last)).
200*404b540aSrobert        */
201*404b540aSrobert       template <typename _InputIterator>
202*404b540aSrobert         multimap(_InputIterator __first, _InputIterator __last,
203*404b540aSrobert 		 const _Compare& __comp,
204*404b540aSrobert 		 const allocator_type& __a = allocator_type())
205*404b540aSrobert         : _M_t(__comp, __a)
206*404b540aSrobert         { _M_t._M_insert_equal(__first, __last); }
207*404b540aSrobert 
208*404b540aSrobert       // FIXME There is no dtor declared, but we should have something generated
209*404b540aSrobert       // by Doxygen.  I don't know what tags to add to this paragraph to make
210*404b540aSrobert       // that happen:
211*404b540aSrobert       /**
212*404b540aSrobert        *  The dtor only erases the elements, and note that if the elements
213*404b540aSrobert        *  themselves are pointers, the pointed-to memory is not touched in any
214*404b540aSrobert        *  way.  Managing the pointer is the user's responsibilty.
215*404b540aSrobert        */
216*404b540aSrobert 
217*404b540aSrobert       /**
218*404b540aSrobert        *  @brief  %Multimap assignment operator.
219*404b540aSrobert        *  @param  x  A %multimap of identical element and allocator types.
220*404b540aSrobert        *
221*404b540aSrobert        *  All the elements of @a x are copied, but unlike the copy constructor,
222*404b540aSrobert        *  the allocator object is not copied.
223*404b540aSrobert        */
224*404b540aSrobert       multimap&
225*404b540aSrobert       operator=(const multimap& __x)
226*404b540aSrobert       {
227*404b540aSrobert 	_M_t = __x._M_t;
228*404b540aSrobert 	return *this;
229*404b540aSrobert       }
230*404b540aSrobert 
231*404b540aSrobert       /// Get a copy of the memory allocation object.
232*404b540aSrobert       allocator_type
233*404b540aSrobert       get_allocator() const
234*404b540aSrobert       { return _M_t.get_allocator(); }
235*404b540aSrobert 
236*404b540aSrobert       // iterators
237*404b540aSrobert       /**
238*404b540aSrobert        *  Returns a read/write iterator that points to the first pair in the
239*404b540aSrobert        *  %multimap.  Iteration is done in ascending order according to the
240*404b540aSrobert        *  keys.
241*404b540aSrobert        */
242*404b540aSrobert       iterator
243*404b540aSrobert       begin()
244*404b540aSrobert       { return _M_t.begin(); }
245*404b540aSrobert 
246*404b540aSrobert       /**
247*404b540aSrobert        *  Returns a read-only (constant) iterator that points to the first pair
248*404b540aSrobert        *  in the %multimap.  Iteration is done in ascending order according to
249*404b540aSrobert        *  the keys.
250*404b540aSrobert        */
251*404b540aSrobert       const_iterator
252*404b540aSrobert       begin() const
253*404b540aSrobert       { return _M_t.begin(); }
254*404b540aSrobert 
255*404b540aSrobert       /**
256*404b540aSrobert        *  Returns a read/write iterator that points one past the last pair in
257*404b540aSrobert        *  the %multimap.  Iteration is done in ascending order according to the
258*404b540aSrobert        *  keys.
259*404b540aSrobert        */
260*404b540aSrobert       iterator
261*404b540aSrobert       end()
262*404b540aSrobert       { return _M_t.end(); }
263*404b540aSrobert 
264*404b540aSrobert       /**
265*404b540aSrobert        *  Returns a read-only (constant) iterator that points one past the last
266*404b540aSrobert        *  pair in the %multimap.  Iteration is done in ascending order according
267*404b540aSrobert        *  to the keys.
268*404b540aSrobert        */
269*404b540aSrobert       const_iterator
270*404b540aSrobert       end() const
271*404b540aSrobert       { return _M_t.end(); }
272*404b540aSrobert 
273*404b540aSrobert       /**
274*404b540aSrobert        *  Returns a read/write reverse iterator that points to the last pair in
275*404b540aSrobert        *  the %multimap.  Iteration is done in descending order according to the
276*404b540aSrobert        *  keys.
277*404b540aSrobert        */
278*404b540aSrobert       reverse_iterator
279*404b540aSrobert       rbegin()
280*404b540aSrobert       { return _M_t.rbegin(); }
281*404b540aSrobert 
282*404b540aSrobert       /**
283*404b540aSrobert        *  Returns a read-only (constant) reverse iterator that points to the
284*404b540aSrobert        *  last pair in the %multimap.  Iteration is done in descending order
285*404b540aSrobert        *  according to the keys.
286*404b540aSrobert        */
287*404b540aSrobert       const_reverse_iterator
288*404b540aSrobert       rbegin() const
289*404b540aSrobert       { return _M_t.rbegin(); }
290*404b540aSrobert 
291*404b540aSrobert       /**
292*404b540aSrobert        *  Returns a read/write reverse iterator that points to one before the
293*404b540aSrobert        *  first pair in the %multimap.  Iteration is done in descending order
294*404b540aSrobert        *  according to the keys.
295*404b540aSrobert        */
296*404b540aSrobert       reverse_iterator
297*404b540aSrobert       rend()
298*404b540aSrobert       { return _M_t.rend(); }
299*404b540aSrobert 
300*404b540aSrobert       /**
301*404b540aSrobert        *  Returns a read-only (constant) reverse iterator that points to one
302*404b540aSrobert        *  before the first pair in the %multimap.  Iteration is done in
303*404b540aSrobert        *  descending order according to the keys.
304*404b540aSrobert        */
305*404b540aSrobert       const_reverse_iterator
306*404b540aSrobert       rend() const
307*404b540aSrobert       { return _M_t.rend(); }
308*404b540aSrobert 
309*404b540aSrobert       // capacity
310*404b540aSrobert       /** Returns true if the %multimap is empty.  */
311*404b540aSrobert       bool
312*404b540aSrobert       empty() const
313*404b540aSrobert       { return _M_t.empty(); }
314*404b540aSrobert 
315*404b540aSrobert       /** Returns the size of the %multimap.  */
316*404b540aSrobert       size_type
317*404b540aSrobert       size() const
318*404b540aSrobert       { return _M_t.size(); }
319*404b540aSrobert 
320*404b540aSrobert       /** Returns the maximum size of the %multimap.  */
321*404b540aSrobert       size_type
322*404b540aSrobert       max_size() const
323*404b540aSrobert       { return _M_t.max_size(); }
324*404b540aSrobert 
325*404b540aSrobert       // modifiers
326*404b540aSrobert       /**
327*404b540aSrobert        *  @brief Inserts a std::pair into the %multimap.
328*404b540aSrobert        *  @param  x  Pair to be inserted (see std::make_pair for easy creation
329*404b540aSrobert        *             of pairs).
330*404b540aSrobert        *  @return An iterator that points to the inserted (key,value) pair.
331*404b540aSrobert        *
332*404b540aSrobert        *  This function inserts a (key, value) pair into the %multimap.
333*404b540aSrobert        *  Contrary to a std::map the %multimap does not rely on unique keys and
334*404b540aSrobert        *  thus multiple pairs with the same key can be inserted.
335*404b540aSrobert        *
336*404b540aSrobert        *  Insertion requires logarithmic time.
337*404b540aSrobert        */
338*404b540aSrobert       iterator
339*404b540aSrobert       insert(const value_type& __x)
340*404b540aSrobert       { return _M_t._M_insert_equal(__x); }
341*404b540aSrobert 
342*404b540aSrobert       /**
343*404b540aSrobert        *  @brief Inserts a std::pair into the %multimap.
344*404b540aSrobert        *  @param  position  An iterator that serves as a hint as to where the
345*404b540aSrobert        *                    pair should be inserted.
346*404b540aSrobert        *  @param  x  Pair to be inserted (see std::make_pair for easy creation
347*404b540aSrobert        *             of pairs).
348*404b540aSrobert        *  @return An iterator that points to the inserted (key,value) pair.
349*404b540aSrobert        *
350*404b540aSrobert        *  This function inserts a (key, value) pair into the %multimap.
351*404b540aSrobert        *  Contrary to a std::map the %multimap does not rely on unique keys and
352*404b540aSrobert        *  thus multiple pairs with the same key can be inserted.
353*404b540aSrobert        *  Note that the first parameter is only a hint and can potentially
354*404b540aSrobert        *  improve the performance of the insertion process.  A bad hint would
355*404b540aSrobert        *  cause no gains in efficiency.
356*404b540aSrobert        *
357*404b540aSrobert        *  See http://gcc.gnu.org/onlinedocs/libstdc++/23_containers/howto.html#4
358*404b540aSrobert        *  for more on "hinting".
359*404b540aSrobert        *
360*404b540aSrobert        *  Insertion requires logarithmic time (if the hint is not taken).
361*404b540aSrobert        */
362*404b540aSrobert       iterator
363*404b540aSrobert       insert(iterator __position, const value_type& __x)
364*404b540aSrobert       { return _M_t._M_insert_equal(__position, __x); }
365*404b540aSrobert 
366*404b540aSrobert       /**
367*404b540aSrobert        *  @brief A template function that attemps to insert a range of elements.
368*404b540aSrobert        *  @param  first  Iterator pointing to the start of the range to be
369*404b540aSrobert        *                 inserted.
370*404b540aSrobert        *  @param  last  Iterator pointing to the end of the range.
371*404b540aSrobert        *
372*404b540aSrobert        *  Complexity similar to that of the range constructor.
373*404b540aSrobert        */
374*404b540aSrobert       template <typename _InputIterator>
375*404b540aSrobert         void
376*404b540aSrobert         insert(_InputIterator __first, _InputIterator __last)
377*404b540aSrobert         { _M_t._M_insert_equal(__first, __last); }
378*404b540aSrobert 
379*404b540aSrobert       /**
380*404b540aSrobert        *  @brief Erases an element from a %multimap.
381*404b540aSrobert        *  @param  position  An iterator pointing to the element to be erased.
382*404b540aSrobert        *
383*404b540aSrobert        *  This function erases an element, pointed to by the given iterator,
384*404b540aSrobert        *  from a %multimap.  Note that this function only erases the element,
385*404b540aSrobert        *  and that if the element is itself a pointer, the pointed-to memory is
386*404b540aSrobert        *  not touched in any way.  Managing the pointer is the user's
387*404b540aSrobert        *  responsibilty.
388*404b540aSrobert        */
389*404b540aSrobert       void
390*404b540aSrobert       erase(iterator __position)
391*404b540aSrobert       { _M_t.erase(__position); }
392*404b540aSrobert 
393*404b540aSrobert       /**
394*404b540aSrobert        *  @brief Erases elements according to the provided key.
395*404b540aSrobert        *  @param  x  Key of element to be erased.
396*404b540aSrobert        *  @return  The number of elements erased.
397*404b540aSrobert        *
398*404b540aSrobert        *  This function erases all elements located by the given key from a
399*404b540aSrobert        *  %multimap.
400*404b540aSrobert        *  Note that this function only erases the element, and that if
401*404b540aSrobert        *  the element is itself a pointer, the pointed-to memory is not touched
402*404b540aSrobert        *  in any way.  Managing the pointer is the user's responsibilty.
403*404b540aSrobert        */
404*404b540aSrobert       size_type
405*404b540aSrobert       erase(const key_type& __x)
406*404b540aSrobert       { return _M_t.erase(__x); }
407*404b540aSrobert 
408*404b540aSrobert       /**
409*404b540aSrobert        *  @brief Erases a [first,last) range of elements from a %multimap.
410*404b540aSrobert        *  @param  first  Iterator pointing to the start of the range to be
411*404b540aSrobert        *                 erased.
412*404b540aSrobert        *  @param  last  Iterator pointing to the end of the range to be erased.
413*404b540aSrobert        *
414*404b540aSrobert        *  This function erases a sequence of elements from a %multimap.
415*404b540aSrobert        *  Note that this function only erases the elements, and that if
416*404b540aSrobert        *  the elements themselves are pointers, the pointed-to memory is not
417*404b540aSrobert        *  touched in any way.  Managing the pointer is the user's responsibilty.
418*404b540aSrobert        */
419*404b540aSrobert       void
420*404b540aSrobert       erase(iterator __first, iterator __last)
421*404b540aSrobert       { _M_t.erase(__first, __last); }
422*404b540aSrobert 
423*404b540aSrobert       /**
424*404b540aSrobert        *  @brief  Swaps data with another %multimap.
425*404b540aSrobert        *  @param  x  A %multimap of the same element and allocator types.
426*404b540aSrobert        *
427*404b540aSrobert        *  This exchanges the elements between two multimaps in constant time.
428*404b540aSrobert        *  (It is only swapping a pointer, an integer, and an instance of
429*404b540aSrobert        *  the @c Compare type (which itself is often stateless and empty), so it
430*404b540aSrobert        *  should be quite fast.)
431*404b540aSrobert        *  Note that the global std::swap() function is specialized such that
432*404b540aSrobert        *  std::swap(m1,m2) will feed to this function.
433*404b540aSrobert        */
434*404b540aSrobert       void
435*404b540aSrobert       swap(multimap& __x)
436*404b540aSrobert       { _M_t.swap(__x._M_t); }
437*404b540aSrobert 
438*404b540aSrobert       /**
439*404b540aSrobert        *  Erases all elements in a %multimap.  Note that this function only
440*404b540aSrobert        *  erases the elements, and that if the elements themselves are pointers,
441*404b540aSrobert        *  the pointed-to memory is not touched in any way.  Managing the pointer
442*404b540aSrobert        *  is the user's responsibilty.
443*404b540aSrobert        */
444*404b540aSrobert       void
445*404b540aSrobert       clear()
446*404b540aSrobert       { _M_t.clear(); }
447*404b540aSrobert 
448*404b540aSrobert       // observers
449*404b540aSrobert       /**
450*404b540aSrobert        *  Returns the key comparison object out of which the %multimap
451*404b540aSrobert        *  was constructed.
452*404b540aSrobert        */
453*404b540aSrobert       key_compare
454*404b540aSrobert       key_comp() const
455*404b540aSrobert       { return _M_t.key_comp(); }
456*404b540aSrobert 
457*404b540aSrobert       /**
458*404b540aSrobert        *  Returns a value comparison object, built from the key comparison
459*404b540aSrobert        *  object out of which the %multimap was constructed.
460*404b540aSrobert        */
461*404b540aSrobert       value_compare
462*404b540aSrobert       value_comp() const
463*404b540aSrobert       { return value_compare(_M_t.key_comp()); }
464*404b540aSrobert 
465*404b540aSrobert       // multimap operations
466*404b540aSrobert       /**
467*404b540aSrobert        *  @brief Tries to locate an element in a %multimap.
468*404b540aSrobert        *  @param  x  Key of (key, value) pair to be located.
469*404b540aSrobert        *  @return  Iterator pointing to sought-after element,
470*404b540aSrobert        *           or end() if not found.
471*404b540aSrobert        *
472*404b540aSrobert        *  This function takes a key and tries to locate the element with which
473*404b540aSrobert        *  the key matches.  If successful the function returns an iterator
474*404b540aSrobert        *  pointing to the sought after %pair.  If unsuccessful it returns the
475*404b540aSrobert        *  past-the-end ( @c end() ) iterator.
476*404b540aSrobert        */
477*404b540aSrobert       iterator
478*404b540aSrobert       find(const key_type& __x)
479*404b540aSrobert       { return _M_t.find(__x); }
480*404b540aSrobert 
481*404b540aSrobert       /**
482*404b540aSrobert        *  @brief Tries to locate an element in a %multimap.
483*404b540aSrobert        *  @param  x  Key of (key, value) pair to be located.
484*404b540aSrobert        *  @return  Read-only (constant) iterator pointing to sought-after
485*404b540aSrobert        *           element, or end() if not found.
486*404b540aSrobert        *
487*404b540aSrobert        *  This function takes a key and tries to locate the element with which
488*404b540aSrobert        *  the key matches.  If successful the function returns a constant
489*404b540aSrobert        *  iterator pointing to the sought after %pair.  If unsuccessful it
490*404b540aSrobert        *  returns the past-the-end ( @c end() ) iterator.
491*404b540aSrobert        */
492*404b540aSrobert       const_iterator
493*404b540aSrobert       find(const key_type& __x) const
494*404b540aSrobert       { return _M_t.find(__x); }
495*404b540aSrobert 
496*404b540aSrobert       /**
497*404b540aSrobert        *  @brief Finds the number of elements with given key.
498*404b540aSrobert        *  @param  x  Key of (key, value) pairs to be located.
499*404b540aSrobert        *  @return Number of elements with specified key.
500*404b540aSrobert        */
501*404b540aSrobert       size_type
502*404b540aSrobert       count(const key_type& __x) const
503*404b540aSrobert       { return _M_t.count(__x); }
504*404b540aSrobert 
505*404b540aSrobert       /**
506*404b540aSrobert        *  @brief Finds the beginning of a subsequence matching given key.
507*404b540aSrobert        *  @param  x  Key of (key, value) pair to be located.
508*404b540aSrobert        *  @return  Iterator pointing to first element equal to or greater
509*404b540aSrobert        *           than key, or end().
510*404b540aSrobert        *
511*404b540aSrobert        *  This function returns the first element of a subsequence of elements
512*404b540aSrobert        *  that matches the given key.  If unsuccessful it returns an iterator
513*404b540aSrobert        *  pointing to the first element that has a greater value than given key
514*404b540aSrobert        *  or end() if no such element exists.
515*404b540aSrobert        */
516*404b540aSrobert       iterator
517*404b540aSrobert       lower_bound(const key_type& __x)
518*404b540aSrobert       { return _M_t.lower_bound(__x); }
519*404b540aSrobert 
520*404b540aSrobert       /**
521*404b540aSrobert        *  @brief Finds the beginning of a subsequence matching given key.
522*404b540aSrobert        *  @param  x  Key of (key, value) pair to be located.
523*404b540aSrobert        *  @return  Read-only (constant) iterator pointing to first element
524*404b540aSrobert        *           equal to or greater than key, or end().
525*404b540aSrobert        *
526*404b540aSrobert        *  This function returns the first element of a subsequence of elements
527*404b540aSrobert        *  that matches the given key.  If unsuccessful the iterator will point
528*404b540aSrobert        *  to the next greatest element or, if no such greater element exists, to
529*404b540aSrobert        *  end().
530*404b540aSrobert        */
531*404b540aSrobert       const_iterator
532*404b540aSrobert       lower_bound(const key_type& __x) const
533*404b540aSrobert       { return _M_t.lower_bound(__x); }
534*404b540aSrobert 
535*404b540aSrobert       /**
536*404b540aSrobert        *  @brief Finds the end of a subsequence matching given key.
537*404b540aSrobert        *  @param  x  Key of (key, value) pair to be located.
538*404b540aSrobert        *  @return Iterator pointing to the first element
539*404b540aSrobert        *          greater than key, or end().
540*404b540aSrobert        */
541*404b540aSrobert       iterator
542*404b540aSrobert       upper_bound(const key_type& __x)
543*404b540aSrobert       { return _M_t.upper_bound(__x); }
544*404b540aSrobert 
545*404b540aSrobert       /**
546*404b540aSrobert        *  @brief Finds the end of a subsequence matching given key.
547*404b540aSrobert        *  @param  x  Key of (key, value) pair to be located.
548*404b540aSrobert        *  @return  Read-only (constant) iterator pointing to first iterator
549*404b540aSrobert        *           greater than key, or end().
550*404b540aSrobert        */
551*404b540aSrobert       const_iterator
552*404b540aSrobert       upper_bound(const key_type& __x) const
553*404b540aSrobert       { return _M_t.upper_bound(__x); }
554*404b540aSrobert 
555*404b540aSrobert       /**
556*404b540aSrobert        *  @brief Finds a subsequence matching given key.
557*404b540aSrobert        *  @param  x  Key of (key, value) pairs to be located.
558*404b540aSrobert        *  @return  Pair of iterators that possibly points to the subsequence
559*404b540aSrobert        *           matching given key.
560*404b540aSrobert        *
561*404b540aSrobert        *  This function is equivalent to
562*404b540aSrobert        *  @code
563*404b540aSrobert        *    std::make_pair(c.lower_bound(val),
564*404b540aSrobert        *                   c.upper_bound(val))
565*404b540aSrobert        *  @endcode
566*404b540aSrobert        *  (but is faster than making the calls separately).
567*404b540aSrobert        */
568*404b540aSrobert       std::pair<iterator, iterator>
569*404b540aSrobert       equal_range(const key_type& __x)
570*404b540aSrobert       { return _M_t.equal_range(__x); }
571*404b540aSrobert 
572*404b540aSrobert       /**
573*404b540aSrobert        *  @brief Finds a subsequence matching given key.
574*404b540aSrobert        *  @param  x  Key of (key, value) pairs to be located.
575*404b540aSrobert        *  @return  Pair of read-only (constant) iterators that possibly points
576*404b540aSrobert        *           to the subsequence matching given key.
577*404b540aSrobert        *
578*404b540aSrobert        *  This function is equivalent to
579*404b540aSrobert        *  @code
580*404b540aSrobert        *    std::make_pair(c.lower_bound(val),
581*404b540aSrobert        *                   c.upper_bound(val))
582*404b540aSrobert        *  @endcode
583*404b540aSrobert        *  (but is faster than making the calls separately).
584*404b540aSrobert        */
585*404b540aSrobert       std::pair<const_iterator, const_iterator>
586*404b540aSrobert       equal_range(const key_type& __x) const
587*404b540aSrobert       { return _M_t.equal_range(__x); }
588*404b540aSrobert 
589*404b540aSrobert       template <typename _K1, typename _T1, typename _C1, typename _A1>
590*404b540aSrobert         friend bool
591*404b540aSrobert         operator== (const multimap<_K1, _T1, _C1, _A1>&,
592*404b540aSrobert 		    const multimap<_K1, _T1, _C1, _A1>&);
593*404b540aSrobert 
594*404b540aSrobert       template <typename _K1, typename _T1, typename _C1, typename _A1>
595*404b540aSrobert         friend bool
596*404b540aSrobert         operator< (const multimap<_K1, _T1, _C1, _A1>&,
597*404b540aSrobert 		   const multimap<_K1, _T1, _C1, _A1>&);
598*404b540aSrobert   };
599*404b540aSrobert 
600*404b540aSrobert   /**
601*404b540aSrobert    *  @brief  Multimap equality comparison.
602*404b540aSrobert    *  @param  x  A %multimap.
603*404b540aSrobert    *  @param  y  A %multimap of the same type as @a x.
604*404b540aSrobert    *  @return  True iff the size and elements of the maps are equal.
605*404b540aSrobert    *
606*404b540aSrobert    *  This is an equivalence relation.  It is linear in the size of the
607*404b540aSrobert    *  multimaps.  Multimaps are considered equivalent if their sizes are equal,
608*404b540aSrobert    *  and if corresponding elements compare equal.
609*404b540aSrobert   */
610*404b540aSrobert   template <typename _Key, typename _Tp, typename _Compare, typename _Alloc>
611*404b540aSrobert     inline bool
612*404b540aSrobert     operator==(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
613*404b540aSrobert                const multimap<_Key, _Tp, _Compare, _Alloc>& __y)
614*404b540aSrobert     { return __x._M_t == __y._M_t; }
615*404b540aSrobert 
616*404b540aSrobert   /**
617*404b540aSrobert    *  @brief  Multimap ordering relation.
618*404b540aSrobert    *  @param  x  A %multimap.
619*404b540aSrobert    *  @param  y  A %multimap of the same type as @a x.
620*404b540aSrobert    *  @return  True iff @a x is lexicographically less than @a y.
621*404b540aSrobert    *
622*404b540aSrobert    *  This is a total ordering relation.  It is linear in the size of the
623*404b540aSrobert    *  multimaps.  The elements must be comparable with @c <.
624*404b540aSrobert    *
625*404b540aSrobert    *  See std::lexicographical_compare() for how the determination is made.
626*404b540aSrobert   */
627*404b540aSrobert   template <typename _Key, typename _Tp, typename _Compare, typename _Alloc>
628*404b540aSrobert     inline bool
629*404b540aSrobert     operator<(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
630*404b540aSrobert               const multimap<_Key, _Tp, _Compare, _Alloc>& __y)
631*404b540aSrobert     { return __x._M_t < __y._M_t; }
632*404b540aSrobert 
633*404b540aSrobert   /// Based on operator==
634*404b540aSrobert   template <typename _Key, typename _Tp, typename _Compare, typename _Alloc>
635*404b540aSrobert     inline bool
636*404b540aSrobert     operator!=(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
637*404b540aSrobert                const multimap<_Key, _Tp, _Compare, _Alloc>& __y)
638*404b540aSrobert     { return !(__x == __y); }
639*404b540aSrobert 
640*404b540aSrobert   /// Based on operator<
641*404b540aSrobert   template <typename _Key, typename _Tp, typename _Compare, typename _Alloc>
642*404b540aSrobert     inline bool
643*404b540aSrobert     operator>(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
644*404b540aSrobert               const multimap<_Key, _Tp, _Compare, _Alloc>& __y)
645*404b540aSrobert     { return __y < __x; }
646*404b540aSrobert 
647*404b540aSrobert   /// Based on operator<
648*404b540aSrobert   template <typename _Key, typename _Tp, typename _Compare, typename _Alloc>
649*404b540aSrobert     inline bool
650*404b540aSrobert     operator<=(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
651*404b540aSrobert                const multimap<_Key, _Tp, _Compare, _Alloc>& __y)
652*404b540aSrobert     { return !(__y < __x); }
653*404b540aSrobert 
654*404b540aSrobert   /// Based on operator<
655*404b540aSrobert   template <typename _Key, typename _Tp, typename _Compare, typename _Alloc>
656*404b540aSrobert     inline bool
657*404b540aSrobert     operator>=(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
658*404b540aSrobert                const multimap<_Key, _Tp, _Compare, _Alloc>& __y)
659*404b540aSrobert     { return !(__x < __y); }
660*404b540aSrobert 
661*404b540aSrobert   /// See std::multimap::swap().
662*404b540aSrobert   template <typename _Key, typename _Tp, typename _Compare, typename _Alloc>
663*404b540aSrobert     inline void
swap(multimap<_Key,_Tp,_Compare,_Alloc> & __x,multimap<_Key,_Tp,_Compare,_Alloc> & __y)664*404b540aSrobert     swap(multimap<_Key, _Tp, _Compare, _Alloc>& __x,
665*404b540aSrobert          multimap<_Key, _Tp, _Compare, _Alloc>& __y)
666*404b540aSrobert     { __x.swap(__y); }
667*404b540aSrobert 
668*404b540aSrobert _GLIBCXX_END_NESTED_NAMESPACE
669*404b540aSrobert 
670*404b540aSrobert #endif /* _MULTIMAP_H */
671