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