stl_map.h

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

Generated on Thu Nov 1 13:12:33 2007 for libstdc++ by  doxygen 1.5.1