stl_multimap.h revision 265220
198524Sfenner// Multimap implementation -*- C++ -*-
298524Sfenner
398524Sfenner// Copyright (C) 2001, 2002, 2004, 2005, 2006 Free Software Foundation, Inc.
498524Sfenner//
598524Sfenner// This file is part of the GNU ISO C++ Library.  This library is free
698524Sfenner// software; you can redistribute it and/or modify it under the
798524Sfenner// terms of the GNU General Public License as published by the
898524Sfenner// Free Software Foundation; either version 2, or (at your option)
998524Sfenner// any later version.
1098524Sfenner
1198524Sfenner// This library is distributed in the hope that it will be useful,
1298524Sfenner// but WITHOUT ANY WARRANTY; without even the implied warranty of
1398524Sfenner// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1498524Sfenner// GNU General Public License for more details.
1598524Sfenner
1698524Sfenner// You should have received a copy of the GNU General Public License along
1798524Sfenner// with this library; see the file COPYING.  If not, write to the Free
1898524Sfenner// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
1998524Sfenner// USA.
2098524Sfenner
2198524Sfenner// As a special exception, you may use this file as part of a free software
2298524Sfenner// library without restriction.  Specifically, if other files instantiate
2398524Sfenner// templates or use macros or inline functions from this file, or you compile
2498524Sfenner// this file and link it with other files to produce an executable, this
2598524Sfenner// file does not by itself cause the resulting executable to be covered by
2698524Sfenner// the GNU General Public License.  This exception does not however
2798524Sfenner// invalidate any other reasons why the executable file might be covered by
2898524Sfenner// the GNU General Public License.
2998524Sfenner
3098524Sfenner/*
3198524Sfenner *
3298524Sfenner * Copyright (c) 1994
3398524Sfenner * Hewlett-Packard Company
3498524Sfenner *
3598524Sfenner * Permission to use, copy, modify, distribute and sell this software
3698524Sfenner * and its documentation for any purpose is hereby granted without fee,
37127668Sbms * provided that the above copyright notice appear in all copies and
38190207Srpaulo * that both that copyright notice and this permission notice appear
3998524Sfenner * in supporting documentation.  Hewlett-Packard Company makes no
4098524Sfenner * representations about the suitability of this software for any
4198524Sfenner * purpose.  It is provided "as is" without express or implied warranty.
4298524Sfenner *
4398524Sfenner *
4498524Sfenner * Copyright (c) 1996,1997
45127668Sbms * Silicon Graphics Computer Systems, Inc.
4698524Sfenner *
4798524Sfenner * Permission to use, copy, modify, distribute and sell this software
4898524Sfenner * and its documentation for any purpose is hereby granted without fee,
4998524Sfenner * provided that the above copyright notice appear in all copies and
5098524Sfenner * that both that copyright notice and this permission notice appear
5198524Sfenner * in supporting documentation.  Silicon Graphics makes no
5298524Sfenner * representations about the suitability of this software for any
5398524Sfenner * purpose.  It is provided "as is" without express or implied warranty.
5498524Sfenner */
5598524Sfenner
5698524Sfenner/** @file stl_multimap.h
5798524Sfenner *  This is an internal header file, included by other library headers.
5898524Sfenner *  You should not attempt to use it directly.
5998524Sfenner */
6098524Sfenner
6198524Sfenner#ifndef _MULTIMAP_H
62235530Sdelphij#define _MULTIMAP_H 1
63235530Sdelphij
64235530Sdelphij#include <bits/concept_check.h>
65214478Srpaulo
66214478Srpaulo_GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD)
67214478Srpaulo
68214478Srpaulo  /**
69214478Srpaulo   *  @brief A standard container made up of (key,value) pairs, which can be
70214478Srpaulo   *  retrieved based on a key, in logarithmic time.
71214478Srpaulo   *
72214478Srpaulo   *  @ingroup Containers
73214478Srpaulo   *  @ingroup Assoc_containers
74214478Srpaulo   *
75214478Srpaulo   *  Meets the requirements of a <a href="tables.html#65">container</a>, a
76214478Srpaulo   *  <a href="tables.html#66">reversible container</a>, and an
77214478Srpaulo   *  <a href="tables.html#69">associative container</a> (using equivalent
78214478Srpaulo   *  keys).  For a @c multimap<Key,T> the key_type is Key, the mapped_type
79214478Srpaulo   *  is T, and the value_type is std::pair<const Key,T>.
80214478Srpaulo   *
81214478Srpaulo   *  Multimaps support bidirectional iterators.
82214478Srpaulo   *
83214478Srpaulo   *  @if maint
84214478Srpaulo   *  The private tree data is declared exactly the same way for map and
8598524Sfenner   *  multimap; the distinction is made entirely in how the tree functions are
8698524Sfenner   *  called (*_unique versus *_equal, same as the standard).
8798524Sfenner   *  @endif
88127668Sbms  */
8998524Sfenner  template <typename _Key, typename _Tp,
9098524Sfenner	    typename _Compare = std::less<_Key>,
9198524Sfenner	    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> > >
9298524Sfenner    class multimap
9398524Sfenner    {
94111726Sfenner    public:
9598524Sfenner      typedef _Key                                          key_type;
9698524Sfenner      typedef _Tp                                           mapped_type;
97111726Sfenner      typedef std::pair<const _Key, _Tp>                    value_type;
98111726Sfenner      typedef _Compare                                      key_compare;
99146773Ssam      typedef _Alloc                                        allocator_type;
100214478Srpaulo
10198524Sfenner    private:
102214478Srpaulo      // concept requirements
103111726Sfenner      typedef typename _Alloc::value_type                   _Alloc_value_type;
104111726Sfenner      __glibcxx_class_requires(_Tp, _SGIAssignableConcept)
105127668Sbms      __glibcxx_class_requires4(_Compare, bool, _Key, _Key,
10698524Sfenner				_BinaryFunctionConcept)
107111726Sfenner      __glibcxx_class_requires2(value_type, _Alloc_value_type, _SameTypeConcept)
10898524Sfenner
10998524Sfenner    public:
11098524Sfenner      class value_compare
111111726Sfenner      : public std::binary_function<value_type, value_type, bool>
11298524Sfenner      {
11398524Sfenner	friend class multimap<_Key, _Tp, _Compare, _Alloc>;
11498524Sfenner      protected:
115147899Ssam	_Compare comp;
11698524Sfenner
117127668Sbms	value_compare(_Compare __c)
11898524Sfenner	: comp(__c) { }
119127668Sbms
12098524Sfenner      public:
12198524Sfenner	bool operator()(const value_type& __x, const value_type& __y) const
12298524Sfenner	{ return comp(__x.first, __y.first); }
123127668Sbms      };
12498524Sfenner
12598524Sfenner    private:
12698524Sfenner      /// @if maint  This turns a red-black tree into a [multi]map.  @endif
127127668Sbms      typedef typename _Alloc::template rebind<value_type>::other
128127668Sbms        _Pair_alloc_type;
129127668Sbms
13098524Sfenner      typedef _Rb_tree<key_type, value_type, _Select1st<value_type>,
13198524Sfenner		       key_compare, _Pair_alloc_type> _Rep_type;
132127668Sbms      /// @if maint  The actual tree structure.  @endif
133127668Sbms      _Rep_type _M_t;
134127668Sbms
135127668Sbms    public:
136127668Sbms      // many of these are specified differently in ISO, but the following are
13798524Sfenner      // "functionally equivalent"
13898524Sfenner      typedef typename _Pair_alloc_type::pointer         pointer;
13998524Sfenner      typedef typename _Pair_alloc_type::const_pointer   const_pointer;
140127668Sbms      typedef typename _Pair_alloc_type::reference       reference;
141127668Sbms      typedef typename _Pair_alloc_type::const_reference const_reference;
142127668Sbms      typedef typename _Rep_type::iterator               iterator;
143127668Sbms      typedef typename _Rep_type::const_iterator         const_iterator;
144127668Sbms      typedef typename _Rep_type::size_type              size_type;
14598524Sfenner      typedef typename _Rep_type::difference_type        difference_type;
14698524Sfenner      typedef typename _Rep_type::reverse_iterator       reverse_iterator;
14798524Sfenner      typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
148214478Srpaulo
149214478Srpaulo      // [23.3.2] construct/copy/destroy
150214478Srpaulo      // (get_allocator() is also listed in this section)
151214478Srpaulo      /**
152214478Srpaulo       *  @brief  Default constructor creates no elements.
153214478Srpaulo       */
154214478Srpaulo      multimap()
155214478Srpaulo      : _M_t() { }
156214478Srpaulo
157146773Ssam      // for some reason this was made a separate function
158146773Ssam      /**
159146773Ssam       *  @brief  Default constructor creates no elements.
160146773Ssam       */
16198524Sfenner      explicit
162127668Sbms      multimap(const _Compare& __comp,
163111726Sfenner	       const allocator_type& __a = allocator_type())
164111726Sfenner      : _M_t(__comp, __a) { }
16598524Sfenner
166111726Sfenner      /**
167111726Sfenner       *  @brief  %Multimap copy constructor.
16898524Sfenner       *  @param  x  A %multimap of identical element and allocator types.
169127668Sbms       *
170111726Sfenner       *  The newly-created %multimap uses a copy of the allocation object used
17198524Sfenner       *  by @a x.
172147899Ssam       */
173111726Sfenner      multimap(const multimap& __x)
174147899Ssam      : _M_t(__x._M_t) { }
175127668Sbms
176147899Ssam      /**
177147899Ssam       *  @brief  Builds a %multimap from a range.
178147899Ssam       *  @param  first  An input iterator.
179147899Ssam       *  @param  last  An input iterator.
180147899Ssam       *
181147899Ssam       *  Create a %multimap consisting of copies of the elements from
182127668Sbms       *  [first,last).  This is linear in N if the range is already sorted,
183147899Ssam       *  and NlogN otherwise (where N is distance(first,last)).
184147899Ssam       */
185147899Ssam      template <typename _InputIterator>
186147899Ssam        multimap(_InputIterator __first, _InputIterator __last)
18798524Sfenner	: _M_t()
18898524Sfenner        { _M_t._M_insert_equal(__first, __last); }
18998524Sfenner
190111726Sfenner      /**
19198524Sfenner       *  @brief  Builds a %multimap from a range.
192146773Ssam       *  @param  first  An input iterator.
19398524Sfenner       *  @param  last  An input iterator.
19498524Sfenner       *  @param  comp  A comparison functor.
19598524Sfenner       *  @param  a  An allocator object.
19698524Sfenner       *
197111726Sfenner       *  Create a %multimap consisting of copies of the elements from
198127668Sbms       *  [first,last).  This is linear in N if the range is already sorted,
19998524Sfenner       *  and NlogN otherwise (where N is distance(first,last)).
200127668Sbms       */
201127668Sbms      template <typename _InputIterator>
20298524Sfenner        multimap(_InputIterator __first, _InputIterator __last,
20398524Sfenner		 const _Compare& __comp,
20498524Sfenner		 const allocator_type& __a = allocator_type())
205127668Sbms        : _M_t(__comp, __a)
20698524Sfenner        { _M_t._M_insert_equal(__first, __last); }
20798524Sfenner
208127668Sbms      // FIXME There is no dtor declared, but we should have something generated
209127668Sbms      // by Doxygen.  I don't know what tags to add to this paragraph to make
21098524Sfenner      // that happen:
21198524Sfenner      /**
21298524Sfenner       *  The dtor only erases the elements, and note that if the elements
213127668Sbms       *  themselves are pointers, the pointed-to memory is not touched in any
214127668Sbms       *  way.  Managing the pointer is the user's responsibilty.
21598524Sfenner       */
216127668Sbms
21798524Sfenner      /**
21898524Sfenner       *  @brief  %Multimap assignment operator.
219127668Sbms       *  @param  x  A %multimap of identical element and allocator types.
22098524Sfenner       *
22198524Sfenner       *  All the elements of @a x are copied, but unlike the copy constructor,
22298524Sfenner       *  the allocator object is not copied.
223111726Sfenner       */
224127668Sbms      multimap&
225127668Sbms      operator=(const multimap& __x)
226127668Sbms      {
227127668Sbms	_M_t = __x._M_t;
228127668Sbms	return *this;
22998524Sfenner      }
230214478Srpaulo
231214478Srpaulo      /// Get a copy of the memory allocation object.
232214478Srpaulo      allocator_type
233214478Srpaulo      get_allocator() const
234214478Srpaulo      { return _M_t.get_allocator(); }
235214478Srpaulo
236214478Srpaulo      // iterators
237214478Srpaulo      /**
238214478Srpaulo       *  Returns a read/write iterator that points to the first pair in the
239214478Srpaulo       *  %multimap.  Iteration is done in ascending order according to the
240214478Srpaulo       *  keys.
241214478Srpaulo       */
242214478Srpaulo      iterator
24398524Sfenner      begin()
244214478Srpaulo      { return _M_t.begin(); }
245214478Srpaulo
246214478Srpaulo      /**
247111726Sfenner       *  Returns a read-only (constant) iterator that points to the first pair
248127668Sbms       *  in the %multimap.  Iteration is done in ascending order according to
24998524Sfenner       *  the keys.
25098524Sfenner       */
251162017Ssam      const_iterator
252111726Sfenner      begin() const
25398524Sfenner      { return _M_t.begin(); }
254214478Srpaulo
255127668Sbms      /**
256127668Sbms       *  Returns a read/write iterator that points one past the last pair in
257172683Smlaier       *  the %multimap.  Iteration is done in ascending order according to the
258127668Sbms       *  keys.
259214478Srpaulo       */
260127668Sbms      iterator
261127668Sbms      end()
26298524Sfenner      { return _M_t.end(); }
263214478Srpaulo
264127668Sbms      /**
265172683Smlaier       *  Returns a read-only (constant) iterator that points one past the last
26698524Sfenner       *  pair in the %multimap.  Iteration is done in ascending order according
26798524Sfenner       *  to the keys.
26898524Sfenner       */
26998524Sfenner      const_iterator
27098524Sfenner      end() const
27198524Sfenner      { return _M_t.end(); }
27298524Sfenner
273111726Sfenner      /**
27498524Sfenner       *  Returns a read/write reverse iterator that points to the last pair in
27598524Sfenner       *  the %multimap.  Iteration is done in descending order according to the
276111726Sfenner       *  keys.
277127668Sbms       */
278127668Sbms      reverse_iterator
279127668Sbms      rbegin()
280127668Sbms      { return _M_t.rbegin(); }
281127668Sbms
28298524Sfenner      /**
28398524Sfenner       *  Returns a read-only (constant) reverse iterator that points to the
28498524Sfenner       *  last pair in the %multimap.  Iteration is done in descending order
28598524Sfenner       *  according to the keys.
28698524Sfenner       */
28798524Sfenner      const_reverse_iterator
28898524Sfenner      rbegin() const
28998524Sfenner      { return _M_t.rbegin(); }
29098524Sfenner
29198524Sfenner      /**
292111726Sfenner       *  Returns a read/write reverse iterator that points to one before the
293127668Sbms       *  first pair in the %multimap.  Iteration is done in descending order
29498524Sfenner       *  according to the keys.
295111726Sfenner       */
296127668Sbms      reverse_iterator
297127668Sbms      rend()
298127668Sbms      { return _M_t.rend(); }
299127668Sbms
300127668Sbms      /**
301127668Sbms       *  Returns a read-only (constant) reverse iterator that points to one
30298524Sfenner       *  before the first pair in the %multimap.  Iteration is done in
30398524Sfenner       *  descending order according to the keys.
30498524Sfenner       */
30598524Sfenner      const_reverse_iterator
30698524Sfenner      rend() const
30798524Sfenner      { return _M_t.rend(); }
30898524Sfenner
30998524Sfenner      // capacity
31098524Sfenner      /** Returns true if the %multimap is empty.  */
311111726Sfenner      bool
312127668Sbms      empty() const
31398524Sfenner      { return _M_t.empty(); }
314147899Ssam
31598524Sfenner      /** Returns the size of the %multimap.  */
31698524Sfenner      size_type
317111726Sfenner      size() const
318127668Sbms      { return _M_t.size(); }
319127668Sbms
320127668Sbms      /** Returns the maximum size of the %multimap.  */
321127668Sbms      size_type
322127668Sbms      max_size() const
323127668Sbms      { return _M_t.max_size(); }
32498524Sfenner
325111726Sfenner      // modifiers
326111726Sfenner      /**
32798524Sfenner       *  @brief Inserts a std::pair into the %multimap.
328127668Sbms       *  @param  x  Pair to be inserted (see std::make_pair for easy creation
32998524Sfenner       *             of pairs).
330127668Sbms       *  @return An iterator that points to the inserted (key,value) pair.
33198524Sfenner       *
332127668Sbms       *  This function inserts a (key, value) pair into the %multimap.
333127668Sbms       *  Contrary to a std::map the %multimap does not rely on unique keys and
33498524Sfenner       *  thus multiple pairs with the same key can be inserted.
335127668Sbms       *
33698524Sfenner       *  Insertion requires logarithmic time.
337147899Ssam       */
338127668Sbms      iterator
339147899Ssam      insert(const value_type& __x)
34098524Sfenner      { return _M_t._M_insert_equal(__x); }
341127668Sbms
34298524Sfenner      /**
34398524Sfenner       *  @brief Inserts a std::pair into the %multimap.
34498524Sfenner       *  @param  position  An iterator that serves as a hint as to where the
34598524Sfenner       *                    pair should be inserted.
34698524Sfenner       *  @param  x  Pair to be inserted (see std::make_pair for easy creation
347111726Sfenner       *             of pairs).
34898524Sfenner       *  @return An iterator that points to the inserted (key,value) pair.
349111726Sfenner       *
35098524Sfenner       *  This function inserts a (key, value) pair into the %multimap.
35198524Sfenner       *  Contrary to a std::map the %multimap does not rely on unique keys and
352127668Sbms       *  thus multiple pairs with the same key can be inserted.
35398524Sfenner       *  Note that the first parameter is only a hint and can potentially
35498524Sfenner       *  improve the performance of the insertion process.  A bad hint would
35598524Sfenner       *  cause no gains in efficiency.
35698524Sfenner       *
35798524Sfenner       *  See http://gcc.gnu.org/onlinedocs/libstdc++/23_containers/howto.html#4
35898524Sfenner       *  for more on "hinting".
35998524Sfenner       *
36098524Sfenner       *  Insertion requires logarithmic time (if the hint is not taken).
36198524Sfenner       */
36298524Sfenner      iterator
36398524Sfenner      insert(iterator __position, const value_type& __x)
36498524Sfenner      { return _M_t._M_insert_equal(__position, __x); }
36598524Sfenner
36698524Sfenner      /**
36798524Sfenner       *  @brief A template function that attemps to insert a range of elements.
36898524Sfenner       *  @param  first  Iterator pointing to the start of the range to be
36998524Sfenner       *                 inserted.
37098524Sfenner       *  @param  last  Iterator pointing to the end of the range.
37198524Sfenner       *
37298524Sfenner       *  Complexity similar to that of the range constructor.
37398524Sfenner       */
37498524Sfenner      template <typename _InputIterator>
37598524Sfenner        void
37698524Sfenner        insert(_InputIterator __first, _InputIterator __last)
37798524Sfenner        { _M_t._M_insert_equal(__first, __last); }
37898524Sfenner
379127668Sbms      /**
38098524Sfenner       *  @brief Erases an element from a %multimap.
38198524Sfenner       *  @param  position  An iterator pointing to the element to be erased.
38298524Sfenner       *
38398524Sfenner       *  This function erases an element, pointed to by the given iterator,
38498524Sfenner       *  from a %multimap.  Note that this function only erases the element,
38598524Sfenner       *  and that if the element is itself a pointer, the pointed-to memory is
38698524Sfenner       *  not touched in any way.  Managing the pointer is the user's
38798524Sfenner       *  responsibilty.
38898524Sfenner       */
38998524Sfenner      void
39098524Sfenner      erase(iterator __position)
39198524Sfenner      { _M_t.erase(__position); }
39298524Sfenner
39398524Sfenner      /**
39498524Sfenner       *  @brief Erases elements according to the provided key.
39598524Sfenner       *  @param  x  Key of element to be erased.
39698524Sfenner       *  @return  The number of elements erased.
39798524Sfenner       *
398146773Ssam       *  This function erases all elements located by the given key from a
399146773Ssam       *  %multimap.
400146773Ssam       *  Note that this function only erases the element, and that if
40198524Sfenner       *  the element is itself a pointer, the pointed-to memory is not touched
402147899Ssam       *  in any way.  Managing the pointer is the user's responsibilty.
403147899Ssam       */
404147899Ssam      size_type
405147899Ssam      erase(const key_type& __x)
406147899Ssam      { return _M_t.erase(__x); }
40798524Sfenner
408      /**
409       *  @brief Erases a [first,last) range of elements from a %multimap.
410       *  @param  first  Iterator pointing to the start of the range to be
411       *                 erased.
412       *  @param  last  Iterator pointing to the end of the range to be erased.
413       *
414       *  This function erases a sequence of elements from a %multimap.
415       *  Note that this function only erases the elements, and that if
416       *  the elements themselves are pointers, the pointed-to memory is not
417       *  touched in any way.  Managing the pointer is the user's responsibilty.
418       */
419      void
420      erase(iterator __first, iterator __last)
421      { _M_t.erase(__first, __last); }
422
423      /**
424       *  @brief  Swaps data with another %multimap.
425       *  @param  x  A %multimap of the same element and allocator types.
426       *
427       *  This exchanges the elements between two multimaps in constant time.
428       *  (It is only swapping a pointer, an integer, and an instance of
429       *  the @c Compare type (which itself is often stateless and empty), so it
430       *  should be quite fast.)
431       *  Note that the global std::swap() function is specialized such that
432       *  std::swap(m1,m2) will feed to this function.
433       */
434      void
435      swap(multimap& __x)
436      { _M_t.swap(__x._M_t); }
437
438      /**
439       *  Erases all elements in a %multimap.  Note that this function only
440       *  erases the elements, and that if the elements themselves are pointers,
441       *  the pointed-to memory is not touched in any way.  Managing the pointer
442       *  is the user's responsibilty.
443       */
444      void
445      clear()
446      { _M_t.clear(); }
447
448      // observers
449      /**
450       *  Returns the key comparison object out of which the %multimap
451       *  was constructed.
452       */
453      key_compare
454      key_comp() const
455      { return _M_t.key_comp(); }
456
457      /**
458       *  Returns a value comparison object, built from the key comparison
459       *  object out of which the %multimap was constructed.
460       */
461      value_compare
462      value_comp() const
463      { return value_compare(_M_t.key_comp()); }
464
465      // multimap operations
466      /**
467       *  @brief Tries to locate an element in a %multimap.
468       *  @param  x  Key of (key, value) pair to be located.
469       *  @return  Iterator pointing to sought-after element,
470       *           or end() if not found.
471       *
472       *  This function takes a key and tries to locate the element with which
473       *  the key matches.  If successful the function returns an iterator
474       *  pointing to the sought after %pair.  If unsuccessful it returns the
475       *  past-the-end ( @c end() ) iterator.
476       */
477      iterator
478      find(const key_type& __x)
479      { return _M_t.find(__x); }
480
481      /**
482       *  @brief Tries to locate an element in a %multimap.
483       *  @param  x  Key of (key, value) pair to be located.
484       *  @return  Read-only (constant) iterator pointing to sought-after
485       *           element, or end() if not found.
486       *
487       *  This function takes a key and tries to locate the element with which
488       *  the key matches.  If successful the function returns a constant
489       *  iterator pointing to the sought after %pair.  If unsuccessful it
490       *  returns the past-the-end ( @c end() ) iterator.
491       */
492      const_iterator
493      find(const key_type& __x) const
494      { return _M_t.find(__x); }
495
496      /**
497       *  @brief Finds the number of elements with given key.
498       *  @param  x  Key of (key, value) pairs to be located.
499       *  @return Number of elements with specified key.
500       */
501      size_type
502      count(const key_type& __x) const
503      { return _M_t.count(__x); }
504
505      /**
506       *  @brief Finds the beginning of a subsequence matching given key.
507       *  @param  x  Key of (key, value) pair to be located.
508       *  @return  Iterator pointing to first element equal to or greater
509       *           than key, or end().
510       *
511       *  This function returns the first element of a subsequence of elements
512       *  that matches the given key.  If unsuccessful it returns an iterator
513       *  pointing to the first element that has a greater value than given key
514       *  or end() if no such element exists.
515       */
516      iterator
517      lower_bound(const key_type& __x)
518      { return _M_t.lower_bound(__x); }
519
520      /**
521       *  @brief Finds the beginning of a subsequence matching given key.
522       *  @param  x  Key of (key, value) pair to be located.
523       *  @return  Read-only (constant) iterator pointing to first element
524       *           equal to or greater than key, or end().
525       *
526       *  This function returns the first element of a subsequence of elements
527       *  that matches the given key.  If unsuccessful the iterator will point
528       *  to the next greatest element or, if no such greater element exists, to
529       *  end().
530       */
531      const_iterator
532      lower_bound(const key_type& __x) const
533      { return _M_t.lower_bound(__x); }
534
535      /**
536       *  @brief Finds the end of a subsequence matching given key.
537       *  @param  x  Key of (key, value) pair to be located.
538       *  @return Iterator pointing to the first element
539       *          greater than key, or end().
540       */
541      iterator
542      upper_bound(const key_type& __x)
543      { return _M_t.upper_bound(__x); }
544
545      /**
546       *  @brief Finds the end of a subsequence matching given key.
547       *  @param  x  Key of (key, value) pair to be located.
548       *  @return  Read-only (constant) iterator pointing to first iterator
549       *           greater than key, or end().
550       */
551      const_iterator
552      upper_bound(const key_type& __x) const
553      { return _M_t.upper_bound(__x); }
554
555      /**
556       *  @brief Finds a subsequence matching given key.
557       *  @param  x  Key of (key, value) pairs to be located.
558       *  @return  Pair of iterators that possibly points to the subsequence
559       *           matching given key.
560       *
561       *  This function is equivalent to
562       *  @code
563       *    std::make_pair(c.lower_bound(val),
564       *                   c.upper_bound(val))
565       *  @endcode
566       *  (but is faster than making the calls separately).
567       */
568      std::pair<iterator, iterator>
569      equal_range(const key_type& __x)
570      { return _M_t.equal_range(__x); }
571
572      /**
573       *  @brief Finds a subsequence matching given key.
574       *  @param  x  Key of (key, value) pairs to be located.
575       *  @return  Pair of read-only (constant) iterators that possibly points
576       *           to the subsequence matching given key.
577       *
578       *  This function is equivalent to
579       *  @code
580       *    std::make_pair(c.lower_bound(val),
581       *                   c.upper_bound(val))
582       *  @endcode
583       *  (but is faster than making the calls separately).
584       */
585      std::pair<const_iterator, const_iterator>
586      equal_range(const key_type& __x) const
587      { return _M_t.equal_range(__x); }
588
589      template <typename _K1, typename _T1, typename _C1, typename _A1>
590        friend bool
591        operator== (const multimap<_K1, _T1, _C1, _A1>&,
592		    const multimap<_K1, _T1, _C1, _A1>&);
593
594      template <typename _K1, typename _T1, typename _C1, typename _A1>
595        friend bool
596        operator< (const multimap<_K1, _T1, _C1, _A1>&,
597		   const multimap<_K1, _T1, _C1, _A1>&);
598  };
599
600  /**
601   *  @brief  Multimap equality comparison.
602   *  @param  x  A %multimap.
603   *  @param  y  A %multimap of the same type as @a x.
604   *  @return  True iff the size and elements of the maps are equal.
605   *
606   *  This is an equivalence relation.  It is linear in the size of the
607   *  multimaps.  Multimaps are considered equivalent if their sizes are equal,
608   *  and if corresponding elements compare equal.
609  */
610  template <typename _Key, typename _Tp, typename _Compare, typename _Alloc>
611    inline bool
612    operator==(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
613               const multimap<_Key, _Tp, _Compare, _Alloc>& __y)
614    { return __x._M_t == __y._M_t; }
615
616  /**
617   *  @brief  Multimap ordering relation.
618   *  @param  x  A %multimap.
619   *  @param  y  A %multimap of the same type as @a x.
620   *  @return  True iff @a x is lexicographically less than @a y.
621   *
622   *  This is a total ordering relation.  It is linear in the size of the
623   *  multimaps.  The elements must be comparable with @c <.
624   *
625   *  See std::lexicographical_compare() for how the determination is made.
626  */
627  template <typename _Key, typename _Tp, typename _Compare, typename _Alloc>
628    inline bool
629    operator<(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
630              const multimap<_Key, _Tp, _Compare, _Alloc>& __y)
631    { return __x._M_t < __y._M_t; }
632
633  /// Based on operator==
634  template <typename _Key, typename _Tp, typename _Compare, typename _Alloc>
635    inline bool
636    operator!=(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
637               const multimap<_Key, _Tp, _Compare, _Alloc>& __y)
638    { return !(__x == __y); }
639
640  /// Based on operator<
641  template <typename _Key, typename _Tp, typename _Compare, typename _Alloc>
642    inline bool
643    operator>(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
644              const multimap<_Key, _Tp, _Compare, _Alloc>& __y)
645    { return __y < __x; }
646
647  /// Based on operator<
648  template <typename _Key, typename _Tp, typename _Compare, typename _Alloc>
649    inline bool
650    operator<=(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
651               const multimap<_Key, _Tp, _Compare, _Alloc>& __y)
652    { return !(__y < __x); }
653
654  /// Based on operator<
655  template <typename _Key, typename _Tp, typename _Compare, typename _Alloc>
656    inline bool
657    operator>=(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
658               const multimap<_Key, _Tp, _Compare, _Alloc>& __y)
659    { return !(__x < __y); }
660
661  /// See std::multimap::swap().
662  template <typename _Key, typename _Tp, typename _Compare, typename _Alloc>
663    inline void
664    swap(multimap<_Key, _Tp, _Compare, _Alloc>& __x,
665         multimap<_Key, _Tp, _Compare, _Alloc>& __y)
666    { __x.swap(__y); }
667
668_GLIBCXX_END_NESTED_NAMESPACE
669
670#endif /* _MULTIMAP_H */
671