stl_map.h

Go to the documentation of this file.
00001 // Map implementation -*- C++ -*-
00002 
00003 // Copyright (C) 2001, 2002, 2004, 2005 Free Software Foundation, Inc.
00004 //
00005 // This file is part of the GNU ISO C++ Library.  This library is free
00006 // software; you can redistribute it and/or modify it under the
00007 // terms of the GNU General Public License as published by the
00008 // Free Software Foundation; either version 2, or (at your option)
00009 // any later version.
00010 
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 
00016 // You should have received a copy of the GNU General Public License along
00017 // with this library; see the file COPYING.  If not, write to the Free
00018 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
00019 // USA.
00020 
00021 // As a special exception, you may use this file as part of a free software
00022 // library without restriction.  Specifically, if other files instantiate
00023 // templates or use macros or inline functions from this file, or you compile
00024 // this file and link it with other files to produce an executable, this
00025 // file does not by itself cause the resulting executable to be covered by
00026 // the GNU General Public License.  This exception does not however
00027 // invalidate any other reasons why the executable file might be covered by
00028 // the GNU General Public License.
00029 
00030 /*
00031  *
00032  * Copyright (c) 1994
00033  * Hewlett-Packard Company
00034  *
00035  * Permission to use, copy, modify, distribute and sell this software
00036  * and its documentation for any purpose is hereby granted without fee,
00037  * provided that the above copyright notice appear in all copies and
00038  * that both that copyright notice and this permission notice appear
00039  * in supporting documentation.  Hewlett-Packard Company makes no
00040  * representations about the suitability of this software for any
00041  * purpose.  It is provided "as is" without express or implied warranty.
00042  *
00043  *
00044  * Copyright (c) 1996,1997
00045  * Silicon Graphics Computer Systems, Inc.
00046  *
00047  * Permission to use, copy, modify, distribute and sell this software
00048  * and its documentation for any purpose is hereby granted without fee,
00049  * provided that the above copyright notice appear in all copies and
00050  * that both that copyright notice and this permission notice appear
00051  * in supporting documentation.  Silicon Graphics makes no
00052  * representations about the suitability of this software for any
00053  * purpose.  It is provided "as is" without express or implied warranty.
00054  */
00055 
00056 /** @file stl_map.h
00057  *  This is an internal header file, included by other library headers.
00058  *  You should not attempt to use it directly.
00059  */
00060 
00061 #ifndef _MAP_H
00062 #define _MAP_H 1
00063 
00064 #include <bits/functexcept.h>
00065 #include <bits/concept_check.h>
00066 
00067 namespace _GLIBCXX_STD
00068 {
00069   /**
00070    *  @brief A standard container made up of (key,value) pairs, which can be
00071    *  retrieved based on a key, in logarithmic time.
00072    *
00073    *  @ingroup Containers
00074    *  @ingroup Assoc_containers
00075    *
00076    *  Meets the requirements of a <a href="tables.html#65">container</a>, a
00077    *  <a href="tables.html#66">reversible container</a>, and an
00078    *  <a href="tables.html#69">associative container</a> (using unique keys).
00079    *  For a @c map<Key,T> the key_type is Key, the mapped_type is T, and the
00080    *  value_type is std::pair<const Key,T>.
00081    *
00082    *  Maps support bidirectional iterators.
00083    *
00084    *  @if maint
00085    *  The private tree data is declared exactly the same way for map and
00086    *  multimap; the distinction is made entirely in how the tree functions are
00087    *  called (*_unique versus *_equal, same as the standard).
00088    *  @endif
00089   */
00090   template <typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
00091             typename _Alloc = std::allocator<std::pair<const _Key, _Tp> > >
00092     class map
00093     {
00094     public:
00095       typedef _Key                                          key_type;
00096       typedef _Tp                                           mapped_type;
00097       typedef std::pair<const _Key, _Tp>                    value_type;
00098       typedef _Compare                                      key_compare;
00099       typedef _Alloc                                        allocator_type;
00100 
00101     private:
00102       // concept requirements
00103       typedef typename _Alloc::value_type                   _Alloc_value_type;
00104       __glibcxx_class_requires(_Tp, _SGIAssignableConcept)
00105       __glibcxx_class_requires4(_Compare, bool, _Key, _Key,
00106                 _BinaryFunctionConcept)
00107       __glibcxx_class_requires2(value_type, _Alloc_value_type, _SameTypeConcept)
00108 
00109     public:
00110       class value_compare
00111       : public std::binary_function<value_type, value_type, bool>
00112       {
00113     friend class map<_Key, _Tp, _Compare, _Alloc>;
00114       protected:
00115     _Compare comp;
00116 
00117     value_compare(_Compare __c)
00118     : comp(__c) { }
00119 
00120       public:
00121     bool operator()(const value_type& __x, const value_type& __y) const
00122     { return comp(__x.first, __y.first); }
00123       };
00124 
00125     private:
00126       /// @if maint  This turns a red-black tree into a [multi]map.  @endif
00127       typedef typename _Alloc::template rebind<value_type>::other 
00128         _Pair_alloc_type;
00129 
00130       typedef _Rb_tree<key_type, value_type, _Select1st<value_type>,
00131                key_compare, _Pair_alloc_type> _Rep_type;
00132 
00133       /// @if maint  The actual tree structure.  @endif
00134       _Rep_type _M_t;
00135 
00136     public:
00137       // many of these are specified differently in ISO, but the following are
00138       // "functionally equivalent"
00139       typedef typename _Pair_alloc_type::pointer         pointer;
00140       typedef typename _Pair_alloc_type::const_pointer   const_pointer;
00141       typedef typename _Pair_alloc_type::reference       reference;
00142       typedef typename _Pair_alloc_type::const_reference const_reference;
00143       typedef typename _Rep_type::iterator               iterator;
00144       typedef typename _Rep_type::const_iterator         const_iterator;
00145       typedef typename _Rep_type::size_type              size_type;
00146       typedef typename _Rep_type::difference_type        difference_type;
00147       typedef typename _Rep_type::reverse_iterator       reverse_iterator;
00148       typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
00149 
00150       // [23.3.1.1] construct/copy/destroy
00151       // (get_allocator() is normally listed in this section, but seems to have
00152       // been accidentally omitted in the printed standard)
00153       /**
00154        *  @brief  Default constructor creates no elements.
00155        */
00156       map()
00157       : _M_t(_Compare(), allocator_type()) { }
00158 
00159       // for some reason this was made a separate function
00160       /**
00161        *  @brief  Default constructor creates no elements.
00162        */
00163       explicit
00164       map(const _Compare& __comp, const allocator_type& __a = allocator_type())
00165       : _M_t(__comp, __a) { }
00166 
00167       /**
00168        *  @brief  Map copy constructor.
00169        *  @param  x  A %map of identical element and allocator types.
00170        *
00171        *  The newly-created %map uses a copy of the allocation object used
00172        *  by @a x.
00173        */
00174       map(const map& __x)
00175       : _M_t(__x._M_t) { }
00176 
00177       /**
00178        *  @brief  Builds a %map from a range.
00179        *  @param  first  An input iterator.
00180        *  @param  last  An input iterator.
00181        *
00182        *  Create a %map consisting of copies of the elements from [first,last).
00183        *  This is linear in N if the range is already sorted, and NlogN
00184        *  otherwise (where N is distance(first,last)).
00185        */
00186       template <typename _InputIterator>
00187         map(_InputIterator __first, _InputIterator __last)
00188     : _M_t(_Compare(), allocator_type())
00189         { _M_t.insert_unique(__first, __last); }
00190 
00191       /**
00192        *  @brief  Builds a %map from a range.
00193        *  @param  first  An input iterator.
00194        *  @param  last  An input iterator.
00195        *  @param  comp  A comparison functor.
00196        *  @param  a  An allocator object.
00197        *
00198        *  Create a %map consisting of copies of the elements from [first,last).
00199        *  This is linear in N if the range is already sorted, and NlogN
00200        *  otherwise (where N is distance(first,last)).
00201        */
00202       template <typename _InputIterator>
00203         map(_InputIterator __first, _InputIterator __last,
00204         const _Compare& __comp, const allocator_type& __a = allocator_type())
00205     : _M_t(__comp, __a)
00206         { _M_t.insert_unique(__first, __last); }
00207 
00208       // FIXME There is no dtor declared, but we should have something generated
00209       // by Doxygen.  I don't know what tags to add to this paragraph to make
00210       // that happen:
00211       /**
00212        *  The dtor only erases the elements, and note that if the elements
00213        *  themselves are pointers, the pointed-to memory is not touched in any
00214        *  way.  Managing the pointer is the user's responsibilty.
00215        */
00216 
00217       /**
00218        *  @brief  Map assignment operator.
00219        *  @param  x  A %map of identical element and allocator types.
00220        *
00221        *  All the elements of @a x are copied, but unlike the copy constructor,
00222        *  the allocator object is not copied.
00223        */
00224       map&
00225       operator=(const map& __x)
00226       {
00227     _M_t = __x._M_t;
00228     return *this;
00229       }
00230 
00231       /// Get a copy of the memory allocation object.
00232       allocator_type
00233       get_allocator() const
00234       { return _M_t.get_allocator(); }
00235 
00236       // iterators
00237       /**
00238        *  Returns a read/write iterator that points to the first pair in the
00239        *  %map.
00240        *  Iteration is done in ascending order according to the keys.
00241        */
00242       iterator
00243       begin()
00244       { return _M_t.begin(); }
00245 
00246       /**
00247        *  Returns a read-only (constant) iterator that points to the first pair
00248        *  in the %map.  Iteration is done in ascending order according to the
00249        *  keys.
00250        */
00251       const_iterator
00252       begin() const
00253       { return _M_t.begin(); }
00254 
00255       /**
00256        *  Returns a read/write iterator that points one past the last pair in
00257        *  the %map.  Iteration is done in ascending order according to the keys.
00258        */
00259       iterator
00260       end()
00261       { return _M_t.end(); }
00262 
00263       /**
00264        *  Returns a read-only (constant) iterator that points one past the last
00265        *  pair in the %map.  Iteration is done in ascending order according to
00266        *  the keys.
00267        */
00268       const_iterator
00269       end() const
00270       { return _M_t.end(); }
00271 
00272       /**
00273        *  Returns a read/write reverse iterator that points to the last pair in
00274        *  the %map.  Iteration is done in descending order according to the
00275        *  keys.
00276        */
00277       reverse_iterator
00278       rbegin()
00279       { return _M_t.rbegin(); }
00280 
00281       /**
00282        *  Returns a read-only (constant) reverse iterator that points to the
00283        *  last pair in the %map.  Iteration is done in descending order
00284        *  according to the keys.
00285        */
00286       const_reverse_iterator
00287       rbegin() const
00288       { return _M_t.rbegin(); }
00289 
00290       /**
00291        *  Returns a read/write reverse iterator that points to one before the
00292        *  first pair in the %map.  Iteration is done in descending order
00293        *  according to the keys.
00294        */
00295       reverse_iterator
00296       rend()
00297       { return _M_t.rend(); }
00298 
00299       /**
00300        *  Returns a read-only (constant) reverse iterator that points to one
00301        *  before the first pair in the %map.  Iteration is done in descending
00302        *  order according to the keys.
00303        */
00304       const_reverse_iterator
00305       rend() const
00306       { return _M_t.rend(); }
00307 
00308       // capacity
00309       /** Returns true if the %map is empty.  (Thus begin() would equal
00310        *  end().)
00311       */
00312       bool
00313       empty() const
00314       { return _M_t.empty(); }
00315 
00316       /** Returns the size of the %map.  */
00317       size_type
00318       size() const
00319       { return _M_t.size(); }
00320 
00321       /** Returns the maximum size of the %map.  */
00322       size_type
00323       max_size() const
00324       { return _M_t.max_size(); }
00325 
00326       // [23.3.1.2] element access
00327       /**
00328        *  @brief  Subscript ( @c [] ) access to %map data.
00329        *  @param  k  The key for which data should be retrieved.
00330        *  @return  A reference to the data of the (key,data) %pair.
00331        *
00332        *  Allows for easy lookup with the subscript ( @c [] ) operator.  Returns
00333        *  data associated with the key specified in subscript.  If the key does
00334        *  not exist, a pair with that key is created using default values, which
00335        *  is then returned.
00336        *
00337        *  Lookup requires logarithmic time.
00338        */
00339       mapped_type&
00340       operator[](const key_type& __k)
00341       {
00342     // concept requirements
00343     __glibcxx_function_requires(_DefaultConstructibleConcept<mapped_type>)
00344 
00345     iterator __i = lower_bound(__k);
00346     // __i->first is greater than or equivalent to __k.
00347     if (__i == end() || key_comp()(__k, (*__i).first))
00348           __i = insert(__i, value_type(__k, mapped_type()));
00349     return (*__i).second;
00350       }
00351 
00352       // _GLIBCXX_RESOLVE_LIB_DEFECTS
00353       // DR 464. Suggestion for new member functions in standard containers.
00354       /**
00355        *  @brief  Access to %map data.
00356        *  @param  k  The key for which data should be retrieved.
00357        *  @return  A reference to the data whose key is equivalent to @a k, if
00358        *           such a data is present in the %map.
00359        *  @throw  std::out_of_range  If no such data is present.
00360        */
00361       mapped_type&
00362       at(const key_type& __k)
00363       {
00364     iterator __i = lower_bound(__k);
00365     if (__i == end() || key_comp()(__k, (*__i).first))
00366       __throw_out_of_range(__N("map::at"));
00367     return (*__i).second;
00368       }
00369 
00370       const mapped_type&
00371       at(const key_type& __k) const
00372       {
00373     const_iterator __i = lower_bound(__k);
00374     if (__i == end() || key_comp()(__k, (*__i).first))
00375       __throw_out_of_range(__N("map::at"));
00376     return (*__i).second;
00377       }
00378 
00379       // modifiers
00380       /**
00381        *  @brief Attempts to insert a std::pair into the %map.
00382        *  @param  x  Pair to be inserted (see std::make_pair for easy creation of
00383        *             pairs).
00384        *  @return  A pair, of which the first element is an iterator that points
00385        *           to the possibly inserted pair, and the second is a bool that
00386        *           is true if the pair was actually inserted.
00387        *
00388        *  This function attempts to insert a (key, value) %pair into the %map.
00389        *  A %map relies on unique keys and thus a %pair is only inserted if its
00390        *  first element (the key) is not already present in the %map.
00391        *
00392        *  Insertion requires logarithmic time.
00393        */
00394       std::pair<iterator,bool>
00395       insert(const value_type& __x)
00396       { return _M_t.insert_unique(__x); }
00397 
00398       /**
00399        *  @brief Attempts to insert a std::pair into the %map.
00400        *  @param  position  An iterator that serves as a hint as to where the
00401        *                    pair should be inserted.
00402        *  @param  x  Pair to be inserted (see std::make_pair for easy creation of
00403        *             pairs).
00404        *  @return  An iterator that points to the element with key of @a x (may
00405        *           or may not be the %pair passed in).
00406        *
00407        *  This function is not concerned about whether the insertion took place,
00408        *  and thus does not return a boolean like the single-argument
00409        *  insert() does.  Note that the first parameter is only a hint and can
00410        *  potentially improve the performance of the insertion process.  A bad
00411        *  hint would cause no gains in efficiency.
00412        *
00413        *  See http://gcc.gnu.org/onlinedocs/libstdc++/23_containers/howto.html#4
00414        *  for more on "hinting".
00415        *
00416        *  Insertion requires logarithmic time (if the hint is not taken).
00417        */
00418       iterator
00419       insert(iterator position, const value_type& __x)
00420       { return _M_t.insert_unique(position, __x); }
00421 
00422       /**
00423        *  @brief A template function that attemps to insert a range of elements.
00424        *  @param  first  Iterator pointing to the start of the range to be
00425        *                 inserted.
00426        *  @param  last  Iterator pointing to the end of the range.
00427        *
00428        *  Complexity similar to that of the range constructor.
00429        */
00430       template <typename _InputIterator>
00431         void
00432         insert(_InputIterator __first, _InputIterator __last)
00433         { _M_t.insert_unique(__first, __last); }
00434 
00435       /**
00436        *  @brief Erases an element from a %map.
00437        *  @param  position  An iterator pointing to the element to be erased.
00438        *
00439        *  This function erases an element, pointed to by the given iterator,
00440        *  from a %map.  Note that this function only erases the element, and
00441        *  that if the element is itself a pointer, the pointed-to memory is not
00442        *  touched in any way.  Managing the pointer is the user's responsibilty.
00443        */
00444       void
00445       erase(iterator __position)
00446       { _M_t.erase(__position); }
00447 
00448       /**
00449        *  @brief Erases elements according to the provided key.
00450        *  @param  x  Key of element to be erased.
00451        *  @return  The number of elements erased.
00452        *
00453        *  This function erases all the elements located by the given key from
00454        *  a %map.
00455        *  Note that this function only erases the element, and that if
00456        *  the element is itself a pointer, the pointed-to memory is not touched
00457        *  in any way.  Managing the pointer is the user's responsibilty.
00458        */
00459       size_type
00460       erase(const key_type& __x)
00461       { return _M_t.erase(__x); }
00462 
00463       /**
00464        *  @brief Erases a [first,last) range of elements from a %map.
00465        *  @param  first  Iterator pointing to the start of the range to be
00466        *                 erased.
00467        *  @param  last  Iterator pointing to the end of the range to be erased.
00468        *
00469        *  This function erases a sequence of elements from a %map.
00470        *  Note that this function only erases the element, and that if
00471        *  the element is itself a pointer, the pointed-to memory is not touched
00472        *  in any way.  Managing the pointer is the user's responsibilty.
00473        */
00474       void
00475       erase(iterator __first, iterator __last)
00476       { _M_t.erase(__first, __last); }
00477 
00478       /**
00479        *  @brief  Swaps data with another %map.
00480        *  @param  x  A %map of the same element and allocator types.
00481        *
00482        *  This exchanges the elements between two maps in constant time.
00483        *  (It is only swapping a pointer, an integer, and an instance of
00484        *  the @c Compare type (which itself is often stateless and empty), so it
00485        *  should be quite fast.)
00486        *  Note that the global std::swap() function is specialized such that
00487        *  std::swap(m1,m2) will feed to this function.
00488        */
00489       void
00490       swap(map& __x)
00491       { _M_t.swap(__x._M_t); }
00492 
00493       /**
00494        *  Erases all elements in a %map.  Note that this function only erases
00495        *  the elements, and that if the elements themselves are pointers, the
00496        *  pointed-to memory is not touched in any way.  Managing the pointer is
00497        *  the user's responsibilty.
00498        */
00499       void
00500       clear()
00501       { _M_t.clear(); }
00502 
00503       // observers
00504       /**
00505        *  Returns the key comparison object out of which the %map was
00506        *  constructed.
00507        */
00508       key_compare
00509       key_comp() const
00510       { return _M_t.key_comp(); }
00511 
00512       /**
00513        *  Returns a value comparison object, built from the key comparison
00514        *  object out of which the %map was constructed.
00515        */
00516       value_compare
00517       value_comp() const
00518       { return value_compare(_M_t.key_comp()); }
00519 
00520       // [23.3.1.3] map operations
00521       /**
00522        *  @brief Tries to locate an element in a %map.
00523        *  @param  x  Key of (key, value) %pair to be located.
00524        *  @return  Iterator pointing to sought-after element, or end() if not
00525        *           found.
00526        *
00527        *  This function takes a key and tries to locate the element with which
00528        *  the key matches.  If successful the function returns an iterator
00529        *  pointing to the sought after %pair.  If unsuccessful it returns the
00530        *  past-the-end ( @c end() ) iterator.
00531        */
00532       iterator
00533       find(const key_type& __x)
00534       { return _M_t.find(__x); }
00535 
00536       /**
00537        *  @brief Tries to locate an element in a %map.
00538        *  @param  x  Key of (key, value) %pair to be located.
00539        *  @return  Read-only (constant) iterator pointing to sought-after
00540        *           element, or end() if not found.
00541        *
00542        *  This function takes a key and tries to locate the element with which
00543        *  the key matches.  If successful the function returns a constant
00544        *  iterator pointing to the sought after %pair. If unsuccessful it
00545        *  returns the past-the-end ( @c end() ) iterator.
00546        */
00547       const_iterator
00548       find(const key_type& __x) const
00549       { return _M_t.find(__x); }
00550 
00551       /**
00552        *  @brief  Finds the number of elements with given key.
00553        *  @param  x  Key of (key, value) pairs to be located.
00554        *  @return  Number of elements with specified key.
00555        *
00556        *  This function only makes sense for multimaps; for map the result will
00557        *  either be 0 (not present) or 1 (present).
00558        */
00559       size_type
00560       count(const key_type& __x) const
00561       { return _M_t.find(__x) == _M_t.end() ? 0 : 1; }
00562 
00563       /**
00564        *  @brief Finds the beginning of a subsequence matching given key.
00565        *  @param  x  Key of (key, value) pair to be located.
00566        *  @return  Iterator pointing to first element equal to or greater
00567        *           than key, or end().
00568        *
00569        *  This function returns the first element of a subsequence of elements
00570        *  that matches the given key.  If unsuccessful it returns an iterator
00571        *  pointing to the first element that has a greater value than given key
00572        *  or end() if no such element exists.
00573        */
00574       iterator
00575       lower_bound(const key_type& __x)
00576       { return _M_t.lower_bound(__x); }
00577 
00578       /**
00579        *  @brief Finds the beginning of a subsequence matching given key.
00580        *  @param  x  Key of (key, value) pair to be located.
00581        *  @return  Read-only (constant) iterator pointing to first element
00582        *           equal to or greater than key, or end().
00583        *
00584        *  This function returns the first element of a subsequence of elements
00585        *  that matches the given key.  If unsuccessful it returns an iterator
00586        *  pointing to the first element that has a greater value than given key
00587        *  or end() if no such element exists.
00588        */
00589       const_iterator
00590       lower_bound(const key_type& __x) const
00591       { return _M_t.lower_bound(__x); }
00592 
00593       /**
00594        *  @brief Finds the end of a subsequence matching given key.
00595        *  @param  x  Key of (key, value) pair to be located.
00596        *  @return Iterator pointing to the first element
00597        *          greater than key, or end().
00598        */
00599       iterator
00600       upper_bound(const key_type& __x)
00601       { return _M_t.upper_bound(__x); }
00602 
00603       /**
00604        *  @brief Finds the end of a subsequence matching given key.
00605        *  @param  x  Key of (key, value) pair to be located.
00606        *  @return  Read-only (constant) iterator pointing to first iterator
00607        *           greater than key, or end().
00608        */
00609       const_iterator
00610       upper_bound(const key_type& __x) const
00611       { return _M_t.upper_bound(__x); }
00612 
00613       /**
00614        *  @brief Finds a subsequence matching given key.
00615        *  @param  x  Key of (key, value) pairs to be located.
00616        *  @return  Pair of iterators that possibly points to the subsequence
00617        *           matching given key.
00618        *
00619        *  This function is equivalent to
00620        *  @code
00621        *    std::make_pair(c.lower_bound(val),
00622        *                   c.upper_bound(val))
00623        *  @endcode
00624        *  (but is faster than making the calls separately).
00625        *
00626        *  This function probably only makes sense for multimaps.
00627        */
00628       std::pair<iterator, iterator>
00629       equal_range(const key_type& __x)
00630       { return _M_t.equal_range(__x); }
00631 
00632       /**
00633        *  @brief Finds a subsequence matching given key.
00634        *  @param  x  Key of (key, value) pairs to be located.
00635        *  @return  Pair of read-only (constant) iterators that possibly points
00636        *           to the subsequence matching given key.
00637        *
00638        *  This function is equivalent to
00639        *  @code
00640        *    std::make_pair(c.lower_bound(val),
00641        *                   c.upper_bound(val))
00642        *  @endcode
00643        *  (but is faster than making the calls separately).
00644        *
00645        *  This function probably only makes sense for multimaps.
00646        */
00647       std::pair<const_iterator, const_iterator>
00648       equal_range(const key_type& __x) const
00649       { return _M_t.equal_range(__x); }
00650 
00651       template <typename _K1, typename _T1, typename _C1, typename _A1>
00652         friend bool
00653         operator== (const map<_K1, _T1, _C1, _A1>&,
00654             const map<_K1, _T1, _C1, _A1>&);
00655 
00656       template <typename _K1, typename _T1, typename _C1, typename _A1>
00657         friend bool
00658         operator< (const map<_K1, _T1, _C1, _A1>&,
00659            const map<_K1, _T1, _C1, _A1>&);
00660     };
00661 
00662   /**
00663    *  @brief  Map equality comparison.
00664    *  @param  x  A %map.
00665    *  @param  y  A %map of the same type as @a x.
00666    *  @return  True iff the size and elements of the maps are equal.
00667    *
00668    *  This is an equivalence relation.  It is linear in the size of the
00669    *  maps.  Maps are considered equivalent if their sizes are equal,
00670    *  and if corresponding elements compare equal.
00671   */
00672   template <typename _Key, typename _Tp, typename _Compare, typename _Alloc>
00673     inline bool
00674     operator==(const map<_Key, _Tp, _Compare, _Alloc>& __x,
00675                const map<_Key, _Tp, _Compare, _Alloc>& __y)
00676     { return __x._M_t == __y._M_t; }
00677 
00678   /**
00679    *  @brief  Map ordering relation.
00680    *  @param  x  A %map.
00681    *  @param  y  A %map of the same type as @a x.
00682    *  @return  True iff @a x is lexicographically less than @a y.
00683    *
00684    *  This is a total ordering relation.  It is linear in the size of the
00685    *  maps.  The elements must be comparable with @c <.
00686    *
00687    *  See std::lexicographical_compare() for how the determination is made.
00688   */
00689   template <typename _Key, typename _Tp, typename _Compare, typename _Alloc>
00690     inline bool
00691     operator<(const map<_Key, _Tp, _Compare, _Alloc>& __x,
00692               const map<_Key, _Tp, _Compare, _Alloc>& __y)
00693     { return __x._M_t < __y._M_t; }
00694 
00695   /// Based on operator==
00696   template <typename _Key, typename _Tp, typename _Compare, typename _Alloc>
00697     inline bool
00698     operator!=(const map<_Key, _Tp, _Compare, _Alloc>& __x,
00699                const map<_Key, _Tp, _Compare, _Alloc>& __y)
00700     { return !(__x == __y); }
00701 
00702   /// Based on operator<
00703   template <typename _Key, typename _Tp, typename _Compare, typename _Alloc>
00704     inline bool
00705     operator>(const map<_Key, _Tp, _Compare, _Alloc>& __x,
00706               const map<_Key, _Tp, _Compare, _Alloc>& __y)
00707     { return __y < __x; }
00708 
00709   /// Based on operator<
00710   template <typename _Key, typename _Tp, typename _Compare, typename _Alloc>
00711     inline bool
00712     operator<=(const map<_Key, _Tp, _Compare, _Alloc>& __x,
00713                const map<_Key, _Tp, _Compare, _Alloc>& __y)
00714     { return !(__y < __x); }
00715 
00716   /// Based on operator<
00717   template <typename _Key, typename _Tp, typename _Compare, typename _Alloc>
00718     inline bool
00719     operator>=(const map<_Key, _Tp, _Compare, _Alloc>& __x,
00720                const map<_Key, _Tp, _Compare, _Alloc>& __y)
00721     { return !(__x < __y); }
00722 
00723   /// See std::map::swap().
00724   template <typename _Key, typename _Tp, typename _Compare, typename _Alloc>
00725     inline void
00726     swap(map<_Key, _Tp, _Compare, _Alloc>& __x,
00727      map<_Key, _Tp, _Compare, _Alloc>& __y)
00728     { __x.swap(__y); }
00729 } // namespace std
00730 
00731 #endif /* _MAP_H */

Generated on Tue Dec 2 03:59:28 2008 for libstdc++ by  doxygen 1.5.7.1