libstdc++
stl_map.h
Go to the documentation of this file.
00001 // Map implementation -*- C++ -*-
00002 
00003 // Copyright (C) 2001-2018 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 3, 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 // Under Section 7 of GPL version 3, you are granted additional
00017 // permissions described in the GCC Runtime Library Exception, version
00018 // 3.1, as published by the Free Software Foundation.
00019 
00020 // You should have received a copy of the GNU General Public License and
00021 // a copy of the GCC Runtime Library Exception along with this program;
00022 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
00023 // <http://www.gnu.org/licenses/>.
00024 
00025 /*
00026  *
00027  * Copyright (c) 1994
00028  * Hewlett-Packard Company
00029  *
00030  * Permission to use, copy, modify, distribute and sell this software
00031  * and its documentation for any purpose is hereby granted without fee,
00032  * provided that the above copyright notice appear in all copies and
00033  * that both that copyright notice and this permission notice appear
00034  * in supporting documentation.  Hewlett-Packard Company makes no
00035  * representations about the suitability of this software for any
00036  * purpose.  It is provided "as is" without express or implied warranty.
00037  *
00038  *
00039  * Copyright (c) 1996,1997
00040  * Silicon Graphics Computer Systems, Inc.
00041  *
00042  * Permission to use, copy, modify, distribute and sell this software
00043  * and its documentation for any purpose is hereby granted without fee,
00044  * provided that the above copyright notice appear in all copies and
00045  * that both that copyright notice and this permission notice appear
00046  * in supporting documentation.  Silicon Graphics makes no
00047  * representations about the suitability of this software for any
00048  * purpose.  It is provided "as is" without express or implied warranty.
00049  */
00050 
00051 /** @file bits/stl_map.h
00052  *  This is an internal header file, included by other library headers.
00053  *  Do not attempt to use it directly. @headername{map}
00054  */
00055 
00056 #ifndef _STL_MAP_H
00057 #define _STL_MAP_H 1
00058 
00059 #include <bits/functexcept.h>
00060 #include <bits/concept_check.h>
00061 #if __cplusplus >= 201103L
00062 #include <initializer_list>
00063 #include <tuple>
00064 #endif
00065 
00066 namespace std _GLIBCXX_VISIBILITY(default)
00067 {
00068 _GLIBCXX_BEGIN_NAMESPACE_VERSION
00069 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
00070 
00071   template <typename _Key, typename _Tp, typename _Compare, typename _Alloc>
00072     class multimap;
00073 
00074   /**
00075    *  @brief A standard container made up of (key,value) pairs, which can be
00076    *  retrieved based on a key, in logarithmic time.
00077    *
00078    *  @ingroup associative_containers
00079    *
00080    *  @tparam _Key  Type of key objects.
00081    *  @tparam  _Tp  Type of mapped objects.
00082    *  @tparam _Compare  Comparison function object type, defaults to less<_Key>.
00083    *  @tparam _Alloc  Allocator type, defaults to
00084    *                  allocator<pair<const _Key, _Tp>.
00085    *
00086    *  Meets the requirements of a <a href="tables.html#65">container</a>, a
00087    *  <a href="tables.html#66">reversible container</a>, and an
00088    *  <a href="tables.html#69">associative container</a> (using unique keys).
00089    *  For a @c map<Key,T> the key_type is Key, the mapped_type is T, and the
00090    *  value_type is std::pair<const Key,T>.
00091    *
00092    *  Maps support bidirectional iterators.
00093    *
00094    *  The private tree data is declared exactly the same way for map and
00095    *  multimap; the distinction is made entirely in how the tree functions are
00096    *  called (*_unique versus *_equal, same as the standard).
00097   */
00098   template <typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
00099             typename _Alloc = std::allocator<std::pair<const _Key, _Tp> > >
00100     class map
00101     {
00102     public:
00103       typedef _Key                                      key_type;
00104       typedef _Tp                                       mapped_type;
00105       typedef std::pair<const _Key, _Tp>                value_type;
00106       typedef _Compare                                  key_compare;
00107       typedef _Alloc                                    allocator_type;
00108 
00109     private:
00110 #ifdef _GLIBCXX_CONCEPT_CHECKS
00111       // concept requirements
00112       typedef typename _Alloc::value_type               _Alloc_value_type;
00113 # if __cplusplus < 201103L
00114       __glibcxx_class_requires(_Tp, _SGIAssignableConcept)
00115 # endif
00116       __glibcxx_class_requires4(_Compare, bool, _Key, _Key,
00117                                 _BinaryFunctionConcept)
00118       __glibcxx_class_requires2(value_type, _Alloc_value_type, _SameTypeConcept)
00119 #endif
00120 
00121 #if __cplusplus >= 201103L && defined(__STRICT_ANSI__)
00122       static_assert(is_same<typename _Alloc::value_type, value_type>::value,
00123           "std::map must have the same value_type as its allocator");
00124 #endif
00125 
00126     public:
00127       class value_compare
00128       : public std::binary_function<value_type, value_type, bool>
00129       {
00130         friend class map<_Key, _Tp, _Compare, _Alloc>;
00131       protected:
00132         _Compare comp;
00133 
00134         value_compare(_Compare __c)
00135         : comp(__c) { }
00136 
00137       public:
00138         bool operator()(const value_type& __x, const value_type& __y) const
00139         { return comp(__x.first, __y.first); }
00140       };
00141 
00142     private:
00143       /// This turns a red-black tree into a [multi]map.
00144       typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template
00145         rebind<value_type>::other _Pair_alloc_type;
00146 
00147       typedef _Rb_tree<key_type, value_type, _Select1st<value_type>,
00148                        key_compare, _Pair_alloc_type> _Rep_type;
00149 
00150       /// The actual tree structure.
00151       _Rep_type _M_t;
00152 
00153       typedef __gnu_cxx::__alloc_traits<_Pair_alloc_type> _Alloc_traits;
00154 
00155     public:
00156       // many of these are specified differently in ISO, but the following are
00157       // "functionally equivalent"
00158       typedef typename _Alloc_traits::pointer            pointer;
00159       typedef typename _Alloc_traits::const_pointer      const_pointer;
00160       typedef typename _Alloc_traits::reference          reference;
00161       typedef typename _Alloc_traits::const_reference    const_reference;
00162       typedef typename _Rep_type::iterator               iterator;
00163       typedef typename _Rep_type::const_iterator         const_iterator;
00164       typedef typename _Rep_type::size_type              size_type;
00165       typedef typename _Rep_type::difference_type        difference_type;
00166       typedef typename _Rep_type::reverse_iterator       reverse_iterator;
00167       typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
00168 
00169 #if __cplusplus > 201402L
00170       using node_type = typename _Rep_type::node_type;
00171       using insert_return_type = typename _Rep_type::insert_return_type;
00172 #endif
00173 
00174       // [23.3.1.1] construct/copy/destroy
00175       // (get_allocator() is also listed in this section)
00176 
00177       /**
00178        *  @brief  Default constructor creates no elements.
00179        */
00180 #if __cplusplus < 201103L
00181       map() : _M_t() { }
00182 #else
00183       map() = default;
00184 #endif
00185 
00186       /**
00187        *  @brief  Creates a %map with no elements.
00188        *  @param  __comp  A comparison object.
00189        *  @param  __a  An allocator object.
00190        */
00191       explicit
00192       map(const _Compare& __comp,
00193           const allocator_type& __a = allocator_type())
00194       : _M_t(__comp, _Pair_alloc_type(__a)) { }
00195 
00196       /**
00197        *  @brief  %Map copy constructor.
00198        *
00199        *  Whether the allocator is copied depends on the allocator traits.
00200        */
00201 #if __cplusplus < 201103L
00202       map(const map& __x)
00203       : _M_t(__x._M_t) { }
00204 #else
00205       map(const map&) = default;
00206 
00207       /**
00208        *  @brief  %Map move constructor.
00209        *
00210        *  The newly-created %map contains the exact contents of the moved
00211        *  instance. The moved instance is a valid, but unspecified, %map.
00212        */
00213       map(map&&) = default;
00214 
00215       /**
00216        *  @brief  Builds a %map from an initializer_list.
00217        *  @param  __l  An initializer_list.
00218        *  @param  __comp  A comparison object.
00219        *  @param  __a  An allocator object.
00220        *
00221        *  Create a %map consisting of copies of the elements in the
00222        *  initializer_list @a __l.
00223        *  This is linear in N if the range is already sorted, and NlogN
00224        *  otherwise (where N is @a __l.size()).
00225        */
00226       map(initializer_list<value_type> __l,
00227           const _Compare& __comp = _Compare(),
00228           const allocator_type& __a = allocator_type())
00229       : _M_t(__comp, _Pair_alloc_type(__a))
00230       { _M_t._M_insert_unique(__l.begin(), __l.end()); }
00231 
00232       /// Allocator-extended default constructor.
00233       explicit
00234       map(const allocator_type& __a)
00235       : _M_t(_Compare(), _Pair_alloc_type(__a)) { }
00236 
00237       /// Allocator-extended copy constructor.
00238       map(const map& __m, const allocator_type& __a)
00239       : _M_t(__m._M_t, _Pair_alloc_type(__a)) { }
00240 
00241       /// Allocator-extended move constructor.
00242       map(map&& __m, const allocator_type& __a)
00243       noexcept(is_nothrow_copy_constructible<_Compare>::value
00244                && _Alloc_traits::_S_always_equal())
00245       : _M_t(std::move(__m._M_t), _Pair_alloc_type(__a)) { }
00246 
00247       /// Allocator-extended initialier-list constructor.
00248       map(initializer_list<value_type> __l, const allocator_type& __a)
00249       : _M_t(_Compare(), _Pair_alloc_type(__a))
00250       { _M_t._M_insert_unique(__l.begin(), __l.end()); }
00251 
00252       /// Allocator-extended range constructor.
00253       template<typename _InputIterator>
00254         map(_InputIterator __first, _InputIterator __last,
00255             const allocator_type& __a)
00256         : _M_t(_Compare(), _Pair_alloc_type(__a))
00257         { _M_t._M_insert_unique(__first, __last); }
00258 #endif
00259 
00260       /**
00261        *  @brief  Builds a %map from a range.
00262        *  @param  __first  An input iterator.
00263        *  @param  __last  An input iterator.
00264        *
00265        *  Create a %map consisting of copies of the elements from
00266        *  [__first,__last).  This is linear in N if the range is
00267        *  already sorted, and NlogN otherwise (where N is
00268        *  distance(__first,__last)).
00269        */
00270       template<typename _InputIterator>
00271         map(_InputIterator __first, _InputIterator __last)
00272         : _M_t()
00273         { _M_t._M_insert_unique(__first, __last); }
00274 
00275       /**
00276        *  @brief  Builds a %map from a range.
00277        *  @param  __first  An input iterator.
00278        *  @param  __last  An input iterator.
00279        *  @param  __comp  A comparison functor.
00280        *  @param  __a  An allocator object.
00281        *
00282        *  Create a %map consisting of copies of the elements from
00283        *  [__first,__last).  This is linear in N if the range is
00284        *  already sorted, and NlogN otherwise (where N is
00285        *  distance(__first,__last)).
00286        */
00287       template<typename _InputIterator>
00288         map(_InputIterator __first, _InputIterator __last,
00289             const _Compare& __comp,
00290             const allocator_type& __a = allocator_type())
00291         : _M_t(__comp, _Pair_alloc_type(__a))
00292         { _M_t._M_insert_unique(__first, __last); }
00293 
00294 #if __cplusplus >= 201103L
00295       /**
00296        *  The dtor only erases the elements, and note that if the elements
00297        *  themselves are pointers, the pointed-to memory is not touched in any
00298        *  way.  Managing the pointer is the user's responsibility.
00299        */
00300       ~map() = default;
00301 #endif
00302 
00303       /**
00304        *  @brief  %Map assignment operator.
00305        *
00306        *  Whether the allocator is copied depends on the allocator traits.
00307        */
00308 #if __cplusplus < 201103L
00309       map&
00310       operator=(const map& __x)
00311       {
00312         _M_t = __x._M_t;
00313         return *this;
00314       }
00315 #else
00316       map&
00317       operator=(const map&) = default;
00318 
00319       /// Move assignment operator.
00320       map&
00321       operator=(map&&) = default;
00322 
00323       /**
00324        *  @brief  %Map list assignment operator.
00325        *  @param  __l  An initializer_list.
00326        *
00327        *  This function fills a %map with copies of the elements in the
00328        *  initializer list @a __l.
00329        *
00330        *  Note that the assignment completely changes the %map and
00331        *  that the resulting %map's size is the same as the number
00332        *  of elements assigned.
00333        */
00334       map&
00335       operator=(initializer_list<value_type> __l)
00336       {
00337         _M_t._M_assign_unique(__l.begin(), __l.end());
00338         return *this;
00339       }
00340 #endif
00341 
00342       /// Get a copy of the memory allocation object.
00343       allocator_type
00344       get_allocator() const _GLIBCXX_NOEXCEPT
00345       { return allocator_type(_M_t.get_allocator()); }
00346 
00347       // iterators
00348       /**
00349        *  Returns a read/write iterator that points to the first pair in the
00350        *  %map.
00351        *  Iteration is done in ascending order according to the keys.
00352        */
00353       iterator
00354       begin() _GLIBCXX_NOEXCEPT
00355       { return _M_t.begin(); }
00356 
00357       /**
00358        *  Returns a read-only (constant) iterator that points to the first pair
00359        *  in the %map.  Iteration is done in ascending order according to the
00360        *  keys.
00361        */
00362       const_iterator
00363       begin() const _GLIBCXX_NOEXCEPT
00364       { return _M_t.begin(); }
00365 
00366       /**
00367        *  Returns a read/write iterator that points one past the last
00368        *  pair in the %map.  Iteration is done in ascending order
00369        *  according to the keys.
00370        */
00371       iterator
00372       end() _GLIBCXX_NOEXCEPT
00373       { return _M_t.end(); }
00374 
00375       /**
00376        *  Returns a read-only (constant) iterator that points one past the last
00377        *  pair in the %map.  Iteration is done in ascending order according to
00378        *  the keys.
00379        */
00380       const_iterator
00381       end() const _GLIBCXX_NOEXCEPT
00382       { return _M_t.end(); }
00383 
00384       /**
00385        *  Returns a read/write reverse iterator that points to the last pair in
00386        *  the %map.  Iteration is done in descending order according to the
00387        *  keys.
00388        */
00389       reverse_iterator
00390       rbegin() _GLIBCXX_NOEXCEPT
00391       { return _M_t.rbegin(); }
00392 
00393       /**
00394        *  Returns a read-only (constant) reverse iterator that points to the
00395        *  last pair in the %map.  Iteration is done in descending order
00396        *  according to the keys.
00397        */
00398       const_reverse_iterator
00399       rbegin() const _GLIBCXX_NOEXCEPT
00400       { return _M_t.rbegin(); }
00401 
00402       /**
00403        *  Returns a read/write reverse iterator that points to one before the
00404        *  first pair in the %map.  Iteration is done in descending order
00405        *  according to the keys.
00406        */
00407       reverse_iterator
00408       rend() _GLIBCXX_NOEXCEPT
00409       { return _M_t.rend(); }
00410 
00411       /**
00412        *  Returns a read-only (constant) reverse iterator that points to one
00413        *  before the first pair in the %map.  Iteration is done in descending
00414        *  order according to the keys.
00415        */
00416       const_reverse_iterator
00417       rend() const _GLIBCXX_NOEXCEPT
00418       { return _M_t.rend(); }
00419 
00420 #if __cplusplus >= 201103L
00421       /**
00422        *  Returns a read-only (constant) iterator that points to the first pair
00423        *  in the %map.  Iteration is done in ascending order according to the
00424        *  keys.
00425        */
00426       const_iterator
00427       cbegin() const noexcept
00428       { return _M_t.begin(); }
00429 
00430       /**
00431        *  Returns a read-only (constant) iterator that points one past the last
00432        *  pair in the %map.  Iteration is done in ascending order according to
00433        *  the keys.
00434        */
00435       const_iterator
00436       cend() const noexcept
00437       { return _M_t.end(); }
00438 
00439       /**
00440        *  Returns a read-only (constant) reverse iterator that points to the
00441        *  last pair in the %map.  Iteration is done in descending order
00442        *  according to the keys.
00443        */
00444       const_reverse_iterator
00445       crbegin() const noexcept
00446       { return _M_t.rbegin(); }
00447 
00448       /**
00449        *  Returns a read-only (constant) reverse iterator that points to one
00450        *  before the first pair in the %map.  Iteration is done in descending
00451        *  order according to the keys.
00452        */
00453       const_reverse_iterator
00454       crend() const noexcept
00455       { return _M_t.rend(); }
00456 #endif
00457 
00458       // capacity
00459       /** Returns true if the %map is empty.  (Thus begin() would equal
00460        *  end().)
00461       */
00462       bool
00463       empty() const _GLIBCXX_NOEXCEPT
00464       { return _M_t.empty(); }
00465 
00466       /** Returns the size of the %map.  */
00467       size_type
00468       size() const _GLIBCXX_NOEXCEPT
00469       { return _M_t.size(); }
00470 
00471       /** Returns the maximum size of the %map.  */
00472       size_type
00473       max_size() const _GLIBCXX_NOEXCEPT
00474       { return _M_t.max_size(); }
00475 
00476       // [23.3.1.2] element access
00477       /**
00478        *  @brief  Subscript ( @c [] ) access to %map data.
00479        *  @param  __k  The key for which data should be retrieved.
00480        *  @return  A reference to the data of the (key,data) %pair.
00481        *
00482        *  Allows for easy lookup with the subscript ( @c [] )
00483        *  operator.  Returns data associated with the key specified in
00484        *  subscript.  If the key does not exist, a pair with that key
00485        *  is created using default values, which is then returned.
00486        *
00487        *  Lookup requires logarithmic time.
00488        */
00489       mapped_type&
00490       operator[](const key_type& __k)
00491       {
00492         // concept requirements
00493         __glibcxx_function_requires(_DefaultConstructibleConcept<mapped_type>)
00494 
00495         iterator __i = lower_bound(__k);
00496         // __i->first is greater than or equivalent to __k.
00497         if (__i == end() || key_comp()(__k, (*__i).first))
00498 #if __cplusplus >= 201103L
00499           __i = _M_t._M_emplace_hint_unique(__i, std::piecewise_construct,
00500                                             std::tuple<const key_type&>(__k),
00501                                             std::tuple<>());
00502 #else
00503           __i = insert(__i, value_type(__k, mapped_type()));
00504 #endif
00505         return (*__i).second;
00506       }
00507 
00508 #if __cplusplus >= 201103L
00509       mapped_type&
00510       operator[](key_type&& __k)
00511       {
00512         // concept requirements
00513         __glibcxx_function_requires(_DefaultConstructibleConcept<mapped_type>)
00514 
00515         iterator __i = lower_bound(__k);
00516         // __i->first is greater than or equivalent to __k.
00517         if (__i == end() || key_comp()(__k, (*__i).first))
00518           __i = _M_t._M_emplace_hint_unique(__i, std::piecewise_construct,
00519                                         std::forward_as_tuple(std::move(__k)),
00520                                         std::tuple<>());
00521         return (*__i).second;
00522       }
00523 #endif
00524 
00525       // _GLIBCXX_RESOLVE_LIB_DEFECTS
00526       // DR 464. Suggestion for new member functions in standard containers.
00527       /**
00528        *  @brief  Access to %map data.
00529        *  @param  __k  The key for which data should be retrieved.
00530        *  @return  A reference to the data whose key is equivalent to @a __k, if
00531        *           such a data is present in the %map.
00532        *  @throw  std::out_of_range  If no such data is present.
00533        */
00534       mapped_type&
00535       at(const key_type& __k)
00536       {
00537         iterator __i = lower_bound(__k);
00538         if (__i == end() || key_comp()(__k, (*__i).first))
00539           __throw_out_of_range(__N("map::at"));
00540         return (*__i).second;
00541       }
00542 
00543       const mapped_type&
00544       at(const key_type& __k) const
00545       {
00546         const_iterator __i = lower_bound(__k);
00547         if (__i == end() || key_comp()(__k, (*__i).first))
00548           __throw_out_of_range(__N("map::at"));
00549         return (*__i).second;
00550       }
00551 
00552       // modifiers
00553 #if __cplusplus >= 201103L
00554       /**
00555        *  @brief Attempts to build and insert a std::pair into the %map.
00556        *
00557        *  @param __args  Arguments used to generate a new pair instance (see
00558        *                std::piecewise_contruct for passing arguments to each
00559        *                part of the pair constructor).
00560        *
00561        *  @return  A pair, of which the first element is an iterator that points
00562        *           to the possibly inserted pair, and the second is a bool that
00563        *           is true if the pair was actually inserted.
00564        *
00565        *  This function attempts to build and insert a (key, value) %pair into
00566        *  the %map.
00567        *  A %map relies on unique keys and thus a %pair is only inserted if its
00568        *  first element (the key) is not already present in the %map.
00569        *
00570        *  Insertion requires logarithmic time.
00571        */
00572       template<typename... _Args>
00573         std::pair<iterator, bool>
00574         emplace(_Args&&... __args)
00575         { return _M_t._M_emplace_unique(std::forward<_Args>(__args)...); }
00576 
00577       /**
00578        *  @brief Attempts to build and insert a std::pair into the %map.
00579        *
00580        *  @param  __pos  An iterator that serves as a hint as to where the pair
00581        *                should be inserted.
00582        *  @param  __args  Arguments used to generate a new pair instance (see
00583        *                 std::piecewise_contruct for passing arguments to each
00584        *                 part of the pair constructor).
00585        *  @return An iterator that points to the element with key of the
00586        *          std::pair built from @a __args (may or may not be that
00587        *          std::pair).
00588        *
00589        *  This function is not concerned about whether the insertion took place,
00590        *  and thus does not return a boolean like the single-argument emplace()
00591        *  does.
00592        *  Note that the first parameter is only a hint and can potentially
00593        *  improve the performance of the insertion process. A bad hint would
00594        *  cause no gains in efficiency.
00595        *
00596        *  See
00597        *  https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints
00598        *  for more on @a hinting.
00599        *
00600        *  Insertion requires logarithmic time (if the hint is not taken).
00601        */
00602       template<typename... _Args>
00603         iterator
00604         emplace_hint(const_iterator __pos, _Args&&... __args)
00605         {
00606           return _M_t._M_emplace_hint_unique(__pos,
00607                                              std::forward<_Args>(__args)...);
00608         }
00609 #endif
00610 
00611 #if __cplusplus > 201402L
00612       /// Extract a node.
00613       node_type
00614       extract(const_iterator __pos)
00615       {
00616         __glibcxx_assert(__pos != end());
00617         return _M_t.extract(__pos);
00618       }
00619 
00620       /// Extract a node.
00621       node_type
00622       extract(const key_type& __x)
00623       { return _M_t.extract(__x); }
00624 
00625       /// Re-insert an extracted node.
00626       insert_return_type
00627       insert(node_type&& __nh)
00628       { return _M_t._M_reinsert_node_unique(std::move(__nh)); }
00629 
00630       /// Re-insert an extracted node.
00631       iterator
00632       insert(const_iterator __hint, node_type&& __nh)
00633       { return _M_t._M_reinsert_node_hint_unique(__hint, std::move(__nh)); }
00634 
00635       template<typename, typename>
00636         friend class std::_Rb_tree_merge_helper;
00637 
00638       template<typename _C2>
00639         void
00640         merge(map<_Key, _Tp, _C2, _Alloc>& __source)
00641         {
00642           using _Merge_helper = _Rb_tree_merge_helper<map, _C2>;
00643           _M_t._M_merge_unique(_Merge_helper::_S_get_tree(__source));
00644         }
00645 
00646       template<typename _C2>
00647         void
00648         merge(map<_Key, _Tp, _C2, _Alloc>&& __source)
00649         { merge(__source); }
00650 
00651       template<typename _C2>
00652         void
00653         merge(multimap<_Key, _Tp, _C2, _Alloc>& __source)
00654         {
00655           using _Merge_helper = _Rb_tree_merge_helper<map, _C2>;
00656           _M_t._M_merge_unique(_Merge_helper::_S_get_tree(__source));
00657         }
00658 
00659       template<typename _C2>
00660         void
00661         merge(multimap<_Key, _Tp, _C2, _Alloc>&& __source)
00662         { merge(__source); }
00663 #endif // C++17
00664 
00665 #if __cplusplus > 201402L
00666 #define __cpp_lib_map_try_emplace 201411
00667       /**
00668        *  @brief Attempts to build and insert a std::pair into the %map.
00669        *
00670        *  @param __k    Key to use for finding a possibly existing pair in
00671        *                the map.
00672        *  @param __args  Arguments used to generate the .second for a new pair
00673        *                instance.
00674        *
00675        *  @return  A pair, of which the first element is an iterator that points
00676        *           to the possibly inserted pair, and the second is a bool that
00677        *           is true if the pair was actually inserted.
00678        *
00679        *  This function attempts to build and insert a (key, value) %pair into
00680        *  the %map.
00681        *  A %map relies on unique keys and thus a %pair is only inserted if its
00682        *  first element (the key) is not already present in the %map.
00683        *  If a %pair is not inserted, this function has no effect.
00684        *
00685        *  Insertion requires logarithmic time.
00686        */
00687       template <typename... _Args>
00688         pair<iterator, bool>
00689         try_emplace(const key_type& __k, _Args&&... __args)
00690         {
00691           iterator __i = lower_bound(__k);
00692           if (__i == end() || key_comp()(__k, (*__i).first))
00693             {
00694               __i = emplace_hint(__i, std::piecewise_construct,
00695                                  std::forward_as_tuple(__k),
00696                                  std::forward_as_tuple(
00697                                    std::forward<_Args>(__args)...));
00698               return {__i, true};
00699             }
00700           return {__i, false};
00701         }
00702 
00703       // move-capable overload
00704       template <typename... _Args>
00705         pair<iterator, bool>
00706         try_emplace(key_type&& __k, _Args&&... __args)
00707         {
00708           iterator __i = lower_bound(__k);
00709           if (__i == end() || key_comp()(__k, (*__i).first))
00710             {
00711               __i = emplace_hint(__i, std::piecewise_construct,
00712                                  std::forward_as_tuple(std::move(__k)),
00713                                  std::forward_as_tuple(
00714                                    std::forward<_Args>(__args)...));
00715               return {__i, true};
00716             }
00717           return {__i, false};
00718         }
00719 
00720       /**
00721        *  @brief Attempts to build and insert a std::pair into the %map.
00722        *
00723        *  @param  __hint  An iterator that serves as a hint as to where the
00724        *                  pair should be inserted.
00725        *  @param __k    Key to use for finding a possibly existing pair in
00726        *                the map.
00727        *  @param __args  Arguments used to generate the .second for a new pair
00728        *                instance.
00729        *  @return An iterator that points to the element with key of the
00730        *          std::pair built from @a __args (may or may not be that
00731        *          std::pair).
00732        *
00733        *  This function is not concerned about whether the insertion took place,
00734        *  and thus does not return a boolean like the single-argument
00735        *  try_emplace() does. However, if insertion did not take place,
00736        *  this function has no effect.
00737        *  Note that the first parameter is only a hint and can potentially
00738        *  improve the performance of the insertion process. A bad hint would
00739        *  cause no gains in efficiency.
00740        *
00741        *  See
00742        *  https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints
00743        *  for more on @a hinting.
00744        *
00745        *  Insertion requires logarithmic time (if the hint is not taken).
00746        */
00747       template <typename... _Args>
00748         iterator
00749         try_emplace(const_iterator __hint, const key_type& __k,
00750                     _Args&&... __args)
00751         {
00752           iterator __i;
00753           auto __true_hint = _M_t._M_get_insert_hint_unique_pos(__hint, __k);
00754           if (__true_hint.second)
00755             __i = emplace_hint(iterator(__true_hint.second),
00756                                std::piecewise_construct,
00757                                std::forward_as_tuple(__k),
00758                                std::forward_as_tuple(
00759                                  std::forward<_Args>(__args)...));
00760           else
00761             __i = iterator(__true_hint.first);
00762           return __i;
00763         }
00764 
00765       // move-capable overload
00766       template <typename... _Args>
00767         iterator
00768         try_emplace(const_iterator __hint, key_type&& __k, _Args&&... __args)
00769         {
00770           iterator __i;
00771           auto __true_hint = _M_t._M_get_insert_hint_unique_pos(__hint, __k);
00772           if (__true_hint.second)
00773             __i = emplace_hint(iterator(__true_hint.second),
00774                                std::piecewise_construct,
00775                                std::forward_as_tuple(std::move(__k)),
00776                                std::forward_as_tuple(
00777                                  std::forward<_Args>(__args)...));
00778           else
00779             __i = iterator(__true_hint.first);
00780           return __i;
00781         }
00782 #endif
00783 
00784       /**
00785        *  @brief Attempts to insert a std::pair into the %map.
00786        *  @param __x Pair to be inserted (see std::make_pair for easy
00787        *             creation of pairs).
00788        *
00789        *  @return  A pair, of which the first element is an iterator that
00790        *           points to the possibly inserted pair, and the second is
00791        *           a bool that is true if the pair was actually inserted.
00792        *
00793        *  This function attempts to insert a (key, value) %pair into the %map.
00794        *  A %map relies on unique keys and thus a %pair is only inserted if its
00795        *  first element (the key) is not already present in the %map.
00796        *
00797        *  Insertion requires logarithmic time.
00798        *  @{
00799        */
00800       std::pair<iterator, bool>
00801       insert(const value_type& __x)
00802       { return _M_t._M_insert_unique(__x); }
00803 
00804 #if __cplusplus >= 201103L
00805       // _GLIBCXX_RESOLVE_LIB_DEFECTS
00806       // 2354. Unnecessary copying when inserting into maps with braced-init
00807       std::pair<iterator, bool>
00808       insert(value_type&& __x)
00809       { return _M_t._M_insert_unique(std::move(__x)); }
00810 
00811       template<typename _Pair, typename = typename
00812                std::enable_if<std::is_constructible<value_type,
00813                                                     _Pair&&>::value>::type>
00814         std::pair<iterator, bool>
00815         insert(_Pair&& __x)
00816         { return _M_t._M_insert_unique(std::forward<_Pair>(__x)); }
00817 #endif
00818       // @}
00819 
00820 #if __cplusplus >= 201103L
00821       /**
00822        *  @brief Attempts to insert a list of std::pairs into the %map.
00823        *  @param  __list  A std::initializer_list<value_type> of pairs to be
00824        *                  inserted.
00825        *
00826        *  Complexity similar to that of the range constructor.
00827        */
00828       void
00829       insert(std::initializer_list<value_type> __list)
00830       { insert(__list.begin(), __list.end()); }
00831 #endif
00832 
00833       /**
00834        *  @brief Attempts to insert a std::pair into the %map.
00835        *  @param  __position  An iterator that serves as a hint as to where the
00836        *                    pair should be inserted.
00837        *  @param  __x  Pair to be inserted (see std::make_pair for easy creation
00838        *               of pairs).
00839        *  @return An iterator that points to the element with key of
00840        *           @a __x (may or may not be the %pair passed in).
00841        *
00842 
00843        *  This function is not concerned about whether the insertion
00844        *  took place, and thus does not return a boolean like the
00845        *  single-argument insert() does.  Note that the first
00846        *  parameter is only a hint and can potentially improve the
00847        *  performance of the insertion process.  A bad hint would
00848        *  cause no gains in efficiency.
00849        *
00850        *  See
00851        *  https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints
00852        *  for more on @a hinting.
00853        *
00854        *  Insertion requires logarithmic time (if the hint is not taken).
00855        *  @{
00856        */
00857       iterator
00858 #if __cplusplus >= 201103L
00859       insert(const_iterator __position, const value_type& __x)
00860 #else
00861       insert(iterator __position, const value_type& __x)
00862 #endif
00863       { return _M_t._M_insert_unique_(__position, __x); }
00864 
00865 #if __cplusplus >= 201103L
00866       // _GLIBCXX_RESOLVE_LIB_DEFECTS
00867       // 2354. Unnecessary copying when inserting into maps with braced-init
00868       iterator
00869       insert(const_iterator __position, value_type&& __x)
00870       { return _M_t._M_insert_unique_(__position, std::move(__x)); }
00871 
00872       template<typename _Pair, typename = typename
00873                std::enable_if<std::is_constructible<value_type,
00874                                                     _Pair&&>::value>::type>
00875         iterator
00876         insert(const_iterator __position, _Pair&& __x)
00877         { return _M_t._M_insert_unique_(__position,
00878                                         std::forward<_Pair>(__x)); }
00879 #endif
00880       // @}
00881 
00882       /**
00883        *  @brief Template function that attempts to insert a range of elements.
00884        *  @param  __first  Iterator pointing to the start of the range to be
00885        *                   inserted.
00886        *  @param  __last  Iterator pointing to the end of the range.
00887        *
00888        *  Complexity similar to that of the range constructor.
00889        */
00890       template<typename _InputIterator>
00891         void
00892         insert(_InputIterator __first, _InputIterator __last)
00893         { _M_t._M_insert_unique(__first, __last); }
00894 
00895 #if __cplusplus > 201402L
00896 #define __cpp_lib_map_insertion 201411
00897       /**
00898        *  @brief Attempts to insert or assign a std::pair into the %map.
00899        *  @param __k    Key to use for finding a possibly existing pair in
00900        *                the map.
00901        *  @param __obj  Argument used to generate the .second for a pair
00902        *                instance.
00903        *
00904        *  @return  A pair, of which the first element is an iterator that
00905        *           points to the possibly inserted pair, and the second is
00906        *           a bool that is true if the pair was actually inserted.
00907        *
00908        *  This function attempts to insert a (key, value) %pair into the %map.
00909        *  A %map relies on unique keys and thus a %pair is only inserted if its
00910        *  first element (the key) is not already present in the %map.
00911        *  If the %pair was already in the %map, the .second of the %pair
00912        *  is assigned from __obj.
00913        *
00914        *  Insertion requires logarithmic time.
00915        */
00916       template <typename _Obj>
00917         pair<iterator, bool>
00918         insert_or_assign(const key_type& __k, _Obj&& __obj)
00919         {
00920           iterator __i = lower_bound(__k);
00921           if (__i == end() || key_comp()(__k, (*__i).first))
00922             {
00923               __i = emplace_hint(__i, std::piecewise_construct,
00924                                  std::forward_as_tuple(__k),
00925                                  std::forward_as_tuple(
00926                                    std::forward<_Obj>(__obj)));
00927               return {__i, true};
00928             }
00929           (*__i).second = std::forward<_Obj>(__obj);
00930           return {__i, false};
00931         }
00932 
00933       // move-capable overload
00934       template <typename _Obj>
00935         pair<iterator, bool>
00936         insert_or_assign(key_type&& __k, _Obj&& __obj)
00937         {
00938           iterator __i = lower_bound(__k);
00939           if (__i == end() || key_comp()(__k, (*__i).first))
00940             {
00941               __i = emplace_hint(__i, std::piecewise_construct,
00942                                  std::forward_as_tuple(std::move(__k)),
00943                                  std::forward_as_tuple(
00944                                    std::forward<_Obj>(__obj)));
00945               return {__i, true};
00946             }
00947           (*__i).second = std::forward<_Obj>(__obj);
00948           return {__i, false};
00949         }
00950 
00951       /**
00952        *  @brief Attempts to insert or assign a std::pair into the %map.
00953        *  @param  __hint  An iterator that serves as a hint as to where the
00954        *                  pair should be inserted.
00955        *  @param __k    Key to use for finding a possibly existing pair in
00956        *                the map.
00957        *  @param __obj  Argument used to generate the .second for a pair
00958        *                instance.
00959        *
00960        *  @return An iterator that points to the element with key of
00961        *           @a __x (may or may not be the %pair passed in).
00962        *
00963        *  This function attempts to insert a (key, value) %pair into the %map.
00964        *  A %map relies on unique keys and thus a %pair is only inserted if its
00965        *  first element (the key) is not already present in the %map.
00966        *  If the %pair was already in the %map, the .second of the %pair
00967        *  is assigned from __obj.
00968        *
00969        *  Insertion requires logarithmic time.
00970        */
00971       template <typename _Obj>
00972         iterator
00973         insert_or_assign(const_iterator __hint,
00974                          const key_type& __k, _Obj&& __obj)
00975         {
00976           iterator __i;
00977           auto __true_hint = _M_t._M_get_insert_hint_unique_pos(__hint, __k);
00978           if (__true_hint.second)
00979             {
00980               return emplace_hint(iterator(__true_hint.second),
00981                                   std::piecewise_construct,
00982                                   std::forward_as_tuple(__k),
00983                                   std::forward_as_tuple(
00984                                     std::forward<_Obj>(__obj)));
00985             }
00986           __i = iterator(__true_hint.first);
00987           (*__i).second = std::forward<_Obj>(__obj);
00988           return __i;
00989         }
00990 
00991       // move-capable overload
00992       template <typename _Obj>
00993         iterator
00994         insert_or_assign(const_iterator __hint, key_type&& __k, _Obj&& __obj)
00995         {
00996           iterator __i;
00997           auto __true_hint = _M_t._M_get_insert_hint_unique_pos(__hint, __k);
00998           if (__true_hint.second)
00999             {
01000               return emplace_hint(iterator(__true_hint.second),
01001                                   std::piecewise_construct,
01002                                   std::forward_as_tuple(std::move(__k)),
01003                                   std::forward_as_tuple(
01004                                     std::forward<_Obj>(__obj)));
01005             }
01006           __i = iterator(__true_hint.first);
01007           (*__i).second = std::forward<_Obj>(__obj);
01008           return __i;
01009         }
01010 #endif
01011 
01012 #if __cplusplus >= 201103L
01013       // _GLIBCXX_RESOLVE_LIB_DEFECTS
01014       // DR 130. Associative erase should return an iterator.
01015       /**
01016        *  @brief Erases an element from a %map.
01017        *  @param  __position  An iterator pointing to the element to be erased.
01018        *  @return An iterator pointing to the element immediately following
01019        *          @a position prior to the element being erased. If no such
01020        *          element exists, end() is returned.
01021        *
01022        *  This function erases an element, pointed to by the given
01023        *  iterator, from a %map.  Note that this function only erases
01024        *  the element, and that if the element is itself a pointer,
01025        *  the pointed-to memory is not touched in any way.  Managing
01026        *  the pointer is the user's responsibility.
01027        *
01028        *  @{
01029        */
01030       iterator
01031       erase(const_iterator __position)
01032       { return _M_t.erase(__position); }
01033 
01034       // LWG 2059
01035       _GLIBCXX_ABI_TAG_CXX11
01036       iterator
01037       erase(iterator __position)
01038       { return _M_t.erase(__position); }
01039       // @}
01040 #else
01041       /**
01042        *  @brief Erases an element from a %map.
01043        *  @param  __position  An iterator pointing to the element to be erased.
01044        *
01045        *  This function erases an element, pointed to by the given
01046        *  iterator, from a %map.  Note that this function only erases
01047        *  the element, and that if the element is itself a pointer,
01048        *  the pointed-to memory is not touched in any way.  Managing
01049        *  the pointer is the user's responsibility.
01050        */
01051       void
01052       erase(iterator __position)
01053       { _M_t.erase(__position); }
01054 #endif
01055 
01056       /**
01057        *  @brief Erases elements according to the provided key.
01058        *  @param  __x  Key of element to be erased.
01059        *  @return  The number of elements erased.
01060        *
01061        *  This function erases all the elements located by the given key from
01062        *  a %map.
01063        *  Note that this function only erases the element, and that if
01064        *  the element is itself a pointer, the pointed-to memory is not touched
01065        *  in any way.  Managing the pointer is the user's responsibility.
01066        */
01067       size_type
01068       erase(const key_type& __x)
01069       { return _M_t.erase(__x); }
01070 
01071 #if __cplusplus >= 201103L
01072       // _GLIBCXX_RESOLVE_LIB_DEFECTS
01073       // DR 130. Associative erase should return an iterator.
01074       /**
01075        *  @brief Erases a [first,last) range of elements from a %map.
01076        *  @param  __first  Iterator pointing to the start of the range to be
01077        *                   erased.
01078        *  @param __last Iterator pointing to the end of the range to
01079        *                be erased.
01080        *  @return The iterator @a __last.
01081        *
01082        *  This function erases a sequence of elements from a %map.
01083        *  Note that this function only erases the element, and that if
01084        *  the element is itself a pointer, the pointed-to memory is not touched
01085        *  in any way.  Managing the pointer is the user's responsibility.
01086        */
01087       iterator
01088       erase(const_iterator __first, const_iterator __last)
01089       { return _M_t.erase(__first, __last); }
01090 #else
01091       /**
01092        *  @brief Erases a [__first,__last) range of elements from a %map.
01093        *  @param  __first  Iterator pointing to the start of the range to be
01094        *                   erased.
01095        *  @param __last Iterator pointing to the end of the range to
01096        *                be erased.
01097        *
01098        *  This function erases a sequence of elements from a %map.
01099        *  Note that this function only erases the element, and that if
01100        *  the element is itself a pointer, the pointed-to memory is not touched
01101        *  in any way.  Managing the pointer is the user's responsibility.
01102        */
01103       void
01104       erase(iterator __first, iterator __last)
01105       { _M_t.erase(__first, __last); }
01106 #endif
01107 
01108       /**
01109        *  @brief  Swaps data with another %map.
01110        *  @param  __x  A %map of the same element and allocator types.
01111        *
01112        *  This exchanges the elements between two maps in constant
01113        *  time.  (It is only swapping a pointer, an integer, and an
01114        *  instance of the @c Compare type (which itself is often
01115        *  stateless and empty), so it should be quite fast.)  Note
01116        *  that the global std::swap() function is specialized such
01117        *  that std::swap(m1,m2) will feed to this function.
01118        *
01119        *  Whether the allocators are swapped depends on the allocator traits.
01120        */
01121       void
01122       swap(map& __x)
01123       _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value)
01124       { _M_t.swap(__x._M_t); }
01125 
01126       /**
01127        *  Erases all elements in a %map.  Note that this function only
01128        *  erases the elements, and that if the elements themselves are
01129        *  pointers, the pointed-to memory is not touched in any way.
01130        *  Managing the pointer is the user's responsibility.
01131        */
01132       void
01133       clear() _GLIBCXX_NOEXCEPT
01134       { _M_t.clear(); }
01135 
01136       // observers
01137       /**
01138        *  Returns the key comparison object out of which the %map was
01139        *  constructed.
01140        */
01141       key_compare
01142       key_comp() const
01143       { return _M_t.key_comp(); }
01144 
01145       /**
01146        *  Returns a value comparison object, built from the key comparison
01147        *  object out of which the %map was constructed.
01148        */
01149       value_compare
01150       value_comp() const
01151       { return value_compare(_M_t.key_comp()); }
01152 
01153       // [23.3.1.3] map operations
01154 
01155       //@{
01156       /**
01157        *  @brief Tries to locate an element in a %map.
01158        *  @param  __x  Key of (key, value) %pair to be located.
01159        *  @return  Iterator pointing to sought-after element, or end() if not
01160        *           found.
01161        *
01162        *  This function takes a key and tries to locate the element with which
01163        *  the key matches.  If successful the function returns an iterator
01164        *  pointing to the sought after %pair.  If unsuccessful it returns the
01165        *  past-the-end ( @c end() ) iterator.
01166        */
01167 
01168       iterator
01169       find(const key_type& __x)
01170       { return _M_t.find(__x); }
01171 
01172 #if __cplusplus > 201103L
01173       template<typename _Kt>
01174         auto
01175         find(const _Kt& __x) -> decltype(_M_t._M_find_tr(__x))
01176         { return _M_t._M_find_tr(__x); }
01177 #endif
01178       //@}
01179 
01180       //@{
01181       /**
01182        *  @brief Tries to locate an element in a %map.
01183        *  @param  __x  Key of (key, value) %pair to be located.
01184        *  @return  Read-only (constant) iterator pointing to sought-after
01185        *           element, or end() if not found.
01186        *
01187        *  This function takes a key and tries to locate the element with which
01188        *  the key matches.  If successful the function returns a constant
01189        *  iterator pointing to the sought after %pair. If unsuccessful it
01190        *  returns the past-the-end ( @c end() ) iterator.
01191        */
01192 
01193       const_iterator
01194       find(const key_type& __x) const
01195       { return _M_t.find(__x); }
01196 
01197 #if __cplusplus > 201103L
01198       template<typename _Kt>
01199         auto
01200         find(const _Kt& __x) const -> decltype(_M_t._M_find_tr(__x))
01201         { return _M_t._M_find_tr(__x); }
01202 #endif
01203       //@}
01204 
01205       //@{
01206       /**
01207        *  @brief  Finds the number of elements with given key.
01208        *  @param  __x  Key of (key, value) pairs to be located.
01209        *  @return  Number of elements with specified key.
01210        *
01211        *  This function only makes sense for multimaps; for map the result will
01212        *  either be 0 (not present) or 1 (present).
01213        */
01214       size_type
01215       count(const key_type& __x) const
01216       { return _M_t.find(__x) == _M_t.end() ? 0 : 1; }
01217 
01218 #if __cplusplus > 201103L
01219       template<typename _Kt>
01220         auto
01221         count(const _Kt& __x) const -> decltype(_M_t._M_count_tr(__x))
01222         { return _M_t._M_count_tr(__x); }
01223 #endif
01224       //@}
01225 
01226       //@{
01227       /**
01228        *  @brief Finds the beginning of a subsequence matching given key.
01229        *  @param  __x  Key of (key, value) pair to be located.
01230        *  @return  Iterator pointing to first element equal to or greater
01231        *           than key, or end().
01232        *
01233        *  This function returns the first element of a subsequence of elements
01234        *  that matches the given key.  If unsuccessful it returns an iterator
01235        *  pointing to the first element that has a greater value than given key
01236        *  or end() if no such element exists.
01237        */
01238       iterator
01239       lower_bound(const key_type& __x)
01240       { return _M_t.lower_bound(__x); }
01241 
01242 #if __cplusplus > 201103L
01243       template<typename _Kt>
01244         auto
01245         lower_bound(const _Kt& __x)
01246         -> decltype(iterator(_M_t._M_lower_bound_tr(__x)))
01247         { return iterator(_M_t._M_lower_bound_tr(__x)); }
01248 #endif
01249       //@}
01250 
01251       //@{
01252       /**
01253        *  @brief Finds the beginning of a subsequence matching given key.
01254        *  @param  __x  Key of (key, value) pair to be located.
01255        *  @return  Read-only (constant) iterator pointing to first element
01256        *           equal to or greater than key, or end().
01257        *
01258        *  This function returns the first element of a subsequence of elements
01259        *  that matches the given key.  If unsuccessful it returns an iterator
01260        *  pointing to the first element that has a greater value than given key
01261        *  or end() if no such element exists.
01262        */
01263       const_iterator
01264       lower_bound(const key_type& __x) const
01265       { return _M_t.lower_bound(__x); }
01266 
01267 #if __cplusplus > 201103L
01268       template<typename _Kt>
01269         auto
01270         lower_bound(const _Kt& __x) const
01271         -> decltype(const_iterator(_M_t._M_lower_bound_tr(__x)))
01272         { return const_iterator(_M_t._M_lower_bound_tr(__x)); }
01273 #endif
01274       //@}
01275 
01276       //@{
01277       /**
01278        *  @brief Finds the end of a subsequence matching given key.
01279        *  @param  __x  Key of (key, value) pair to be located.
01280        *  @return Iterator pointing to the first element
01281        *          greater than key, or end().
01282        */
01283       iterator
01284       upper_bound(const key_type& __x)
01285       { return _M_t.upper_bound(__x); }
01286 
01287 #if __cplusplus > 201103L
01288       template<typename _Kt>
01289         auto
01290         upper_bound(const _Kt& __x)
01291         -> decltype(iterator(_M_t._M_upper_bound_tr(__x)))
01292         { return iterator(_M_t._M_upper_bound_tr(__x)); }
01293 #endif
01294       //@}
01295 
01296       //@{
01297       /**
01298        *  @brief Finds the end of a subsequence matching given key.
01299        *  @param  __x  Key of (key, value) pair to be located.
01300        *  @return  Read-only (constant) iterator pointing to first iterator
01301        *           greater than key, or end().
01302        */
01303       const_iterator
01304       upper_bound(const key_type& __x) const
01305       { return _M_t.upper_bound(__x); }
01306 
01307 #if __cplusplus > 201103L
01308       template<typename _Kt>
01309         auto
01310         upper_bound(const _Kt& __x) const
01311         -> decltype(const_iterator(_M_t._M_upper_bound_tr(__x)))
01312         { return const_iterator(_M_t._M_upper_bound_tr(__x)); }
01313 #endif
01314       //@}
01315 
01316       //@{
01317       /**
01318        *  @brief Finds a subsequence matching given key.
01319        *  @param  __x  Key of (key, value) pairs to be located.
01320        *  @return  Pair of iterators that possibly points to the subsequence
01321        *           matching given key.
01322        *
01323        *  This function is equivalent to
01324        *  @code
01325        *    std::make_pair(c.lower_bound(val),
01326        *                   c.upper_bound(val))
01327        *  @endcode
01328        *  (but is faster than making the calls separately).
01329        *
01330        *  This function probably only makes sense for multimaps.
01331        */
01332       std::pair<iterator, iterator>
01333       equal_range(const key_type& __x)
01334       { return _M_t.equal_range(__x); }
01335 
01336 #if __cplusplus > 201103L
01337       template<typename _Kt>
01338         auto
01339         equal_range(const _Kt& __x)
01340         -> decltype(pair<iterator, iterator>(_M_t._M_equal_range_tr(__x)))
01341         { return pair<iterator, iterator>(_M_t._M_equal_range_tr(__x)); }
01342 #endif
01343       //@}
01344 
01345       //@{
01346       /**
01347        *  @brief Finds a subsequence matching given key.
01348        *  @param  __x  Key of (key, value) pairs to be located.
01349        *  @return  Pair of read-only (constant) iterators that possibly points
01350        *           to the subsequence matching given key.
01351        *
01352        *  This function is equivalent to
01353        *  @code
01354        *    std::make_pair(c.lower_bound(val),
01355        *                   c.upper_bound(val))
01356        *  @endcode
01357        *  (but is faster than making the calls separately).
01358        *
01359        *  This function probably only makes sense for multimaps.
01360        */
01361       std::pair<const_iterator, const_iterator>
01362       equal_range(const key_type& __x) const
01363       { return _M_t.equal_range(__x); }
01364 
01365 #if __cplusplus > 201103L
01366       template<typename _Kt>
01367         auto
01368         equal_range(const _Kt& __x) const
01369         -> decltype(pair<const_iterator, const_iterator>(
01370               _M_t._M_equal_range_tr(__x)))
01371         {
01372           return pair<const_iterator, const_iterator>(
01373               _M_t._M_equal_range_tr(__x));
01374         }
01375 #endif
01376       //@}
01377 
01378       template<typename _K1, typename _T1, typename _C1, typename _A1>
01379         friend bool
01380         operator==(const map<_K1, _T1, _C1, _A1>&,
01381                    const map<_K1, _T1, _C1, _A1>&);
01382 
01383       template<typename _K1, typename _T1, typename _C1, typename _A1>
01384         friend bool
01385         operator<(const map<_K1, _T1, _C1, _A1>&,
01386                   const map<_K1, _T1, _C1, _A1>&);
01387     };
01388 
01389 
01390 #if __cpp_deduction_guides >= 201606
01391 
01392   template<typename _InputIterator,
01393            typename _Compare = less<__iter_key_t<_InputIterator>>,
01394            typename _Allocator = allocator<__iter_to_alloc_t<_InputIterator>>,
01395            typename = _RequireInputIter<_InputIterator>,
01396            typename = _RequireAllocator<_Allocator>>
01397     map(_InputIterator, _InputIterator,
01398         _Compare = _Compare(), _Allocator = _Allocator())
01399     -> map<__iter_key_t<_InputIterator>, __iter_val_t<_InputIterator>,
01400            _Compare, _Allocator>;
01401 
01402   template<typename _Key, typename _Tp, typename _Compare = less<_Key>,
01403            typename _Allocator = allocator<pair<const _Key, _Tp>>,
01404            typename = _RequireAllocator<_Allocator>>
01405     map(initializer_list<pair<_Key, _Tp>>,
01406         _Compare = _Compare(), _Allocator = _Allocator())
01407     -> map<_Key, _Tp, _Compare, _Allocator>;
01408 
01409   template <typename _InputIterator, typename _Allocator,
01410             typename = _RequireInputIter<_InputIterator>,
01411             typename = _RequireAllocator<_Allocator>>
01412     map(_InputIterator, _InputIterator, _Allocator)
01413     -> map<__iter_key_t<_InputIterator>, __iter_val_t<_InputIterator>,
01414            less<__iter_key_t<_InputIterator>>, _Allocator>;
01415 
01416   template<typename _Key, typename _Tp, typename _Allocator,
01417            typename = _RequireAllocator<_Allocator>>
01418     map(initializer_list<pair<_Key, _Tp>>, _Allocator)
01419     -> map<_Key, _Tp, less<_Key>, _Allocator>;
01420 
01421 #endif
01422 
01423   /**
01424    *  @brief  Map equality comparison.
01425    *  @param  __x  A %map.
01426    *  @param  __y  A %map of the same type as @a x.
01427    *  @return  True iff the size and elements of the maps are equal.
01428    *
01429    *  This is an equivalence relation.  It is linear in the size of the
01430    *  maps.  Maps are considered equivalent if their sizes are equal,
01431    *  and if corresponding elements compare equal.
01432   */
01433   template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
01434     inline bool
01435     operator==(const map<_Key, _Tp, _Compare, _Alloc>& __x,
01436                const map<_Key, _Tp, _Compare, _Alloc>& __y)
01437     { return __x._M_t == __y._M_t; }
01438 
01439   /**
01440    *  @brief  Map ordering relation.
01441    *  @param  __x  A %map.
01442    *  @param  __y  A %map of the same type as @a x.
01443    *  @return  True iff @a x is lexicographically less than @a y.
01444    *
01445    *  This is a total ordering relation.  It is linear in the size of the
01446    *  maps.  The elements must be comparable with @c <.
01447    *
01448    *  See std::lexicographical_compare() for how the determination is made.
01449   */
01450   template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
01451     inline bool
01452     operator<(const map<_Key, _Tp, _Compare, _Alloc>& __x,
01453               const map<_Key, _Tp, _Compare, _Alloc>& __y)
01454     { return __x._M_t < __y._M_t; }
01455 
01456   /// Based on operator==
01457   template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
01458     inline bool
01459     operator!=(const map<_Key, _Tp, _Compare, _Alloc>& __x,
01460                const map<_Key, _Tp, _Compare, _Alloc>& __y)
01461     { return !(__x == __y); }
01462 
01463   /// Based on operator<
01464   template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
01465     inline bool
01466     operator>(const map<_Key, _Tp, _Compare, _Alloc>& __x,
01467               const map<_Key, _Tp, _Compare, _Alloc>& __y)
01468     { return __y < __x; }
01469 
01470   /// Based on operator<
01471   template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
01472     inline bool
01473     operator<=(const map<_Key, _Tp, _Compare, _Alloc>& __x,
01474                const map<_Key, _Tp, _Compare, _Alloc>& __y)
01475     { return !(__y < __x); }
01476 
01477   /// Based on operator<
01478   template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
01479     inline bool
01480     operator>=(const map<_Key, _Tp, _Compare, _Alloc>& __x,
01481                const map<_Key, _Tp, _Compare, _Alloc>& __y)
01482     { return !(__x < __y); }
01483 
01484   /// See std::map::swap().
01485   template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
01486     inline void
01487     swap(map<_Key, _Tp, _Compare, _Alloc>& __x,
01488          map<_Key, _Tp, _Compare, _Alloc>& __y)
01489     _GLIBCXX_NOEXCEPT_IF(noexcept(__x.swap(__y)))
01490     { __x.swap(__y); }
01491 
01492 _GLIBCXX_END_NAMESPACE_CONTAINER
01493 
01494 #if __cplusplus > 201402L
01495   // Allow std::map access to internals of compatible maps.
01496   template<typename _Key, typename _Val, typename _Cmp1, typename _Alloc,
01497            typename _Cmp2>
01498     struct
01499     _Rb_tree_merge_helper<_GLIBCXX_STD_C::map<_Key, _Val, _Cmp1, _Alloc>,
01500                           _Cmp2>
01501     {
01502     private:
01503       friend class _GLIBCXX_STD_C::map<_Key, _Val, _Cmp1, _Alloc>;
01504 
01505       static auto&
01506       _S_get_tree(_GLIBCXX_STD_C::map<_Key, _Val, _Cmp2, _Alloc>& __map)
01507       { return __map._M_t; }
01508 
01509       static auto&
01510       _S_get_tree(_GLIBCXX_STD_C::multimap<_Key, _Val, _Cmp2, _Alloc>& __map)
01511       { return __map._M_t; }
01512     };
01513 #endif // C++17
01514 
01515 _GLIBCXX_END_NAMESPACE_VERSION
01516 } // namespace std
01517 
01518 #endif /* _STL_MAP_H */