OSDN Git Service

6b74558948c2996a427aff7000ae3489bda124bd
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / include / bits / stl_multimap.h
1 // Multimap implementation -*- C++ -*-
2
3 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
4 // 2011 Free Software Foundation, Inc.
5 //
6 // This file is part of the GNU ISO C++ Library.  This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
10 // any later version.
11
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 // GNU General Public License for more details.
16
17 // Under Section 7 of GPL version 3, you are granted additional
18 // permissions described in the GCC Runtime Library Exception, version
19 // 3.1, as published by the Free Software Foundation.
20
21 // You should have received a copy of the GNU General Public License and
22 // a copy of the GCC Runtime Library Exception along with this program;
23 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
24 // <http://www.gnu.org/licenses/>.
25
26 /*
27  *
28  * Copyright (c) 1994
29  * Hewlett-Packard Company
30  *
31  * Permission to use, copy, modify, distribute and sell this software
32  * and its documentation for any purpose is hereby granted without fee,
33  * provided that the above copyright notice appear in all copies and
34  * that both that copyright notice and this permission notice appear
35  * in supporting documentation.  Hewlett-Packard Company makes no
36  * representations about the suitability of this software for any
37  * purpose.  It is provided "as is" without express or implied warranty.
38  *
39  *
40  * Copyright (c) 1996,1997
41  * Silicon Graphics Computer Systems, Inc.
42  *
43  * Permission to use, copy, modify, distribute and sell this software
44  * and its documentation for any purpose is hereby granted without fee,
45  * provided that the above copyright notice appear in all copies and
46  * that both that copyright notice and this permission notice appear
47  * in supporting documentation.  Silicon Graphics makes no
48  * representations about the suitability of this software for any
49  * purpose.  It is provided "as is" without express or implied warranty.
50  */
51
52 /** @file bits/stl_multimap.h
53  *  This is an internal header file, included by other library headers.
54  *  Do not attempt to use it directly. @headername{map}
55  */
56
57 #ifndef _STL_MULTIMAP_H
58 #define _STL_MULTIMAP_H 1
59
60 #include <bits/concept_check.h>
61 #include <initializer_list>
62
63 namespace std _GLIBCXX_VISIBILITY(default)
64 {
65 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
66
67   /**
68    *  @brief A standard container made up of (key,value) pairs, which can be
69    *  retrieved based on a key, in logarithmic time.
70    *
71    *  @ingroup associative_containers
72    *
73    *  Meets the requirements of a <a href="tables.html#65">container</a>, a
74    *  <a href="tables.html#66">reversible container</a>, and an
75    *  <a href="tables.html#69">associative container</a> (using equivalent
76    *  keys).  For a @c multimap<Key,T> the key_type is Key, the mapped_type
77    *  is T, and the value_type is std::pair<const Key,T>.
78    *
79    *  Multimaps support bidirectional iterators.
80    *
81    *  The private tree data is declared exactly the same way for map and
82    *  multimap; the distinction is made entirely in how the tree functions are
83    *  called (*_unique versus *_equal, same as the standard).
84   */
85   template <typename _Key, typename _Tp,
86             typename _Compare = std::less<_Key>,
87             typename _Alloc = std::allocator<std::pair<const _Key, _Tp> > >
88     class multimap
89     {
90     public:
91       typedef _Key                                          key_type;
92       typedef _Tp                                           mapped_type;
93       typedef std::pair<const _Key, _Tp>                    value_type;
94       typedef _Compare                                      key_compare;
95       typedef _Alloc                                        allocator_type;
96
97     private:
98       // concept requirements
99       typedef typename _Alloc::value_type                   _Alloc_value_type;
100       __glibcxx_class_requires(_Tp, _SGIAssignableConcept)
101       __glibcxx_class_requires4(_Compare, bool, _Key, _Key,
102                                 _BinaryFunctionConcept)
103       __glibcxx_class_requires2(value_type, _Alloc_value_type, _SameTypeConcept)        
104
105     public:
106       class value_compare
107       : public std::binary_function<value_type, value_type, bool>
108       {
109         friend class multimap<_Key, _Tp, _Compare, _Alloc>;
110       protected:
111         _Compare comp;
112
113         value_compare(_Compare __c)
114         : comp(__c) { }
115
116       public:
117         bool operator()(const value_type& __x, const value_type& __y) const
118         { return comp(__x.first, __y.first); }
119       };
120
121     private:
122       /// This turns a red-black tree into a [multi]map.
123       typedef typename _Alloc::template rebind<value_type>::other 
124         _Pair_alloc_type;
125
126       typedef _Rb_tree<key_type, value_type, _Select1st<value_type>,
127                        key_compare, _Pair_alloc_type> _Rep_type;
128       /// The actual tree structure.
129       _Rep_type _M_t;
130
131     public:
132       // many of these are specified differently in ISO, but the following are
133       // "functionally equivalent"
134       typedef typename _Pair_alloc_type::pointer         pointer;
135       typedef typename _Pair_alloc_type::const_pointer   const_pointer;
136       typedef typename _Pair_alloc_type::reference       reference;
137       typedef typename _Pair_alloc_type::const_reference const_reference;
138       typedef typename _Rep_type::iterator               iterator;
139       typedef typename _Rep_type::const_iterator         const_iterator;
140       typedef typename _Rep_type::size_type              size_type;
141       typedef typename _Rep_type::difference_type        difference_type;
142       typedef typename _Rep_type::reverse_iterator       reverse_iterator;
143       typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
144
145       // [23.3.2] construct/copy/destroy
146       // (get_allocator() is also listed in this section)
147       /**
148        *  @brief  Default constructor creates no elements.
149        */
150       multimap()
151       : _M_t() { }
152
153       /**
154        *  @brief  Creates a %multimap with no elements.
155        *  @param  __comp  A comparison object.
156        *  @param  __a  An allocator object.
157        */
158       explicit
159       multimap(const _Compare& __comp,
160                const allocator_type& __a = allocator_type())
161       : _M_t(__comp, _Pair_alloc_type(__a)) { }
162
163       /**
164        *  @brief  %Multimap copy constructor.
165        *  @param  __x  A %multimap of identical element and allocator types.
166        *
167        *  The newly-created %multimap uses a copy of the allocation object
168        *  used by @a __x.
169        */
170       multimap(const multimap& __x)
171       : _M_t(__x._M_t) { }
172
173 #ifdef __GXX_EXPERIMENTAL_CXX0X__
174       /**
175        *  @brief  %Multimap move constructor.
176        *  @param   __x  A %multimap of identical element and allocator types.
177        *
178        *  The newly-created %multimap contains the exact contents of @a __x.
179        *  The contents of @a __x are a valid, but unspecified %multimap.
180        */
181       multimap(multimap&& __x)
182       noexcept(is_nothrow_copy_constructible<_Compare>::value)
183       : _M_t(std::move(__x._M_t)) { }
184
185       /**
186        *  @brief  Builds a %multimap from an initializer_list.
187        *  @param  __l  An initializer_list.
188        *  @param  __comp  A comparison functor.
189        *  @param  __a  An allocator object.
190        *
191        *  Create a %multimap consisting of copies of the elements from
192        *  the initializer_list.  This is linear in N if the list is already
193        *  sorted, and NlogN otherwise (where N is @a __l.size()).
194        */
195       multimap(initializer_list<value_type> __l,
196                const _Compare& __comp = _Compare(),
197                const allocator_type& __a = allocator_type())
198       : _M_t(__comp, _Pair_alloc_type(__a))
199       { _M_t._M_insert_equal(__l.begin(), __l.end()); }
200 #endif
201
202       /**
203        *  @brief  Builds a %multimap from a range.
204        *  @param  __first  An input iterator.
205        *  @param  __last  An input iterator.
206        *
207        *  Create a %multimap consisting of copies of the elements from
208        *  [__first,__last).  This is linear in N if the range is already sorted,
209        *  and NlogN otherwise (where N is distance(__first,__last)).
210        */
211       template<typename _InputIterator>
212         multimap(_InputIterator __first, _InputIterator __last)
213         : _M_t()
214         { _M_t._M_insert_equal(__first, __last); }
215
216       /**
217        *  @brief  Builds a %multimap from a range.
218        *  @param  __first  An input iterator.
219        *  @param  __last  An input iterator.
220        *  @param  __comp  A comparison functor.
221        *  @param  __a  An allocator object.
222        *
223        *  Create a %multimap consisting of copies of the elements from
224        *  [__first,__last).  This is linear in N if the range is already sorted,
225        *  and NlogN otherwise (where N is distance(__first,__last)).
226        */
227       template<typename _InputIterator>
228         multimap(_InputIterator __first, _InputIterator __last,
229                  const _Compare& __comp,
230                  const allocator_type& __a = allocator_type())
231         : _M_t(__comp, _Pair_alloc_type(__a))
232         { _M_t._M_insert_equal(__first, __last); }
233
234       // FIXME There is no dtor declared, but we should have something generated
235       // by Doxygen.  I don't know what tags to add to this paragraph to make
236       // that happen:
237       /**
238        *  The dtor only erases the elements, and note that if the elements
239        *  themselves are pointers, the pointed-to memory is not touched in any
240        *  way.  Managing the pointer is the user's responsibility.
241        */
242
243       /**
244        *  @brief  %Multimap assignment operator.
245        *  @param  __x  A %multimap of identical element and allocator types.
246        *
247        *  All the elements of @a __x are copied, but unlike the copy
248        *  constructor, the allocator object is not copied.
249        */
250       multimap&
251       operator=(const multimap& __x)
252       {
253         _M_t = __x._M_t;
254         return *this;
255       }
256
257 #ifdef __GXX_EXPERIMENTAL_CXX0X__
258       /**
259        *  @brief  %Multimap move assignment operator.
260        *  @param  __x  A %multimap of identical element and allocator types.
261        *
262        *  The contents of @a __x are moved into this multimap (without copying).
263        *  @a __x is a valid, but unspecified multimap.
264        */
265       multimap&
266       operator=(multimap&& __x)
267       {
268         // NB: DR 1204.
269         // NB: DR 675.
270         this->clear();
271         this->swap(__x);
272         return *this;
273       }
274
275       /**
276        *  @brief  %Multimap list assignment operator.
277        *  @param  __l  An initializer_list.
278        *
279        *  This function fills a %multimap with copies of the elements
280        *  in the initializer list @a __l.
281        *
282        *  Note that the assignment completely changes the %multimap and
283        *  that the resulting %multimap's size is the same as the number
284        *  of elements assigned.  Old data may be lost.
285        */
286       multimap&
287       operator=(initializer_list<value_type> __l)
288       {
289         this->clear();
290         this->insert(__l.begin(), __l.end());
291         return *this;
292       }
293 #endif
294
295       /// Get a copy of the memory allocation object.
296       allocator_type
297       get_allocator() const _GLIBCXX_NOEXCEPT 
298       { return allocator_type(_M_t.get_allocator()); }
299
300       // iterators
301       /**
302        *  Returns a read/write iterator that points to the first pair in the
303        *  %multimap.  Iteration is done in ascending order according to the
304        *  keys.
305        */
306       iterator
307       begin() _GLIBCXX_NOEXCEPT
308       { return _M_t.begin(); }
309
310       /**
311        *  Returns a read-only (constant) iterator that points to the first pair
312        *  in the %multimap.  Iteration is done in ascending order according to
313        *  the keys.
314        */
315       const_iterator
316       begin() const _GLIBCXX_NOEXCEPT
317       { return _M_t.begin(); }
318
319       /**
320        *  Returns a read/write iterator that points one past the last pair in
321        *  the %multimap.  Iteration is done in ascending order according to the
322        *  keys.
323        */
324       iterator
325       end() _GLIBCXX_NOEXCEPT
326       { return _M_t.end(); }
327
328       /**
329        *  Returns a read-only (constant) iterator that points one past the last
330        *  pair in the %multimap.  Iteration is done in ascending order according
331        *  to the keys.
332        */
333       const_iterator
334       end() const _GLIBCXX_NOEXCEPT
335       { return _M_t.end(); }
336
337       /**
338        *  Returns a read/write reverse iterator that points to the last pair in
339        *  the %multimap.  Iteration is done in descending order according to the
340        *  keys.
341        */
342       reverse_iterator
343       rbegin() _GLIBCXX_NOEXCEPT
344       { return _M_t.rbegin(); }
345
346       /**
347        *  Returns a read-only (constant) reverse iterator that points to the
348        *  last pair in the %multimap.  Iteration is done in descending order
349        *  according to the keys.
350        */
351       const_reverse_iterator
352       rbegin() const _GLIBCXX_NOEXCEPT
353       { return _M_t.rbegin(); }
354
355       /**
356        *  Returns a read/write reverse iterator that points to one before the
357        *  first pair in the %multimap.  Iteration is done in descending order
358        *  according to the keys.
359        */
360       reverse_iterator
361       rend() _GLIBCXX_NOEXCEPT
362       { return _M_t.rend(); }
363
364       /**
365        *  Returns a read-only (constant) reverse iterator that points to one
366        *  before the first pair in the %multimap.  Iteration is done in
367        *  descending order according to the keys.
368        */
369       const_reverse_iterator
370       rend() const _GLIBCXX_NOEXCEPT
371       { return _M_t.rend(); }
372
373 #ifdef __GXX_EXPERIMENTAL_CXX0X__
374       /**
375        *  Returns a read-only (constant) iterator that points to the first pair
376        *  in the %multimap.  Iteration is done in ascending order according to
377        *  the keys.
378        */
379       const_iterator
380       cbegin() const noexcept
381       { return _M_t.begin(); }
382
383       /**
384        *  Returns a read-only (constant) iterator that points one past the last
385        *  pair in the %multimap.  Iteration is done in ascending order according
386        *  to the keys.
387        */
388       const_iterator
389       cend() const noexcept
390       { return _M_t.end(); }
391
392       /**
393        *  Returns a read-only (constant) reverse iterator that points to the
394        *  last pair in the %multimap.  Iteration is done in descending order
395        *  according to the keys.
396        */
397       const_reverse_iterator
398       crbegin() const noexcept
399       { return _M_t.rbegin(); }
400
401       /**
402        *  Returns a read-only (constant) reverse iterator that points to one
403        *  before the first pair in the %multimap.  Iteration is done in
404        *  descending order according to the keys.
405        */
406       const_reverse_iterator
407       crend() const noexcept
408       { return _M_t.rend(); }
409 #endif
410
411       // capacity
412       /** Returns true if the %multimap is empty.  */
413       bool
414       empty() const _GLIBCXX_NOEXCEPT
415       { return _M_t.empty(); }
416
417       /** Returns the size of the %multimap.  */
418       size_type
419       size() const _GLIBCXX_NOEXCEPT
420       { return _M_t.size(); }
421
422       /** Returns the maximum size of the %multimap.  */
423       size_type
424       max_size() const _GLIBCXX_NOEXCEPT
425       { return _M_t.max_size(); }
426
427       // modifiers
428       /**
429        *  @brief Inserts a std::pair into the %multimap.
430        *  @param  __x  Pair to be inserted (see std::make_pair for easy creation
431        *             of pairs).
432        *  @return An iterator that points to the inserted (key,value) pair.
433        *
434        *  This function inserts a (key, value) pair into the %multimap.
435        *  Contrary to a std::map the %multimap does not rely on unique keys and
436        *  thus multiple pairs with the same key can be inserted.
437        *
438        *  Insertion requires logarithmic time.
439        */
440       iterator
441       insert(const value_type& __x)
442       { return _M_t._M_insert_equal(__x); }
443
444 #ifdef __GXX_EXPERIMENTAL_CXX0X__
445       template<typename _Pair, typename = typename
446                std::enable_if<std::is_convertible<_Pair,
447                                                   value_type>::value>::type>
448         iterator
449         insert(_Pair&& __x)
450         { return _M_t._M_insert_equal(std::forward<_Pair>(__x)); }
451 #endif
452
453       /**
454        *  @brief Inserts a std::pair into the %multimap.
455        *  @param  __position  An iterator that serves as a hint as to where the
456        *                      pair should be inserted.
457        *  @param  __x  Pair to be inserted (see std::make_pair for easy creation
458        *               of pairs).
459        *  @return An iterator that points to the inserted (key,value) pair.
460        *
461        *  This function inserts a (key, value) pair into the %multimap.
462        *  Contrary to a std::map the %multimap does not rely on unique keys and
463        *  thus multiple pairs with the same key can be inserted.
464        *  Note that the first parameter is only a hint and can potentially
465        *  improve the performance of the insertion process.  A bad hint would
466        *  cause no gains in efficiency.
467        *
468        *  For more on @a hinting, see:
469        *  http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt07ch17.html
470        *
471        *  Insertion requires logarithmic time (if the hint is not taken).
472        */
473       iterator
474 #ifdef __GXX_EXPERIMENTAL_CXX0X__
475       insert(const_iterator __position, const value_type& __x)
476 #else
477       insert(iterator __position, const value_type& __x)
478 #endif
479       { return _M_t._M_insert_equal_(__position, __x); }
480
481 #ifdef __GXX_EXPERIMENTAL_CXX0X__
482       template<typename _Pair, typename = typename
483                std::enable_if<std::is_convertible<_Pair,
484                                                   value_type>::value>::type>
485         iterator
486         insert(const_iterator __position, _Pair&& __x)
487         { return _M_t._M_insert_equal_(__position,
488                                        std::forward<_Pair>(__x)); }
489 #endif
490
491       /**
492        *  @brief A template function that attempts to insert a range
493        *  of elements.
494        *  @param  __first  Iterator pointing to the start of the range to be
495        *                   inserted.
496        *  @param  __last  Iterator pointing to the end of the range.
497        *
498        *  Complexity similar to that of the range constructor.
499        */
500       template<typename _InputIterator>
501         void
502         insert(_InputIterator __first, _InputIterator __last)
503         { _M_t._M_insert_equal(__first, __last); }
504
505 #ifdef __GXX_EXPERIMENTAL_CXX0X__
506       /**
507        *  @brief Attempts to insert a list of std::pairs into the %multimap.
508        *  @param  __l  A std::initializer_list<value_type> of pairs to be
509        *               inserted.
510        *
511        *  Complexity similar to that of the range constructor.
512        */
513       void
514       insert(initializer_list<value_type> __l)
515       { this->insert(__l.begin(), __l.end()); }
516 #endif
517
518 #ifdef __GXX_EXPERIMENTAL_CXX0X__
519       // _GLIBCXX_RESOLVE_LIB_DEFECTS
520       // DR 130. Associative erase should return an iterator.
521       /**
522        *  @brief Erases an element from a %multimap.
523        *  @param  __position  An iterator pointing to the element to be erased.
524        *  @return An iterator pointing to the element immediately following
525        *          @a position prior to the element being erased. If no such 
526        *          element exists, end() is returned.
527        *
528        *  This function erases an element, pointed to by the given iterator,
529        *  from a %multimap.  Note that this function only erases the element,
530        *  and that if the element is itself a pointer, the pointed-to memory is
531        *  not touched in any way.  Managing the pointer is the user's
532        *  responsibility.
533        */
534       iterator
535       erase(const_iterator __position)
536       { return _M_t.erase(__position); }
537 #else
538       /**
539        *  @brief Erases an element from a %multimap.
540        *  @param  __position  An iterator pointing to the element to be erased.
541        *
542        *  This function erases an element, pointed to by the given iterator,
543        *  from a %multimap.  Note that this function only erases the element,
544        *  and that if the element is itself a pointer, the pointed-to memory is
545        *  not touched in any way.  Managing the pointer is the user's
546        *  responsibility.
547        */
548       void
549       erase(iterator __position)
550       { _M_t.erase(__position); }
551 #endif
552
553       /**
554        *  @brief Erases elements according to the provided key.
555        *  @param  __x  Key of element to be erased.
556        *  @return  The number of elements erased.
557        *
558        *  This function erases all elements located by the given key from a
559        *  %multimap.
560        *  Note that this function only erases the element, and that if
561        *  the element is itself a pointer, the pointed-to memory is not touched
562        *  in any way.  Managing the pointer is the user's responsibility.
563        */
564       size_type
565       erase(const key_type& __x)
566       { return _M_t.erase(__x); }
567
568 #ifdef __GXX_EXPERIMENTAL_CXX0X__
569       // _GLIBCXX_RESOLVE_LIB_DEFECTS
570       // DR 130. Associative erase should return an iterator.
571       /**
572        *  @brief Erases a [first,last) range of elements from a %multimap.
573        *  @param  __first  Iterator pointing to the start of the range to be
574        *                   erased.
575        *  @param __last Iterator pointing to the end of the range to be
576        *                erased .
577        *  @return The iterator @a __last.
578        *
579        *  This function erases a sequence of elements from a %multimap.
580        *  Note that this function only erases the elements, and that if
581        *  the elements themselves are pointers, the pointed-to memory is not
582        *  touched in any way.  Managing the pointer is the user's
583        *  responsibility.
584        */
585       iterator
586       erase(const_iterator __first, const_iterator __last)
587       { return _M_t.erase(__first, __last); }
588 #else
589       // _GLIBCXX_RESOLVE_LIB_DEFECTS
590       // DR 130. Associative erase should return an iterator.
591       /**
592        *  @brief Erases a [first,last) range of elements from a %multimap.
593        *  @param  __first  Iterator pointing to the start of the range to be
594        *                 erased.
595        *  @param __last Iterator pointing to the end of the range to
596        *                be erased.
597        *
598        *  This function erases a sequence of elements from a %multimap.
599        *  Note that this function only erases the elements, and that if
600        *  the elements themselves are pointers, the pointed-to memory is not
601        *  touched in any way.  Managing the pointer is the user's
602        *  responsibility.
603        */
604       void
605       erase(iterator __first, iterator __last)
606       { _M_t.erase(__first, __last); }
607 #endif
608
609       /**
610        *  @brief  Swaps data with another %multimap.
611        *  @param  __x  A %multimap of the same element and allocator types.
612        *
613        *  This exchanges the elements between two multimaps in constant time.
614        *  (It is only swapping a pointer, an integer, and an instance of
615        *  the @c Compare type (which itself is often stateless and empty), so it
616        *  should be quite fast.)
617        *  Note that the global std::swap() function is specialized such that
618        *  std::swap(m1,m2) will feed to this function.
619        */
620       void
621       swap(multimap& __x)
622       { _M_t.swap(__x._M_t); }
623
624       /**
625        *  Erases all elements in a %multimap.  Note that this function only
626        *  erases the elements, and that if the elements themselves are pointers,
627        *  the pointed-to memory is not touched in any way.  Managing the pointer
628        *  is the user's responsibility.
629        */
630       void
631       clear() _GLIBCXX_NOEXCEPT
632       { _M_t.clear(); }
633
634       // observers
635       /**
636        *  Returns the key comparison object out of which the %multimap
637        *  was constructed.
638        */
639       key_compare
640       key_comp() const
641       { return _M_t.key_comp(); }
642
643       /**
644        *  Returns a value comparison object, built from the key comparison
645        *  object out of which the %multimap was constructed.
646        */
647       value_compare
648       value_comp() const
649       { return value_compare(_M_t.key_comp()); }
650
651       // multimap operations
652       /**
653        *  @brief Tries to locate an element in a %multimap.
654        *  @param  __x  Key of (key, value) pair to be located.
655        *  @return  Iterator pointing to sought-after element,
656        *           or end() if not found.
657        *
658        *  This function takes a key and tries to locate the element with which
659        *  the key matches.  If successful the function returns an iterator
660        *  pointing to the sought after %pair.  If unsuccessful it returns the
661        *  past-the-end ( @c end() ) iterator.
662        */
663       iterator
664       find(const key_type& __x)
665       { return _M_t.find(__x); }
666
667       /**
668        *  @brief Tries to locate an element in a %multimap.
669        *  @param  __x  Key of (key, value) pair to be located.
670        *  @return  Read-only (constant) iterator pointing to sought-after
671        *           element, or end() if not found.
672        *
673        *  This function takes a key and tries to locate the element with which
674        *  the key matches.  If successful the function returns a constant
675        *  iterator pointing to the sought after %pair.  If unsuccessful it
676        *  returns the past-the-end ( @c end() ) iterator.
677        */
678       const_iterator
679       find(const key_type& __x) const
680       { return _M_t.find(__x); }
681
682       /**
683        *  @brief Finds the number of elements with given key.
684        *  @param  __x  Key of (key, value) pairs to be located.
685        *  @return Number of elements with specified key.
686        */
687       size_type
688       count(const key_type& __x) const
689       { return _M_t.count(__x); }
690
691       /**
692        *  @brief Finds the beginning of a subsequence matching given key.
693        *  @param  __x  Key of (key, value) pair to be located.
694        *  @return  Iterator pointing to first element equal to or greater
695        *           than key, or end().
696        *
697        *  This function returns the first element of a subsequence of elements
698        *  that matches the given key.  If unsuccessful it returns an iterator
699        *  pointing to the first element that has a greater value than given key
700        *  or end() if no such element exists.
701        */
702       iterator
703       lower_bound(const key_type& __x)
704       { return _M_t.lower_bound(__x); }
705
706       /**
707        *  @brief Finds the beginning of a subsequence matching given key.
708        *  @param  __x  Key of (key, value) pair to be located.
709        *  @return  Read-only (constant) iterator pointing to first element
710        *           equal to or greater than key, or end().
711        *
712        *  This function returns the first element of a subsequence of
713        *  elements that matches the given key.  If unsuccessful the
714        *  iterator will point to the next greatest element or, if no
715        *  such greater element exists, to end().
716        */
717       const_iterator
718       lower_bound(const key_type& __x) const
719       { return _M_t.lower_bound(__x); }
720
721       /**
722        *  @brief Finds the end of a subsequence matching given key.
723        *  @param  __x  Key of (key, value) pair to be located.
724        *  @return Iterator pointing to the first element
725        *          greater than key, or end().
726        */
727       iterator
728       upper_bound(const key_type& __x)
729       { return _M_t.upper_bound(__x); }
730
731       /**
732        *  @brief Finds the end of a subsequence matching given key.
733        *  @param  __x  Key of (key, value) pair to be located.
734        *  @return  Read-only (constant) iterator pointing to first iterator
735        *           greater than key, or end().
736        */
737       const_iterator
738       upper_bound(const key_type& __x) const
739       { return _M_t.upper_bound(__x); }
740
741       /**
742        *  @brief Finds a subsequence matching given key.
743        *  @param  __x  Key of (key, value) pairs to be located.
744        *  @return  Pair of iterators that possibly points to the subsequence
745        *           matching given key.
746        *
747        *  This function is equivalent to
748        *  @code
749        *    std::make_pair(c.lower_bound(val),
750        *                   c.upper_bound(val))
751        *  @endcode
752        *  (but is faster than making the calls separately).
753        */
754       std::pair<iterator, iterator>
755       equal_range(const key_type& __x)
756       { return _M_t.equal_range(__x); }
757
758       /**
759        *  @brief Finds a subsequence matching given key.
760        *  @param  __x  Key of (key, value) pairs to be located.
761        *  @return  Pair of read-only (constant) iterators that possibly points
762        *           to the subsequence matching given key.
763        *
764        *  This function is equivalent to
765        *  @code
766        *    std::make_pair(c.lower_bound(val),
767        *                   c.upper_bound(val))
768        *  @endcode
769        *  (but is faster than making the calls separately).
770        */
771       std::pair<const_iterator, const_iterator>
772       equal_range(const key_type& __x) const
773       { return _M_t.equal_range(__x); }
774
775       template<typename _K1, typename _T1, typename _C1, typename _A1>
776         friend bool
777         operator==(const multimap<_K1, _T1, _C1, _A1>&,
778                    const multimap<_K1, _T1, _C1, _A1>&);
779
780       template<typename _K1, typename _T1, typename _C1, typename _A1>
781         friend bool
782         operator<(const multimap<_K1, _T1, _C1, _A1>&,
783                   const multimap<_K1, _T1, _C1, _A1>&);
784   };
785
786   /**
787    *  @brief  Multimap equality comparison.
788    *  @param  __x  A %multimap.
789    *  @param  __y  A %multimap of the same type as @a __x.
790    *  @return  True iff the size and elements of the maps are equal.
791    *
792    *  This is an equivalence relation.  It is linear in the size of the
793    *  multimaps.  Multimaps are considered equivalent if their sizes are equal,
794    *  and if corresponding elements compare equal.
795   */
796   template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
797     inline bool
798     operator==(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
799                const multimap<_Key, _Tp, _Compare, _Alloc>& __y)
800     { return __x._M_t == __y._M_t; }
801
802   /**
803    *  @brief  Multimap ordering relation.
804    *  @param  __x  A %multimap.
805    *  @param  __y  A %multimap of the same type as @a __x.
806    *  @return  True iff @a x is lexicographically less than @a y.
807    *
808    *  This is a total ordering relation.  It is linear in the size of the
809    *  multimaps.  The elements must be comparable with @c <.
810    *
811    *  See std::lexicographical_compare() for how the determination is made.
812   */
813   template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
814     inline bool
815     operator<(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
816               const multimap<_Key, _Tp, _Compare, _Alloc>& __y)
817     { return __x._M_t < __y._M_t; }
818
819   /// Based on operator==
820   template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
821     inline bool
822     operator!=(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
823                const multimap<_Key, _Tp, _Compare, _Alloc>& __y)
824     { return !(__x == __y); }
825
826   /// Based on operator<
827   template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
828     inline bool
829     operator>(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
830               const multimap<_Key, _Tp, _Compare, _Alloc>& __y)
831     { return __y < __x; }
832
833   /// Based on operator<
834   template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
835     inline bool
836     operator<=(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
837                const multimap<_Key, _Tp, _Compare, _Alloc>& __y)
838     { return !(__y < __x); }
839
840   /// Based on operator<
841   template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
842     inline bool
843     operator>=(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
844                const multimap<_Key, _Tp, _Compare, _Alloc>& __y)
845     { return !(__x < __y); }
846
847   /// See std::multimap::swap().
848   template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
849     inline void
850     swap(multimap<_Key, _Tp, _Compare, _Alloc>& __x,
851          multimap<_Key, _Tp, _Compare, _Alloc>& __y)
852     { __x.swap(__y); }
853
854 _GLIBCXX_END_NAMESPACE_CONTAINER
855 } // namespace std
856
857 #endif /* _STL_MULTIMAP_H */