OSDN Git Service

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