1*38fd1498Szrj // Map implementation -*- C++ -*- 2*38fd1498Szrj 3*38fd1498Szrj // Copyright (C) 2001-2018 Free Software Foundation, Inc. 4*38fd1498Szrj // 5*38fd1498Szrj // This file is part of the GNU ISO C++ Library. This library is free 6*38fd1498Szrj // software; you can redistribute it and/or modify it under the 7*38fd1498Szrj // terms of the GNU General Public License as published by the 8*38fd1498Szrj // Free Software Foundation; either version 3, or (at your option) 9*38fd1498Szrj // any later version. 10*38fd1498Szrj 11*38fd1498Szrj // This library is distributed in the hope that it will be useful, 12*38fd1498Szrj // but WITHOUT ANY WARRANTY; without even the implied warranty of 13*38fd1498Szrj // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14*38fd1498Szrj // GNU General Public License for more details. 15*38fd1498Szrj 16*38fd1498Szrj // Under Section 7 of GPL version 3, you are granted additional 17*38fd1498Szrj // permissions described in the GCC Runtime Library Exception, version 18*38fd1498Szrj // 3.1, as published by the Free Software Foundation. 19*38fd1498Szrj 20*38fd1498Szrj // You should have received a copy of the GNU General Public License and 21*38fd1498Szrj // a copy of the GCC Runtime Library Exception along with this program; 22*38fd1498Szrj // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 23*38fd1498Szrj // <http://www.gnu.org/licenses/>. 24*38fd1498Szrj 25*38fd1498Szrj /* 26*38fd1498Szrj * 27*38fd1498Szrj * Copyright (c) 1994 28*38fd1498Szrj * Hewlett-Packard Company 29*38fd1498Szrj * 30*38fd1498Szrj * Permission to use, copy, modify, distribute and sell this software 31*38fd1498Szrj * and its documentation for any purpose is hereby granted without fee, 32*38fd1498Szrj * provided that the above copyright notice appear in all copies and 33*38fd1498Szrj * that both that copyright notice and this permission notice appear 34*38fd1498Szrj * in supporting documentation. Hewlett-Packard Company makes no 35*38fd1498Szrj * representations about the suitability of this software for any 36*38fd1498Szrj * purpose. It is provided "as is" without express or implied warranty. 37*38fd1498Szrj * 38*38fd1498Szrj * 39*38fd1498Szrj * Copyright (c) 1996,1997 40*38fd1498Szrj * Silicon Graphics Computer Systems, Inc. 41*38fd1498Szrj * 42*38fd1498Szrj * Permission to use, copy, modify, distribute and sell this software 43*38fd1498Szrj * and its documentation for any purpose is hereby granted without fee, 44*38fd1498Szrj * provided that the above copyright notice appear in all copies and 45*38fd1498Szrj * that both that copyright notice and this permission notice appear 46*38fd1498Szrj * in supporting documentation. Silicon Graphics makes no 47*38fd1498Szrj * representations about the suitability of this software for any 48*38fd1498Szrj * purpose. It is provided "as is" without express or implied warranty. 49*38fd1498Szrj */ 50*38fd1498Szrj 51*38fd1498Szrj /** @file bits/stl_map.h 52*38fd1498Szrj * This is an internal header file, included by other library headers. 53*38fd1498Szrj * Do not attempt to use it directly. @headername{map} 54*38fd1498Szrj */ 55*38fd1498Szrj 56*38fd1498Szrj #ifndef _STL_MAP_H 57*38fd1498Szrj #define _STL_MAP_H 1 58*38fd1498Szrj 59*38fd1498Szrj #include <bits/functexcept.h> 60*38fd1498Szrj #include <bits/concept_check.h> 61*38fd1498Szrj #if __cplusplus >= 201103L 62*38fd1498Szrj #include <initializer_list> 63*38fd1498Szrj #include <tuple> 64*38fd1498Szrj #endif 65*38fd1498Szrj 66*38fd1498Szrj namespace std _GLIBCXX_VISIBILITY(default) 67*38fd1498Szrj { 68*38fd1498Szrj _GLIBCXX_BEGIN_NAMESPACE_VERSION 69*38fd1498Szrj _GLIBCXX_BEGIN_NAMESPACE_CONTAINER 70*38fd1498Szrj 71*38fd1498Szrj template <typename _Key, typename _Tp, typename _Compare, typename _Alloc> 72*38fd1498Szrj class multimap; 73*38fd1498Szrj 74*38fd1498Szrj /** 75*38fd1498Szrj * @brief A standard container made up of (key,value) pairs, which can be 76*38fd1498Szrj * retrieved based on a key, in logarithmic time. 77*38fd1498Szrj * 78*38fd1498Szrj * @ingroup associative_containers 79*38fd1498Szrj * 80*38fd1498Szrj * @tparam _Key Type of key objects. 81*38fd1498Szrj * @tparam _Tp Type of mapped objects. 82*38fd1498Szrj * @tparam _Compare Comparison function object type, defaults to less<_Key>. 83*38fd1498Szrj * @tparam _Alloc Allocator type, defaults to 84*38fd1498Szrj * allocator<pair<const _Key, _Tp>. 85*38fd1498Szrj * 86*38fd1498Szrj * Meets the requirements of a <a href="tables.html#65">container</a>, a 87*38fd1498Szrj * <a href="tables.html#66">reversible container</a>, and an 88*38fd1498Szrj * <a href="tables.html#69">associative container</a> (using unique keys). 89*38fd1498Szrj * For a @c map<Key,T> the key_type is Key, the mapped_type is T, and the 90*38fd1498Szrj * value_type is std::pair<const Key,T>. 91*38fd1498Szrj * 92*38fd1498Szrj * Maps support bidirectional iterators. 93*38fd1498Szrj * 94*38fd1498Szrj * The private tree data is declared exactly the same way for map and 95*38fd1498Szrj * multimap; the distinction is made entirely in how the tree functions are 96*38fd1498Szrj * called (*_unique versus *_equal, same as the standard). 97*38fd1498Szrj */ 98*38fd1498Szrj template <typename _Key, typename _Tp, typename _Compare = std::less<_Key>, 99*38fd1498Szrj typename _Alloc = std::allocator<std::pair<const _Key, _Tp> > > 100*38fd1498Szrj class map 101*38fd1498Szrj { 102*38fd1498Szrj public: 103*38fd1498Szrj typedef _Key key_type; 104*38fd1498Szrj typedef _Tp mapped_type; 105*38fd1498Szrj typedef std::pair<const _Key, _Tp> value_type; 106*38fd1498Szrj typedef _Compare key_compare; 107*38fd1498Szrj typedef _Alloc allocator_type; 108*38fd1498Szrj 109*38fd1498Szrj private: 110*38fd1498Szrj #ifdef _GLIBCXX_CONCEPT_CHECKS 111*38fd1498Szrj // concept requirements 112*38fd1498Szrj typedef typename _Alloc::value_type _Alloc_value_type; 113*38fd1498Szrj # if __cplusplus < 201103L 114*38fd1498Szrj __glibcxx_class_requires(_Tp, _SGIAssignableConcept) 115*38fd1498Szrj # endif 116*38fd1498Szrj __glibcxx_class_requires4(_Compare, bool, _Key, _Key, 117*38fd1498Szrj _BinaryFunctionConcept) 118*38fd1498Szrj __glibcxx_class_requires2(value_type, _Alloc_value_type, _SameTypeConcept) 119*38fd1498Szrj #endif 120*38fd1498Szrj 121*38fd1498Szrj #if __cplusplus >= 201103L && defined(__STRICT_ANSI__) 122*38fd1498Szrj static_assert(is_same<typename _Alloc::value_type, value_type>::value, 123*38fd1498Szrj "std::map must have the same value_type as its allocator"); 124*38fd1498Szrj #endif 125*38fd1498Szrj 126*38fd1498Szrj public: 127*38fd1498Szrj class value_compare 128*38fd1498Szrj : public std::binary_function<value_type, value_type, bool> 129*38fd1498Szrj { 130*38fd1498Szrj friend class map<_Key, _Tp, _Compare, _Alloc>; 131*38fd1498Szrj protected: 132*38fd1498Szrj _Compare comp; 133*38fd1498Szrj 134*38fd1498Szrj value_compare(_Compare __c) 135*38fd1498Szrj : comp(__c) { } 136*38fd1498Szrj 137*38fd1498Szrj public: 138*38fd1498Szrj bool operator()(const value_type& __x, const value_type& __y) const 139*38fd1498Szrj { return comp(__x.first, __y.first); } 140*38fd1498Szrj }; 141*38fd1498Szrj 142*38fd1498Szrj private: 143*38fd1498Szrj /// This turns a red-black tree into a [multi]map. 144*38fd1498Szrj typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template 145*38fd1498Szrj rebind<value_type>::other _Pair_alloc_type; 146*38fd1498Szrj 147*38fd1498Szrj typedef _Rb_tree<key_type, value_type, _Select1st<value_type>, 148*38fd1498Szrj key_compare, _Pair_alloc_type> _Rep_type; 149*38fd1498Szrj 150*38fd1498Szrj /// The actual tree structure. 151*38fd1498Szrj _Rep_type _M_t; 152*38fd1498Szrj 153*38fd1498Szrj typedef __gnu_cxx::__alloc_traits<_Pair_alloc_type> _Alloc_traits; 154*38fd1498Szrj 155*38fd1498Szrj public: 156*38fd1498Szrj // many of these are specified differently in ISO, but the following are 157*38fd1498Szrj // "functionally equivalent" 158*38fd1498Szrj typedef typename _Alloc_traits::pointer pointer; 159*38fd1498Szrj typedef typename _Alloc_traits::const_pointer const_pointer; 160*38fd1498Szrj typedef typename _Alloc_traits::reference reference; 161*38fd1498Szrj typedef typename _Alloc_traits::const_reference const_reference; 162*38fd1498Szrj typedef typename _Rep_type::iterator iterator; 163*38fd1498Szrj typedef typename _Rep_type::const_iterator const_iterator; 164*38fd1498Szrj typedef typename _Rep_type::size_type size_type; 165*38fd1498Szrj typedef typename _Rep_type::difference_type difference_type; 166*38fd1498Szrj typedef typename _Rep_type::reverse_iterator reverse_iterator; 167*38fd1498Szrj typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator; 168*38fd1498Szrj 169*38fd1498Szrj #if __cplusplus > 201402L 170*38fd1498Szrj using node_type = typename _Rep_type::node_type; 171*38fd1498Szrj using insert_return_type = typename _Rep_type::insert_return_type; 172*38fd1498Szrj #endif 173*38fd1498Szrj 174*38fd1498Szrj // [23.3.1.1] construct/copy/destroy 175*38fd1498Szrj // (get_allocator() is also listed in this section) 176*38fd1498Szrj 177*38fd1498Szrj /** 178*38fd1498Szrj * @brief Default constructor creates no elements. 179*38fd1498Szrj */ 180*38fd1498Szrj #if __cplusplus < 201103L 181*38fd1498Szrj map() : _M_t() { } 182*38fd1498Szrj #else 183*38fd1498Szrj map() = default; 184*38fd1498Szrj #endif 185*38fd1498Szrj 186*38fd1498Szrj /** 187*38fd1498Szrj * @brief Creates a %map with no elements. 188*38fd1498Szrj * @param __comp A comparison object. 189*38fd1498Szrj * @param __a An allocator object. 190*38fd1498Szrj */ 191*38fd1498Szrj explicit 192*38fd1498Szrj map(const _Compare& __comp, 193*38fd1498Szrj const allocator_type& __a = allocator_type()) 194*38fd1498Szrj : _M_t(__comp, _Pair_alloc_type(__a)) { } 195*38fd1498Szrj 196*38fd1498Szrj /** 197*38fd1498Szrj * @brief %Map copy constructor. 198*38fd1498Szrj * 199*38fd1498Szrj * Whether the allocator is copied depends on the allocator traits. 200*38fd1498Szrj */ 201*38fd1498Szrj #if __cplusplus < 201103L 202*38fd1498Szrj map(const map& __x) 203*38fd1498Szrj : _M_t(__x._M_t) { } 204*38fd1498Szrj #else 205*38fd1498Szrj map(const map&) = default; 206*38fd1498Szrj 207*38fd1498Szrj /** 208*38fd1498Szrj * @brief %Map move constructor. 209*38fd1498Szrj * 210*38fd1498Szrj * The newly-created %map contains the exact contents of the moved 211*38fd1498Szrj * instance. The moved instance is a valid, but unspecified, %map. 212*38fd1498Szrj */ 213*38fd1498Szrj map(map&&) = default; 214*38fd1498Szrj 215*38fd1498Szrj /** 216*38fd1498Szrj * @brief Builds a %map from an initializer_list. 217*38fd1498Szrj * @param __l An initializer_list. 218*38fd1498Szrj * @param __comp A comparison object. 219*38fd1498Szrj * @param __a An allocator object. 220*38fd1498Szrj * 221*38fd1498Szrj * Create a %map consisting of copies of the elements in the 222*38fd1498Szrj * initializer_list @a __l. 223*38fd1498Szrj * This is linear in N if the range is already sorted, and NlogN 224*38fd1498Szrj * otherwise (where N is @a __l.size()). 225*38fd1498Szrj */ 226*38fd1498Szrj map(initializer_list<value_type> __l, 227*38fd1498Szrj const _Compare& __comp = _Compare(), 228*38fd1498Szrj const allocator_type& __a = allocator_type()) 229*38fd1498Szrj : _M_t(__comp, _Pair_alloc_type(__a)) 230*38fd1498Szrj { _M_t._M_insert_unique(__l.begin(), __l.end()); } 231*38fd1498Szrj 232*38fd1498Szrj /// Allocator-extended default constructor. 233*38fd1498Szrj explicit 234*38fd1498Szrj map(const allocator_type& __a) 235*38fd1498Szrj : _M_t(_Compare(), _Pair_alloc_type(__a)) { } 236*38fd1498Szrj 237*38fd1498Szrj /// Allocator-extended copy constructor. 238*38fd1498Szrj map(const map& __m, const allocator_type& __a) 239*38fd1498Szrj : _M_t(__m._M_t, _Pair_alloc_type(__a)) { } 240*38fd1498Szrj 241*38fd1498Szrj /// Allocator-extended move constructor. 242*38fd1498Szrj map(map&& __m, const allocator_type& __a) 243*38fd1498Szrj noexcept(is_nothrow_copy_constructible<_Compare>::value 244*38fd1498Szrj && _Alloc_traits::_S_always_equal()) 245*38fd1498Szrj : _M_t(std::move(__m._M_t), _Pair_alloc_type(__a)) { } 246*38fd1498Szrj 247*38fd1498Szrj /// Allocator-extended initialier-list constructor. 248*38fd1498Szrj map(initializer_list<value_type> __l, const allocator_type& __a) 249*38fd1498Szrj : _M_t(_Compare(), _Pair_alloc_type(__a)) 250*38fd1498Szrj { _M_t._M_insert_unique(__l.begin(), __l.end()); } 251*38fd1498Szrj 252*38fd1498Szrj /// Allocator-extended range constructor. 253*38fd1498Szrj template<typename _InputIterator> 254*38fd1498Szrj map(_InputIterator __first, _InputIterator __last, 255*38fd1498Szrj const allocator_type& __a) 256*38fd1498Szrj : _M_t(_Compare(), _Pair_alloc_type(__a)) 257*38fd1498Szrj { _M_t._M_insert_unique(__first, __last); } 258*38fd1498Szrj #endif 259*38fd1498Szrj 260*38fd1498Szrj /** 261*38fd1498Szrj * @brief Builds a %map from a range. 262*38fd1498Szrj * @param __first An input iterator. 263*38fd1498Szrj * @param __last An input iterator. 264*38fd1498Szrj * 265*38fd1498Szrj * Create a %map consisting of copies of the elements from 266*38fd1498Szrj * [__first,__last). This is linear in N if the range is 267*38fd1498Szrj * already sorted, and NlogN otherwise (where N is 268*38fd1498Szrj * distance(__first,__last)). 269*38fd1498Szrj */ 270*38fd1498Szrj template<typename _InputIterator> 271*38fd1498Szrj map(_InputIterator __first, _InputIterator __last) 272*38fd1498Szrj : _M_t() 273*38fd1498Szrj { _M_t._M_insert_unique(__first, __last); } 274*38fd1498Szrj 275*38fd1498Szrj /** 276*38fd1498Szrj * @brief Builds a %map from a range. 277*38fd1498Szrj * @param __first An input iterator. 278*38fd1498Szrj * @param __last An input iterator. 279*38fd1498Szrj * @param __comp A comparison functor. 280*38fd1498Szrj * @param __a An allocator object. 281*38fd1498Szrj * 282*38fd1498Szrj * Create a %map consisting of copies of the elements from 283*38fd1498Szrj * [__first,__last). This is linear in N if the range is 284*38fd1498Szrj * already sorted, and NlogN otherwise (where N is 285*38fd1498Szrj * distance(__first,__last)). 286*38fd1498Szrj */ 287*38fd1498Szrj template<typename _InputIterator> 288*38fd1498Szrj map(_InputIterator __first, _InputIterator __last, 289*38fd1498Szrj const _Compare& __comp, 290*38fd1498Szrj const allocator_type& __a = allocator_type()) 291*38fd1498Szrj : _M_t(__comp, _Pair_alloc_type(__a)) 292*38fd1498Szrj { _M_t._M_insert_unique(__first, __last); } 293*38fd1498Szrj 294*38fd1498Szrj #if __cplusplus >= 201103L 295*38fd1498Szrj /** 296*38fd1498Szrj * The dtor only erases the elements, and note that if the elements 297*38fd1498Szrj * themselves are pointers, the pointed-to memory is not touched in any 298*38fd1498Szrj * way. Managing the pointer is the user's responsibility. 299*38fd1498Szrj */ 300*38fd1498Szrj ~map() = default; 301*38fd1498Szrj #endif 302*38fd1498Szrj 303*38fd1498Szrj /** 304*38fd1498Szrj * @brief %Map assignment operator. 305*38fd1498Szrj * 306*38fd1498Szrj * Whether the allocator is copied depends on the allocator traits. 307*38fd1498Szrj */ 308*38fd1498Szrj #if __cplusplus < 201103L 309*38fd1498Szrj map& 310*38fd1498Szrj operator=(const map& __x) 311*38fd1498Szrj { 312*38fd1498Szrj _M_t = __x._M_t; 313*38fd1498Szrj return *this; 314*38fd1498Szrj } 315*38fd1498Szrj #else 316*38fd1498Szrj map& 317*38fd1498Szrj operator=(const map&) = default; 318*38fd1498Szrj 319*38fd1498Szrj /// Move assignment operator. 320*38fd1498Szrj map& 321*38fd1498Szrj operator=(map&&) = default; 322*38fd1498Szrj 323*38fd1498Szrj /** 324*38fd1498Szrj * @brief %Map list assignment operator. 325*38fd1498Szrj * @param __l An initializer_list. 326*38fd1498Szrj * 327*38fd1498Szrj * This function fills a %map with copies of the elements in the 328*38fd1498Szrj * initializer list @a __l. 329*38fd1498Szrj * 330*38fd1498Szrj * Note that the assignment completely changes the %map and 331*38fd1498Szrj * that the resulting %map's size is the same as the number 332*38fd1498Szrj * of elements assigned. 333*38fd1498Szrj */ 334*38fd1498Szrj map& 335*38fd1498Szrj operator=(initializer_list<value_type> __l) 336*38fd1498Szrj { 337*38fd1498Szrj _M_t._M_assign_unique(__l.begin(), __l.end()); 338*38fd1498Szrj return *this; 339*38fd1498Szrj } 340*38fd1498Szrj #endif 341*38fd1498Szrj 342*38fd1498Szrj /// Get a copy of the memory allocation object. 343*38fd1498Szrj allocator_type 344*38fd1498Szrj get_allocator() const _GLIBCXX_NOEXCEPT 345*38fd1498Szrj { return allocator_type(_M_t.get_allocator()); } 346*38fd1498Szrj 347*38fd1498Szrj // iterators 348*38fd1498Szrj /** 349*38fd1498Szrj * Returns a read/write iterator that points to the first pair in the 350*38fd1498Szrj * %map. 351*38fd1498Szrj * Iteration is done in ascending order according to the keys. 352*38fd1498Szrj */ 353*38fd1498Szrj iterator 354*38fd1498Szrj begin() _GLIBCXX_NOEXCEPT 355*38fd1498Szrj { return _M_t.begin(); } 356*38fd1498Szrj 357*38fd1498Szrj /** 358*38fd1498Szrj * Returns a read-only (constant) iterator that points to the first pair 359*38fd1498Szrj * in the %map. Iteration is done in ascending order according to the 360*38fd1498Szrj * keys. 361*38fd1498Szrj */ 362*38fd1498Szrj const_iterator 363*38fd1498Szrj begin() const _GLIBCXX_NOEXCEPT 364*38fd1498Szrj { return _M_t.begin(); } 365*38fd1498Szrj 366*38fd1498Szrj /** 367*38fd1498Szrj * Returns a read/write iterator that points one past the last 368*38fd1498Szrj * pair in the %map. Iteration is done in ascending order 369*38fd1498Szrj * according to the keys. 370*38fd1498Szrj */ 371*38fd1498Szrj iterator 372*38fd1498Szrj end() _GLIBCXX_NOEXCEPT 373*38fd1498Szrj { return _M_t.end(); } 374*38fd1498Szrj 375*38fd1498Szrj /** 376*38fd1498Szrj * Returns a read-only (constant) iterator that points one past the last 377*38fd1498Szrj * pair in the %map. Iteration is done in ascending order according to 378*38fd1498Szrj * the keys. 379*38fd1498Szrj */ 380*38fd1498Szrj const_iterator 381*38fd1498Szrj end() const _GLIBCXX_NOEXCEPT 382*38fd1498Szrj { return _M_t.end(); } 383*38fd1498Szrj 384*38fd1498Szrj /** 385*38fd1498Szrj * Returns a read/write reverse iterator that points to the last pair in 386*38fd1498Szrj * the %map. Iteration is done in descending order according to the 387*38fd1498Szrj * keys. 388*38fd1498Szrj */ 389*38fd1498Szrj reverse_iterator 390*38fd1498Szrj rbegin() _GLIBCXX_NOEXCEPT 391*38fd1498Szrj { return _M_t.rbegin(); } 392*38fd1498Szrj 393*38fd1498Szrj /** 394*38fd1498Szrj * Returns a read-only (constant) reverse iterator that points to the 395*38fd1498Szrj * last pair in the %map. Iteration is done in descending order 396*38fd1498Szrj * according to the keys. 397*38fd1498Szrj */ 398*38fd1498Szrj const_reverse_iterator 399*38fd1498Szrj rbegin() const _GLIBCXX_NOEXCEPT 400*38fd1498Szrj { return _M_t.rbegin(); } 401*38fd1498Szrj 402*38fd1498Szrj /** 403*38fd1498Szrj * Returns a read/write reverse iterator that points to one before the 404*38fd1498Szrj * first pair in the %map. Iteration is done in descending order 405*38fd1498Szrj * according to the keys. 406*38fd1498Szrj */ 407*38fd1498Szrj reverse_iterator 408*38fd1498Szrj rend() _GLIBCXX_NOEXCEPT 409*38fd1498Szrj { return _M_t.rend(); } 410*38fd1498Szrj 411*38fd1498Szrj /** 412*38fd1498Szrj * Returns a read-only (constant) reverse iterator that points to one 413*38fd1498Szrj * before the first pair in the %map. Iteration is done in descending 414*38fd1498Szrj * order according to the keys. 415*38fd1498Szrj */ 416*38fd1498Szrj const_reverse_iterator 417*38fd1498Szrj rend() const _GLIBCXX_NOEXCEPT 418*38fd1498Szrj { return _M_t.rend(); } 419*38fd1498Szrj 420*38fd1498Szrj #if __cplusplus >= 201103L 421*38fd1498Szrj /** 422*38fd1498Szrj * Returns a read-only (constant) iterator that points to the first pair 423*38fd1498Szrj * in the %map. Iteration is done in ascending order according to the 424*38fd1498Szrj * keys. 425*38fd1498Szrj */ 426*38fd1498Szrj const_iterator 427*38fd1498Szrj cbegin() const noexcept 428*38fd1498Szrj { return _M_t.begin(); } 429*38fd1498Szrj 430*38fd1498Szrj /** 431*38fd1498Szrj * Returns a read-only (constant) iterator that points one past the last 432*38fd1498Szrj * pair in the %map. Iteration is done in ascending order according to 433*38fd1498Szrj * the keys. 434*38fd1498Szrj */ 435*38fd1498Szrj const_iterator 436*38fd1498Szrj cend() const noexcept 437*38fd1498Szrj { return _M_t.end(); } 438*38fd1498Szrj 439*38fd1498Szrj /** 440*38fd1498Szrj * Returns a read-only (constant) reverse iterator that points to the 441*38fd1498Szrj * last pair in the %map. Iteration is done in descending order 442*38fd1498Szrj * according to the keys. 443*38fd1498Szrj */ 444*38fd1498Szrj const_reverse_iterator 445*38fd1498Szrj crbegin() const noexcept 446*38fd1498Szrj { return _M_t.rbegin(); } 447*38fd1498Szrj 448*38fd1498Szrj /** 449*38fd1498Szrj * Returns a read-only (constant) reverse iterator that points to one 450*38fd1498Szrj * before the first pair in the %map. Iteration is done in descending 451*38fd1498Szrj * order according to the keys. 452*38fd1498Szrj */ 453*38fd1498Szrj const_reverse_iterator 454*38fd1498Szrj crend() const noexcept 455*38fd1498Szrj { return _M_t.rend(); } 456*38fd1498Szrj #endif 457*38fd1498Szrj 458*38fd1498Szrj // capacity 459*38fd1498Szrj /** Returns true if the %map is empty. (Thus begin() would equal 460*38fd1498Szrj * end().) 461*38fd1498Szrj */ 462*38fd1498Szrj bool 463*38fd1498Szrj empty() const _GLIBCXX_NOEXCEPT 464*38fd1498Szrj { return _M_t.empty(); } 465*38fd1498Szrj 466*38fd1498Szrj /** Returns the size of the %map. */ 467*38fd1498Szrj size_type 468*38fd1498Szrj size() const _GLIBCXX_NOEXCEPT 469*38fd1498Szrj { return _M_t.size(); } 470*38fd1498Szrj 471*38fd1498Szrj /** Returns the maximum size of the %map. */ 472*38fd1498Szrj size_type 473*38fd1498Szrj max_size() const _GLIBCXX_NOEXCEPT 474*38fd1498Szrj { return _M_t.max_size(); } 475*38fd1498Szrj 476*38fd1498Szrj // [23.3.1.2] element access 477*38fd1498Szrj /** 478*38fd1498Szrj * @brief Subscript ( @c [] ) access to %map data. 479*38fd1498Szrj * @param __k The key for which data should be retrieved. 480*38fd1498Szrj * @return A reference to the data of the (key,data) %pair. 481*38fd1498Szrj * 482*38fd1498Szrj * Allows for easy lookup with the subscript ( @c [] ) 483*38fd1498Szrj * operator. Returns data associated with the key specified in 484*38fd1498Szrj * subscript. If the key does not exist, a pair with that key 485*38fd1498Szrj * is created using default values, which is then returned. 486*38fd1498Szrj * 487*38fd1498Szrj * Lookup requires logarithmic time. 488*38fd1498Szrj */ 489*38fd1498Szrj mapped_type& 490*38fd1498Szrj operator[](const key_type& __k) 491*38fd1498Szrj { 492*38fd1498Szrj // concept requirements 493*38fd1498Szrj __glibcxx_function_requires(_DefaultConstructibleConcept<mapped_type>) 494*38fd1498Szrj 495*38fd1498Szrj iterator __i = lower_bound(__k); 496*38fd1498Szrj // __i->first is greater than or equivalent to __k. 497*38fd1498Szrj if (__i == end() || key_comp()(__k, (*__i).first)) 498*38fd1498Szrj #if __cplusplus >= 201103L 499*38fd1498Szrj __i = _M_t._M_emplace_hint_unique(__i, std::piecewise_construct, 500*38fd1498Szrj std::tuple<const key_type&>(__k), 501*38fd1498Szrj std::tuple<>()); 502*38fd1498Szrj #else 503*38fd1498Szrj __i = insert(__i, value_type(__k, mapped_type())); 504*38fd1498Szrj #endif 505*38fd1498Szrj return (*__i).second; 506*38fd1498Szrj } 507*38fd1498Szrj 508*38fd1498Szrj #if __cplusplus >= 201103L 509*38fd1498Szrj mapped_type& 510*38fd1498Szrj operator[](key_type&& __k) 511*38fd1498Szrj { 512*38fd1498Szrj // concept requirements 513*38fd1498Szrj __glibcxx_function_requires(_DefaultConstructibleConcept<mapped_type>) 514*38fd1498Szrj 515*38fd1498Szrj iterator __i = lower_bound(__k); 516*38fd1498Szrj // __i->first is greater than or equivalent to __k. 517*38fd1498Szrj if (__i == end() || key_comp()(__k, (*__i).first)) 518*38fd1498Szrj __i = _M_t._M_emplace_hint_unique(__i, std::piecewise_construct, 519*38fd1498Szrj std::forward_as_tuple(std::move(__k)), 520*38fd1498Szrj std::tuple<>()); 521*38fd1498Szrj return (*__i).second; 522*38fd1498Szrj } 523*38fd1498Szrj #endif 524*38fd1498Szrj 525*38fd1498Szrj // _GLIBCXX_RESOLVE_LIB_DEFECTS 526*38fd1498Szrj // DR 464. Suggestion for new member functions in standard containers. 527*38fd1498Szrj /** 528*38fd1498Szrj * @brief Access to %map data. 529*38fd1498Szrj * @param __k The key for which data should be retrieved. 530*38fd1498Szrj * @return A reference to the data whose key is equivalent to @a __k, if 531*38fd1498Szrj * such a data is present in the %map. 532*38fd1498Szrj * @throw std::out_of_range If no such data is present. 533*38fd1498Szrj */ 534*38fd1498Szrj mapped_type& 535*38fd1498Szrj at(const key_type& __k) 536*38fd1498Szrj { 537*38fd1498Szrj iterator __i = lower_bound(__k); 538*38fd1498Szrj if (__i == end() || key_comp()(__k, (*__i).first)) 539*38fd1498Szrj __throw_out_of_range(__N("map::at")); 540*38fd1498Szrj return (*__i).second; 541*38fd1498Szrj } 542*38fd1498Szrj 543*38fd1498Szrj const mapped_type& 544*38fd1498Szrj at(const key_type& __k) const 545*38fd1498Szrj { 546*38fd1498Szrj const_iterator __i = lower_bound(__k); 547*38fd1498Szrj if (__i == end() || key_comp()(__k, (*__i).first)) 548*38fd1498Szrj __throw_out_of_range(__N("map::at")); 549*38fd1498Szrj return (*__i).second; 550*38fd1498Szrj } 551*38fd1498Szrj 552*38fd1498Szrj // modifiers 553*38fd1498Szrj #if __cplusplus >= 201103L 554*38fd1498Szrj /** 555*38fd1498Szrj * @brief Attempts to build and insert a std::pair into the %map. 556*38fd1498Szrj * 557*38fd1498Szrj * @param __args Arguments used to generate a new pair instance (see 558*38fd1498Szrj * std::piecewise_contruct for passing arguments to each 559*38fd1498Szrj * part of the pair constructor). 560*38fd1498Szrj * 561*38fd1498Szrj * @return A pair, of which the first element is an iterator that points 562*38fd1498Szrj * to the possibly inserted pair, and the second is a bool that 563*38fd1498Szrj * is true if the pair was actually inserted. 564*38fd1498Szrj * 565*38fd1498Szrj * This function attempts to build and insert a (key, value) %pair into 566*38fd1498Szrj * the %map. 567*38fd1498Szrj * A %map relies on unique keys and thus a %pair is only inserted if its 568*38fd1498Szrj * first element (the key) is not already present in the %map. 569*38fd1498Szrj * 570*38fd1498Szrj * Insertion requires logarithmic time. 571*38fd1498Szrj */ 572*38fd1498Szrj template<typename... _Args> 573*38fd1498Szrj std::pair<iterator, bool> 574*38fd1498Szrj emplace(_Args&&... __args) 575*38fd1498Szrj { return _M_t._M_emplace_unique(std::forward<_Args>(__args)...); } 576*38fd1498Szrj 577*38fd1498Szrj /** 578*38fd1498Szrj * @brief Attempts to build and insert a std::pair into the %map. 579*38fd1498Szrj * 580*38fd1498Szrj * @param __pos An iterator that serves as a hint as to where the pair 581*38fd1498Szrj * should be inserted. 582*38fd1498Szrj * @param __args Arguments used to generate a new pair instance (see 583*38fd1498Szrj * std::piecewise_contruct for passing arguments to each 584*38fd1498Szrj * part of the pair constructor). 585*38fd1498Szrj * @return An iterator that points to the element with key of the 586*38fd1498Szrj * std::pair built from @a __args (may or may not be that 587*38fd1498Szrj * std::pair). 588*38fd1498Szrj * 589*38fd1498Szrj * This function is not concerned about whether the insertion took place, 590*38fd1498Szrj * and thus does not return a boolean like the single-argument emplace() 591*38fd1498Szrj * does. 592*38fd1498Szrj * Note that the first parameter is only a hint and can potentially 593*38fd1498Szrj * improve the performance of the insertion process. A bad hint would 594*38fd1498Szrj * cause no gains in efficiency. 595*38fd1498Szrj * 596*38fd1498Szrj * See 597*38fd1498Szrj * https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints 598*38fd1498Szrj * for more on @a hinting. 599*38fd1498Szrj * 600*38fd1498Szrj * Insertion requires logarithmic time (if the hint is not taken). 601*38fd1498Szrj */ 602*38fd1498Szrj template<typename... _Args> 603*38fd1498Szrj iterator 604*38fd1498Szrj emplace_hint(const_iterator __pos, _Args&&... __args) 605*38fd1498Szrj { 606*38fd1498Szrj return _M_t._M_emplace_hint_unique(__pos, 607*38fd1498Szrj std::forward<_Args>(__args)...); 608*38fd1498Szrj } 609*38fd1498Szrj #endif 610*38fd1498Szrj 611*38fd1498Szrj #if __cplusplus > 201402L 612*38fd1498Szrj /// Extract a node. 613*38fd1498Szrj node_type 614*38fd1498Szrj extract(const_iterator __pos) 615*38fd1498Szrj { 616*38fd1498Szrj __glibcxx_assert(__pos != end()); 617*38fd1498Szrj return _M_t.extract(__pos); 618*38fd1498Szrj } 619*38fd1498Szrj 620*38fd1498Szrj /// Extract a node. 621*38fd1498Szrj node_type 622*38fd1498Szrj extract(const key_type& __x) 623*38fd1498Szrj { return _M_t.extract(__x); } 624*38fd1498Szrj 625*38fd1498Szrj /// Re-insert an extracted node. 626*38fd1498Szrj insert_return_type 627*38fd1498Szrj insert(node_type&& __nh) 628*38fd1498Szrj { return _M_t._M_reinsert_node_unique(std::move(__nh)); } 629*38fd1498Szrj 630*38fd1498Szrj /// Re-insert an extracted node. 631*38fd1498Szrj iterator 632*38fd1498Szrj insert(const_iterator __hint, node_type&& __nh) 633*38fd1498Szrj { return _M_t._M_reinsert_node_hint_unique(__hint, std::move(__nh)); } 634*38fd1498Szrj 635*38fd1498Szrj template<typename, typename> 636*38fd1498Szrj friend class std::_Rb_tree_merge_helper; 637*38fd1498Szrj 638*38fd1498Szrj template<typename _C2> 639*38fd1498Szrj void 640*38fd1498Szrj merge(map<_Key, _Tp, _C2, _Alloc>& __source) 641*38fd1498Szrj { 642*38fd1498Szrj using _Merge_helper = _Rb_tree_merge_helper<map, _C2>; 643*38fd1498Szrj _M_t._M_merge_unique(_Merge_helper::_S_get_tree(__source)); 644*38fd1498Szrj } 645*38fd1498Szrj 646*38fd1498Szrj template<typename _C2> 647*38fd1498Szrj void 648*38fd1498Szrj merge(map<_Key, _Tp, _C2, _Alloc>&& __source) 649*38fd1498Szrj { merge(__source); } 650*38fd1498Szrj 651*38fd1498Szrj template<typename _C2> 652*38fd1498Szrj void 653*38fd1498Szrj merge(multimap<_Key, _Tp, _C2, _Alloc>& __source) 654*38fd1498Szrj { 655*38fd1498Szrj using _Merge_helper = _Rb_tree_merge_helper<map, _C2>; 656*38fd1498Szrj _M_t._M_merge_unique(_Merge_helper::_S_get_tree(__source)); 657*38fd1498Szrj } 658*38fd1498Szrj 659*38fd1498Szrj template<typename _C2> 660*38fd1498Szrj void 661*38fd1498Szrj merge(multimap<_Key, _Tp, _C2, _Alloc>&& __source) 662*38fd1498Szrj { merge(__source); } 663*38fd1498Szrj #endif // C++17 664*38fd1498Szrj 665*38fd1498Szrj #if __cplusplus > 201402L 666*38fd1498Szrj #define __cpp_lib_map_try_emplace 201411 667*38fd1498Szrj /** 668*38fd1498Szrj * @brief Attempts to build and insert a std::pair into the %map. 669*38fd1498Szrj * 670*38fd1498Szrj * @param __k Key to use for finding a possibly existing pair in 671*38fd1498Szrj * the map. 672*38fd1498Szrj * @param __args Arguments used to generate the .second for a new pair 673*38fd1498Szrj * instance. 674*38fd1498Szrj * 675*38fd1498Szrj * @return A pair, of which the first element is an iterator that points 676*38fd1498Szrj * to the possibly inserted pair, and the second is a bool that 677*38fd1498Szrj * is true if the pair was actually inserted. 678*38fd1498Szrj * 679*38fd1498Szrj * This function attempts to build and insert a (key, value) %pair into 680*38fd1498Szrj * the %map. 681*38fd1498Szrj * A %map relies on unique keys and thus a %pair is only inserted if its 682*38fd1498Szrj * first element (the key) is not already present in the %map. 683*38fd1498Szrj * If a %pair is not inserted, this function has no effect. 684*38fd1498Szrj * 685*38fd1498Szrj * Insertion requires logarithmic time. 686*38fd1498Szrj */ 687*38fd1498Szrj template <typename... _Args> 688*38fd1498Szrj pair<iterator, bool> 689*38fd1498Szrj try_emplace(const key_type& __k, _Args&&... __args) 690*38fd1498Szrj { 691*38fd1498Szrj iterator __i = lower_bound(__k); 692*38fd1498Szrj if (__i == end() || key_comp()(__k, (*__i).first)) 693*38fd1498Szrj { 694*38fd1498Szrj __i = emplace_hint(__i, std::piecewise_construct, 695*38fd1498Szrj std::forward_as_tuple(__k), 696*38fd1498Szrj std::forward_as_tuple( 697*38fd1498Szrj std::forward<_Args>(__args)...)); 698*38fd1498Szrj return {__i, true}; 699*38fd1498Szrj } 700*38fd1498Szrj return {__i, false}; 701*38fd1498Szrj } 702*38fd1498Szrj 703*38fd1498Szrj // move-capable overload 704*38fd1498Szrj template <typename... _Args> 705*38fd1498Szrj pair<iterator, bool> 706*38fd1498Szrj try_emplace(key_type&& __k, _Args&&... __args) 707*38fd1498Szrj { 708*38fd1498Szrj iterator __i = lower_bound(__k); 709*38fd1498Szrj if (__i == end() || key_comp()(__k, (*__i).first)) 710*38fd1498Szrj { 711*38fd1498Szrj __i = emplace_hint(__i, std::piecewise_construct, 712*38fd1498Szrj std::forward_as_tuple(std::move(__k)), 713*38fd1498Szrj std::forward_as_tuple( 714*38fd1498Szrj std::forward<_Args>(__args)...)); 715*38fd1498Szrj return {__i, true}; 716*38fd1498Szrj } 717*38fd1498Szrj return {__i, false}; 718*38fd1498Szrj } 719*38fd1498Szrj 720*38fd1498Szrj /** 721*38fd1498Szrj * @brief Attempts to build and insert a std::pair into the %map. 722*38fd1498Szrj * 723*38fd1498Szrj * @param __hint An iterator that serves as a hint as to where the 724*38fd1498Szrj * pair should be inserted. 725*38fd1498Szrj * @param __k Key to use for finding a possibly existing pair in 726*38fd1498Szrj * the map. 727*38fd1498Szrj * @param __args Arguments used to generate the .second for a new pair 728*38fd1498Szrj * instance. 729*38fd1498Szrj * @return An iterator that points to the element with key of the 730*38fd1498Szrj * std::pair built from @a __args (may or may not be that 731*38fd1498Szrj * std::pair). 732*38fd1498Szrj * 733*38fd1498Szrj * This function is not concerned about whether the insertion took place, 734*38fd1498Szrj * and thus does not return a boolean like the single-argument 735*38fd1498Szrj * try_emplace() does. However, if insertion did not take place, 736*38fd1498Szrj * this function has no effect. 737*38fd1498Szrj * Note that the first parameter is only a hint and can potentially 738*38fd1498Szrj * improve the performance of the insertion process. A bad hint would 739*38fd1498Szrj * cause no gains in efficiency. 740*38fd1498Szrj * 741*38fd1498Szrj * See 742*38fd1498Szrj * https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints 743*38fd1498Szrj * for more on @a hinting. 744*38fd1498Szrj * 745*38fd1498Szrj * Insertion requires logarithmic time (if the hint is not taken). 746*38fd1498Szrj */ 747*38fd1498Szrj template <typename... _Args> 748*38fd1498Szrj iterator 749*38fd1498Szrj try_emplace(const_iterator __hint, const key_type& __k, 750*38fd1498Szrj _Args&&... __args) 751*38fd1498Szrj { 752*38fd1498Szrj iterator __i; 753*38fd1498Szrj auto __true_hint = _M_t._M_get_insert_hint_unique_pos(__hint, __k); 754*38fd1498Szrj if (__true_hint.second) 755*38fd1498Szrj __i = emplace_hint(iterator(__true_hint.second), 756*38fd1498Szrj std::piecewise_construct, 757*38fd1498Szrj std::forward_as_tuple(__k), 758*38fd1498Szrj std::forward_as_tuple( 759*38fd1498Szrj std::forward<_Args>(__args)...)); 760*38fd1498Szrj else 761*38fd1498Szrj __i = iterator(__true_hint.first); 762*38fd1498Szrj return __i; 763*38fd1498Szrj } 764*38fd1498Szrj 765*38fd1498Szrj // move-capable overload 766*38fd1498Szrj template <typename... _Args> 767*38fd1498Szrj iterator 768*38fd1498Szrj try_emplace(const_iterator __hint, key_type&& __k, _Args&&... __args) 769*38fd1498Szrj { 770*38fd1498Szrj iterator __i; 771*38fd1498Szrj auto __true_hint = _M_t._M_get_insert_hint_unique_pos(__hint, __k); 772*38fd1498Szrj if (__true_hint.second) 773*38fd1498Szrj __i = emplace_hint(iterator(__true_hint.second), 774*38fd1498Szrj std::piecewise_construct, 775*38fd1498Szrj std::forward_as_tuple(std::move(__k)), 776*38fd1498Szrj std::forward_as_tuple( 777*38fd1498Szrj std::forward<_Args>(__args)...)); 778*38fd1498Szrj else 779*38fd1498Szrj __i = iterator(__true_hint.first); 780*38fd1498Szrj return __i; 781*38fd1498Szrj } 782*38fd1498Szrj #endif 783*38fd1498Szrj 784*38fd1498Szrj /** 785*38fd1498Szrj * @brief Attempts to insert a std::pair into the %map. 786*38fd1498Szrj * @param __x Pair to be inserted (see std::make_pair for easy 787*38fd1498Szrj * creation of pairs). 788*38fd1498Szrj * 789*38fd1498Szrj * @return A pair, of which the first element is an iterator that 790*38fd1498Szrj * points to the possibly inserted pair, and the second is 791*38fd1498Szrj * a bool that is true if the pair was actually inserted. 792*38fd1498Szrj * 793*38fd1498Szrj * This function attempts to insert a (key, value) %pair into the %map. 794*38fd1498Szrj * A %map relies on unique keys and thus a %pair is only inserted if its 795*38fd1498Szrj * first element (the key) is not already present in the %map. 796*38fd1498Szrj * 797*38fd1498Szrj * Insertion requires logarithmic time. 798*38fd1498Szrj * @{ 799*38fd1498Szrj */ 800*38fd1498Szrj std::pair<iterator, bool> 801*38fd1498Szrj insert(const value_type& __x) 802*38fd1498Szrj { return _M_t._M_insert_unique(__x); } 803*38fd1498Szrj 804*38fd1498Szrj #if __cplusplus >= 201103L 805*38fd1498Szrj // _GLIBCXX_RESOLVE_LIB_DEFECTS 806*38fd1498Szrj // 2354. Unnecessary copying when inserting into maps with braced-init 807*38fd1498Szrj std::pair<iterator, bool> 808*38fd1498Szrj insert(value_type&& __x) 809*38fd1498Szrj { return _M_t._M_insert_unique(std::move(__x)); } 810*38fd1498Szrj 811*38fd1498Szrj template<typename _Pair, typename = typename 812*38fd1498Szrj std::enable_if<std::is_constructible<value_type, 813*38fd1498Szrj _Pair&&>::value>::type> 814*38fd1498Szrj std::pair<iterator, bool> 815*38fd1498Szrj insert(_Pair&& __x) 816*38fd1498Szrj { return _M_t._M_insert_unique(std::forward<_Pair>(__x)); } 817*38fd1498Szrj #endif 818*38fd1498Szrj // @} 819*38fd1498Szrj 820*38fd1498Szrj #if __cplusplus >= 201103L 821*38fd1498Szrj /** 822*38fd1498Szrj * @brief Attempts to insert a list of std::pairs into the %map. 823*38fd1498Szrj * @param __list A std::initializer_list<value_type> of pairs to be 824*38fd1498Szrj * inserted. 825*38fd1498Szrj * 826*38fd1498Szrj * Complexity similar to that of the range constructor. 827*38fd1498Szrj */ 828*38fd1498Szrj void 829*38fd1498Szrj insert(std::initializer_list<value_type> __list) 830*38fd1498Szrj { insert(__list.begin(), __list.end()); } 831*38fd1498Szrj #endif 832*38fd1498Szrj 833*38fd1498Szrj /** 834*38fd1498Szrj * @brief Attempts to insert a std::pair into the %map. 835*38fd1498Szrj * @param __position An iterator that serves as a hint as to where the 836*38fd1498Szrj * pair should be inserted. 837*38fd1498Szrj * @param __x Pair to be inserted (see std::make_pair for easy creation 838*38fd1498Szrj * of pairs). 839*38fd1498Szrj * @return An iterator that points to the element with key of 840*38fd1498Szrj * @a __x (may or may not be the %pair passed in). 841*38fd1498Szrj * 842*38fd1498Szrj 843*38fd1498Szrj * This function is not concerned about whether the insertion 844*38fd1498Szrj * took place, and thus does not return a boolean like the 845*38fd1498Szrj * single-argument insert() does. Note that the first 846*38fd1498Szrj * parameter is only a hint and can potentially improve the 847*38fd1498Szrj * performance of the insertion process. A bad hint would 848*38fd1498Szrj * cause no gains in efficiency. 849*38fd1498Szrj * 850*38fd1498Szrj * See 851*38fd1498Szrj * https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints 852*38fd1498Szrj * for more on @a hinting. 853*38fd1498Szrj * 854*38fd1498Szrj * Insertion requires logarithmic time (if the hint is not taken). 855*38fd1498Szrj * @{ 856*38fd1498Szrj */ 857*38fd1498Szrj iterator 858*38fd1498Szrj #if __cplusplus >= 201103L 859*38fd1498Szrj insert(const_iterator __position, const value_type& __x) 860*38fd1498Szrj #else 861*38fd1498Szrj insert(iterator __position, const value_type& __x) 862*38fd1498Szrj #endif 863*38fd1498Szrj { return _M_t._M_insert_unique_(__position, __x); } 864*38fd1498Szrj 865*38fd1498Szrj #if __cplusplus >= 201103L 866*38fd1498Szrj // _GLIBCXX_RESOLVE_LIB_DEFECTS 867*38fd1498Szrj // 2354. Unnecessary copying when inserting into maps with braced-init 868*38fd1498Szrj iterator 869*38fd1498Szrj insert(const_iterator __position, value_type&& __x) 870*38fd1498Szrj { return _M_t._M_insert_unique_(__position, std::move(__x)); } 871*38fd1498Szrj 872*38fd1498Szrj template<typename _Pair, typename = typename 873*38fd1498Szrj std::enable_if<std::is_constructible<value_type, 874*38fd1498Szrj _Pair&&>::value>::type> 875*38fd1498Szrj iterator 876*38fd1498Szrj insert(const_iterator __position, _Pair&& __x) 877*38fd1498Szrj { return _M_t._M_insert_unique_(__position, 878*38fd1498Szrj std::forward<_Pair>(__x)); } 879*38fd1498Szrj #endif 880*38fd1498Szrj // @} 881*38fd1498Szrj 882*38fd1498Szrj /** 883*38fd1498Szrj * @brief Template function that attempts to insert a range of elements. 884*38fd1498Szrj * @param __first Iterator pointing to the start of the range to be 885*38fd1498Szrj * inserted. 886*38fd1498Szrj * @param __last Iterator pointing to the end of the range. 887*38fd1498Szrj * 888*38fd1498Szrj * Complexity similar to that of the range constructor. 889*38fd1498Szrj */ 890*38fd1498Szrj template<typename _InputIterator> 891*38fd1498Szrj void 892*38fd1498Szrj insert(_InputIterator __first, _InputIterator __last) 893*38fd1498Szrj { _M_t._M_insert_unique(__first, __last); } 894*38fd1498Szrj 895*38fd1498Szrj #if __cplusplus > 201402L 896*38fd1498Szrj #define __cpp_lib_map_insertion 201411 897*38fd1498Szrj /** 898*38fd1498Szrj * @brief Attempts to insert or assign a std::pair into the %map. 899*38fd1498Szrj * @param __k Key to use for finding a possibly existing pair in 900*38fd1498Szrj * the map. 901*38fd1498Szrj * @param __obj Argument used to generate the .second for a pair 902*38fd1498Szrj * instance. 903*38fd1498Szrj * 904*38fd1498Szrj * @return A pair, of which the first element is an iterator that 905*38fd1498Szrj * points to the possibly inserted pair, and the second is 906*38fd1498Szrj * a bool that is true if the pair was actually inserted. 907*38fd1498Szrj * 908*38fd1498Szrj * This function attempts to insert a (key, value) %pair into the %map. 909*38fd1498Szrj * A %map relies on unique keys and thus a %pair is only inserted if its 910*38fd1498Szrj * first element (the key) is not already present in the %map. 911*38fd1498Szrj * If the %pair was already in the %map, the .second of the %pair 912*38fd1498Szrj * is assigned from __obj. 913*38fd1498Szrj * 914*38fd1498Szrj * Insertion requires logarithmic time. 915*38fd1498Szrj */ 916*38fd1498Szrj template <typename _Obj> 917*38fd1498Szrj pair<iterator, bool> 918*38fd1498Szrj insert_or_assign(const key_type& __k, _Obj&& __obj) 919*38fd1498Szrj { 920*38fd1498Szrj iterator __i = lower_bound(__k); 921*38fd1498Szrj if (__i == end() || key_comp()(__k, (*__i).first)) 922*38fd1498Szrj { 923*38fd1498Szrj __i = emplace_hint(__i, std::piecewise_construct, 924*38fd1498Szrj std::forward_as_tuple(__k), 925*38fd1498Szrj std::forward_as_tuple( 926*38fd1498Szrj std::forward<_Obj>(__obj))); 927*38fd1498Szrj return {__i, true}; 928*38fd1498Szrj } 929*38fd1498Szrj (*__i).second = std::forward<_Obj>(__obj); 930*38fd1498Szrj return {__i, false}; 931*38fd1498Szrj } 932*38fd1498Szrj 933*38fd1498Szrj // move-capable overload 934*38fd1498Szrj template <typename _Obj> 935*38fd1498Szrj pair<iterator, bool> 936*38fd1498Szrj insert_or_assign(key_type&& __k, _Obj&& __obj) 937*38fd1498Szrj { 938*38fd1498Szrj iterator __i = lower_bound(__k); 939*38fd1498Szrj if (__i == end() || key_comp()(__k, (*__i).first)) 940*38fd1498Szrj { 941*38fd1498Szrj __i = emplace_hint(__i, std::piecewise_construct, 942*38fd1498Szrj std::forward_as_tuple(std::move(__k)), 943*38fd1498Szrj std::forward_as_tuple( 944*38fd1498Szrj std::forward<_Obj>(__obj))); 945*38fd1498Szrj return {__i, true}; 946*38fd1498Szrj } 947*38fd1498Szrj (*__i).second = std::forward<_Obj>(__obj); 948*38fd1498Szrj return {__i, false}; 949*38fd1498Szrj } 950*38fd1498Szrj 951*38fd1498Szrj /** 952*38fd1498Szrj * @brief Attempts to insert or assign a std::pair into the %map. 953*38fd1498Szrj * @param __hint An iterator that serves as a hint as to where the 954*38fd1498Szrj * pair should be inserted. 955*38fd1498Szrj * @param __k Key to use for finding a possibly existing pair in 956*38fd1498Szrj * the map. 957*38fd1498Szrj * @param __obj Argument used to generate the .second for a pair 958*38fd1498Szrj * instance. 959*38fd1498Szrj * 960*38fd1498Szrj * @return An iterator that points to the element with key of 961*38fd1498Szrj * @a __x (may or may not be the %pair passed in). 962*38fd1498Szrj * 963*38fd1498Szrj * This function attempts to insert a (key, value) %pair into the %map. 964*38fd1498Szrj * A %map relies on unique keys and thus a %pair is only inserted if its 965*38fd1498Szrj * first element (the key) is not already present in the %map. 966*38fd1498Szrj * If the %pair was already in the %map, the .second of the %pair 967*38fd1498Szrj * is assigned from __obj. 968*38fd1498Szrj * 969*38fd1498Szrj * Insertion requires logarithmic time. 970*38fd1498Szrj */ 971*38fd1498Szrj template <typename _Obj> 972*38fd1498Szrj iterator 973*38fd1498Szrj insert_or_assign(const_iterator __hint, 974*38fd1498Szrj const key_type& __k, _Obj&& __obj) 975*38fd1498Szrj { 976*38fd1498Szrj iterator __i; 977*38fd1498Szrj auto __true_hint = _M_t._M_get_insert_hint_unique_pos(__hint, __k); 978*38fd1498Szrj if (__true_hint.second) 979*38fd1498Szrj { 980*38fd1498Szrj return emplace_hint(iterator(__true_hint.second), 981*38fd1498Szrj std::piecewise_construct, 982*38fd1498Szrj std::forward_as_tuple(__k), 983*38fd1498Szrj std::forward_as_tuple( 984*38fd1498Szrj std::forward<_Obj>(__obj))); 985*38fd1498Szrj } 986*38fd1498Szrj __i = iterator(__true_hint.first); 987*38fd1498Szrj (*__i).second = std::forward<_Obj>(__obj); 988*38fd1498Szrj return __i; 989*38fd1498Szrj } 990*38fd1498Szrj 991*38fd1498Szrj // move-capable overload 992*38fd1498Szrj template <typename _Obj> 993*38fd1498Szrj iterator 994*38fd1498Szrj insert_or_assign(const_iterator __hint, key_type&& __k, _Obj&& __obj) 995*38fd1498Szrj { 996*38fd1498Szrj iterator __i; 997*38fd1498Szrj auto __true_hint = _M_t._M_get_insert_hint_unique_pos(__hint, __k); 998*38fd1498Szrj if (__true_hint.second) 999*38fd1498Szrj { 1000*38fd1498Szrj return emplace_hint(iterator(__true_hint.second), 1001*38fd1498Szrj std::piecewise_construct, 1002*38fd1498Szrj std::forward_as_tuple(std::move(__k)), 1003*38fd1498Szrj std::forward_as_tuple( 1004*38fd1498Szrj std::forward<_Obj>(__obj))); 1005*38fd1498Szrj } 1006*38fd1498Szrj __i = iterator(__true_hint.first); 1007*38fd1498Szrj (*__i).second = std::forward<_Obj>(__obj); 1008*38fd1498Szrj return __i; 1009*38fd1498Szrj } 1010*38fd1498Szrj #endif 1011*38fd1498Szrj 1012*38fd1498Szrj #if __cplusplus >= 201103L 1013*38fd1498Szrj // _GLIBCXX_RESOLVE_LIB_DEFECTS 1014*38fd1498Szrj // DR 130. Associative erase should return an iterator. 1015*38fd1498Szrj /** 1016*38fd1498Szrj * @brief Erases an element from a %map. 1017*38fd1498Szrj * @param __position An iterator pointing to the element to be erased. 1018*38fd1498Szrj * @return An iterator pointing to the element immediately following 1019*38fd1498Szrj * @a position prior to the element being erased. If no such 1020*38fd1498Szrj * element exists, end() is returned. 1021*38fd1498Szrj * 1022*38fd1498Szrj * This function erases an element, pointed to by the given 1023*38fd1498Szrj * iterator, from a %map. Note that this function only erases 1024*38fd1498Szrj * the element, and that if the element is itself a pointer, 1025*38fd1498Szrj * the pointed-to memory is not touched in any way. Managing 1026*38fd1498Szrj * the pointer is the user's responsibility. 1027*38fd1498Szrj * 1028*38fd1498Szrj * @{ 1029*38fd1498Szrj */ 1030*38fd1498Szrj iterator 1031*38fd1498Szrj erase(const_iterator __position) 1032*38fd1498Szrj { return _M_t.erase(__position); } 1033*38fd1498Szrj 1034*38fd1498Szrj // LWG 2059 1035*38fd1498Szrj _GLIBCXX_ABI_TAG_CXX11 1036*38fd1498Szrj iterator 1037*38fd1498Szrj erase(iterator __position) 1038*38fd1498Szrj { return _M_t.erase(__position); } 1039*38fd1498Szrj // @} 1040*38fd1498Szrj #else 1041*38fd1498Szrj /** 1042*38fd1498Szrj * @brief Erases an element from a %map. 1043*38fd1498Szrj * @param __position An iterator pointing to the element to be erased. 1044*38fd1498Szrj * 1045*38fd1498Szrj * This function erases an element, pointed to by the given 1046*38fd1498Szrj * iterator, from a %map. Note that this function only erases 1047*38fd1498Szrj * the element, and that if the element is itself a pointer, 1048*38fd1498Szrj * the pointed-to memory is not touched in any way. Managing 1049*38fd1498Szrj * the pointer is the user's responsibility. 1050*38fd1498Szrj */ 1051*38fd1498Szrj void 1052*38fd1498Szrj erase(iterator __position) 1053*38fd1498Szrj { _M_t.erase(__position); } 1054*38fd1498Szrj #endif 1055*38fd1498Szrj 1056*38fd1498Szrj /** 1057*38fd1498Szrj * @brief Erases elements according to the provided key. 1058*38fd1498Szrj * @param __x Key of element to be erased. 1059*38fd1498Szrj * @return The number of elements erased. 1060*38fd1498Szrj * 1061*38fd1498Szrj * This function erases all the elements located by the given key from 1062*38fd1498Szrj * a %map. 1063*38fd1498Szrj * Note that this function only erases the element, and that if 1064*38fd1498Szrj * the element is itself a pointer, the pointed-to memory is not touched 1065*38fd1498Szrj * in any way. Managing the pointer is the user's responsibility. 1066*38fd1498Szrj */ 1067*38fd1498Szrj size_type 1068*38fd1498Szrj erase(const key_type& __x) 1069*38fd1498Szrj { return _M_t.erase(__x); } 1070*38fd1498Szrj 1071*38fd1498Szrj #if __cplusplus >= 201103L 1072*38fd1498Szrj // _GLIBCXX_RESOLVE_LIB_DEFECTS 1073*38fd1498Szrj // DR 130. Associative erase should return an iterator. 1074*38fd1498Szrj /** 1075*38fd1498Szrj * @brief Erases a [first,last) range of elements from a %map. 1076*38fd1498Szrj * @param __first Iterator pointing to the start of the range to be 1077*38fd1498Szrj * erased. 1078*38fd1498Szrj * @param __last Iterator pointing to the end of the range to 1079*38fd1498Szrj * be erased. 1080*38fd1498Szrj * @return The iterator @a __last. 1081*38fd1498Szrj * 1082*38fd1498Szrj * This function erases a sequence of elements from a %map. 1083*38fd1498Szrj * Note that this function only erases the element, and that if 1084*38fd1498Szrj * the element is itself a pointer, the pointed-to memory is not touched 1085*38fd1498Szrj * in any way. Managing the pointer is the user's responsibility. 1086*38fd1498Szrj */ 1087*38fd1498Szrj iterator 1088*38fd1498Szrj erase(const_iterator __first, const_iterator __last) 1089*38fd1498Szrj { return _M_t.erase(__first, __last); } 1090*38fd1498Szrj #else 1091*38fd1498Szrj /** 1092*38fd1498Szrj * @brief Erases a [__first,__last) range of elements from a %map. 1093*38fd1498Szrj * @param __first Iterator pointing to the start of the range to be 1094*38fd1498Szrj * erased. 1095*38fd1498Szrj * @param __last Iterator pointing to the end of the range to 1096*38fd1498Szrj * be erased. 1097*38fd1498Szrj * 1098*38fd1498Szrj * This function erases a sequence of elements from a %map. 1099*38fd1498Szrj * Note that this function only erases the element, and that if 1100*38fd1498Szrj * the element is itself a pointer, the pointed-to memory is not touched 1101*38fd1498Szrj * in any way. Managing the pointer is the user's responsibility. 1102*38fd1498Szrj */ 1103*38fd1498Szrj void 1104*38fd1498Szrj erase(iterator __first, iterator __last) 1105*38fd1498Szrj { _M_t.erase(__first, __last); } 1106*38fd1498Szrj #endif 1107*38fd1498Szrj 1108*38fd1498Szrj /** 1109*38fd1498Szrj * @brief Swaps data with another %map. 1110*38fd1498Szrj * @param __x A %map of the same element and allocator types. 1111*38fd1498Szrj * 1112*38fd1498Szrj * This exchanges the elements between two maps in constant 1113*38fd1498Szrj * time. (It is only swapping a pointer, an integer, and an 1114*38fd1498Szrj * instance of the @c Compare type (which itself is often 1115*38fd1498Szrj * stateless and empty), so it should be quite fast.) Note 1116*38fd1498Szrj * that the global std::swap() function is specialized such 1117*38fd1498Szrj * that std::swap(m1,m2) will feed to this function. 1118*38fd1498Szrj * 1119*38fd1498Szrj * Whether the allocators are swapped depends on the allocator traits. 1120*38fd1498Szrj */ 1121*38fd1498Szrj void 1122*38fd1498Szrj swap(map& __x) 1123*38fd1498Szrj _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value) 1124*38fd1498Szrj { _M_t.swap(__x._M_t); } 1125*38fd1498Szrj 1126*38fd1498Szrj /** 1127*38fd1498Szrj * Erases all elements in a %map. Note that this function only 1128*38fd1498Szrj * erases the elements, and that if the elements themselves are 1129*38fd1498Szrj * pointers, the pointed-to memory is not touched in any way. 1130*38fd1498Szrj * Managing the pointer is the user's responsibility. 1131*38fd1498Szrj */ 1132*38fd1498Szrj void 1133*38fd1498Szrj clear() _GLIBCXX_NOEXCEPT 1134*38fd1498Szrj { _M_t.clear(); } 1135*38fd1498Szrj 1136*38fd1498Szrj // observers 1137*38fd1498Szrj /** 1138*38fd1498Szrj * Returns the key comparison object out of which the %map was 1139*38fd1498Szrj * constructed. 1140*38fd1498Szrj */ 1141*38fd1498Szrj key_compare 1142*38fd1498Szrj key_comp() const 1143*38fd1498Szrj { return _M_t.key_comp(); } 1144*38fd1498Szrj 1145*38fd1498Szrj /** 1146*38fd1498Szrj * Returns a value comparison object, built from the key comparison 1147*38fd1498Szrj * object out of which the %map was constructed. 1148*38fd1498Szrj */ 1149*38fd1498Szrj value_compare 1150*38fd1498Szrj value_comp() const 1151*38fd1498Szrj { return value_compare(_M_t.key_comp()); } 1152*38fd1498Szrj 1153*38fd1498Szrj // [23.3.1.3] map operations 1154*38fd1498Szrj 1155*38fd1498Szrj //@{ 1156*38fd1498Szrj /** 1157*38fd1498Szrj * @brief Tries to locate an element in a %map. 1158*38fd1498Szrj * @param __x Key of (key, value) %pair to be located. 1159*38fd1498Szrj * @return Iterator pointing to sought-after element, or end() if not 1160*38fd1498Szrj * found. 1161*38fd1498Szrj * 1162*38fd1498Szrj * This function takes a key and tries to locate the element with which 1163*38fd1498Szrj * the key matches. If successful the function returns an iterator 1164*38fd1498Szrj * pointing to the sought after %pair. If unsuccessful it returns the 1165*38fd1498Szrj * past-the-end ( @c end() ) iterator. 1166*38fd1498Szrj */ 1167*38fd1498Szrj 1168*38fd1498Szrj iterator 1169*38fd1498Szrj find(const key_type& __x) 1170*38fd1498Szrj { return _M_t.find(__x); } 1171*38fd1498Szrj 1172*38fd1498Szrj #if __cplusplus > 201103L 1173*38fd1498Szrj template<typename _Kt> 1174*38fd1498Szrj auto 1175*38fd1498Szrj find(const _Kt& __x) -> decltype(_M_t._M_find_tr(__x)) 1176*38fd1498Szrj { return _M_t._M_find_tr(__x); } 1177*38fd1498Szrj #endif 1178*38fd1498Szrj //@} 1179*38fd1498Szrj 1180*38fd1498Szrj //@{ 1181*38fd1498Szrj /** 1182*38fd1498Szrj * @brief Tries to locate an element in a %map. 1183*38fd1498Szrj * @param __x Key of (key, value) %pair to be located. 1184*38fd1498Szrj * @return Read-only (constant) iterator pointing to sought-after 1185*38fd1498Szrj * element, or end() if not found. 1186*38fd1498Szrj * 1187*38fd1498Szrj * This function takes a key and tries to locate the element with which 1188*38fd1498Szrj * the key matches. If successful the function returns a constant 1189*38fd1498Szrj * iterator pointing to the sought after %pair. If unsuccessful it 1190*38fd1498Szrj * returns the past-the-end ( @c end() ) iterator. 1191*38fd1498Szrj */ 1192*38fd1498Szrj 1193*38fd1498Szrj const_iterator 1194*38fd1498Szrj find(const key_type& __x) const 1195*38fd1498Szrj { return _M_t.find(__x); } 1196*38fd1498Szrj 1197*38fd1498Szrj #if __cplusplus > 201103L 1198*38fd1498Szrj template<typename _Kt> 1199*38fd1498Szrj auto 1200*38fd1498Szrj find(const _Kt& __x) const -> decltype(_M_t._M_find_tr(__x)) 1201*38fd1498Szrj { return _M_t._M_find_tr(__x); } 1202*38fd1498Szrj #endif 1203*38fd1498Szrj //@} 1204*38fd1498Szrj 1205*38fd1498Szrj //@{ 1206*38fd1498Szrj /** 1207*38fd1498Szrj * @brief Finds the number of elements with given key. 1208*38fd1498Szrj * @param __x Key of (key, value) pairs to be located. 1209*38fd1498Szrj * @return Number of elements with specified key. 1210*38fd1498Szrj * 1211*38fd1498Szrj * This function only makes sense for multimaps; for map the result will 1212*38fd1498Szrj * either be 0 (not present) or 1 (present). 1213*38fd1498Szrj */ 1214*38fd1498Szrj size_type 1215*38fd1498Szrj count(const key_type& __x) const 1216*38fd1498Szrj { return _M_t.find(__x) == _M_t.end() ? 0 : 1; } 1217*38fd1498Szrj 1218*38fd1498Szrj #if __cplusplus > 201103L 1219*38fd1498Szrj template<typename _Kt> 1220*38fd1498Szrj auto 1221*38fd1498Szrj count(const _Kt& __x) const -> decltype(_M_t._M_count_tr(__x)) 1222*38fd1498Szrj { return _M_t._M_count_tr(__x); } 1223*38fd1498Szrj #endif 1224*38fd1498Szrj //@} 1225*38fd1498Szrj 1226*38fd1498Szrj //@{ 1227*38fd1498Szrj /** 1228*38fd1498Szrj * @brief Finds the beginning of a subsequence matching given key. 1229*38fd1498Szrj * @param __x Key of (key, value) pair to be located. 1230*38fd1498Szrj * @return Iterator pointing to first element equal to or greater 1231*38fd1498Szrj * than key, or end(). 1232*38fd1498Szrj * 1233*38fd1498Szrj * This function returns the first element of a subsequence of elements 1234*38fd1498Szrj * that matches the given key. If unsuccessful it returns an iterator 1235*38fd1498Szrj * pointing to the first element that has a greater value than given key 1236*38fd1498Szrj * or end() if no such element exists. 1237*38fd1498Szrj */ 1238*38fd1498Szrj iterator 1239*38fd1498Szrj lower_bound(const key_type& __x) 1240*38fd1498Szrj { return _M_t.lower_bound(__x); } 1241*38fd1498Szrj 1242*38fd1498Szrj #if __cplusplus > 201103L 1243*38fd1498Szrj template<typename _Kt> 1244*38fd1498Szrj auto 1245*38fd1498Szrj lower_bound(const _Kt& __x) 1246*38fd1498Szrj -> decltype(iterator(_M_t._M_lower_bound_tr(__x))) 1247*38fd1498Szrj { return iterator(_M_t._M_lower_bound_tr(__x)); } 1248*38fd1498Szrj #endif 1249*38fd1498Szrj //@} 1250*38fd1498Szrj 1251*38fd1498Szrj //@{ 1252*38fd1498Szrj /** 1253*38fd1498Szrj * @brief Finds the beginning of a subsequence matching given key. 1254*38fd1498Szrj * @param __x Key of (key, value) pair to be located. 1255*38fd1498Szrj * @return Read-only (constant) iterator pointing to first element 1256*38fd1498Szrj * equal to or greater than key, or end(). 1257*38fd1498Szrj * 1258*38fd1498Szrj * This function returns the first element of a subsequence of elements 1259*38fd1498Szrj * that matches the given key. If unsuccessful it returns an iterator 1260*38fd1498Szrj * pointing to the first element that has a greater value than given key 1261*38fd1498Szrj * or end() if no such element exists. 1262*38fd1498Szrj */ 1263*38fd1498Szrj const_iterator 1264*38fd1498Szrj lower_bound(const key_type& __x) const 1265*38fd1498Szrj { return _M_t.lower_bound(__x); } 1266*38fd1498Szrj 1267*38fd1498Szrj #if __cplusplus > 201103L 1268*38fd1498Szrj template<typename _Kt> 1269*38fd1498Szrj auto 1270*38fd1498Szrj lower_bound(const _Kt& __x) const 1271*38fd1498Szrj -> decltype(const_iterator(_M_t._M_lower_bound_tr(__x))) 1272*38fd1498Szrj { return const_iterator(_M_t._M_lower_bound_tr(__x)); } 1273*38fd1498Szrj #endif 1274*38fd1498Szrj //@} 1275*38fd1498Szrj 1276*38fd1498Szrj //@{ 1277*38fd1498Szrj /** 1278*38fd1498Szrj * @brief Finds the end of a subsequence matching given key. 1279*38fd1498Szrj * @param __x Key of (key, value) pair to be located. 1280*38fd1498Szrj * @return Iterator pointing to the first element 1281*38fd1498Szrj * greater than key, or end(). 1282*38fd1498Szrj */ 1283*38fd1498Szrj iterator 1284*38fd1498Szrj upper_bound(const key_type& __x) 1285*38fd1498Szrj { return _M_t.upper_bound(__x); } 1286*38fd1498Szrj 1287*38fd1498Szrj #if __cplusplus > 201103L 1288*38fd1498Szrj template<typename _Kt> 1289*38fd1498Szrj auto 1290*38fd1498Szrj upper_bound(const _Kt& __x) 1291*38fd1498Szrj -> decltype(iterator(_M_t._M_upper_bound_tr(__x))) 1292*38fd1498Szrj { return iterator(_M_t._M_upper_bound_tr(__x)); } 1293*38fd1498Szrj #endif 1294*38fd1498Szrj //@} 1295*38fd1498Szrj 1296*38fd1498Szrj //@{ 1297*38fd1498Szrj /** 1298*38fd1498Szrj * @brief Finds the end of a subsequence matching given key. 1299*38fd1498Szrj * @param __x Key of (key, value) pair to be located. 1300*38fd1498Szrj * @return Read-only (constant) iterator pointing to first iterator 1301*38fd1498Szrj * greater than key, or end(). 1302*38fd1498Szrj */ 1303*38fd1498Szrj const_iterator 1304*38fd1498Szrj upper_bound(const key_type& __x) const 1305*38fd1498Szrj { return _M_t.upper_bound(__x); } 1306*38fd1498Szrj 1307*38fd1498Szrj #if __cplusplus > 201103L 1308*38fd1498Szrj template<typename _Kt> 1309*38fd1498Szrj auto 1310*38fd1498Szrj upper_bound(const _Kt& __x) const 1311*38fd1498Szrj -> decltype(const_iterator(_M_t._M_upper_bound_tr(__x))) 1312*38fd1498Szrj { return const_iterator(_M_t._M_upper_bound_tr(__x)); } 1313*38fd1498Szrj #endif 1314*38fd1498Szrj //@} 1315*38fd1498Szrj 1316*38fd1498Szrj //@{ 1317*38fd1498Szrj /** 1318*38fd1498Szrj * @brief Finds a subsequence matching given key. 1319*38fd1498Szrj * @param __x Key of (key, value) pairs to be located. 1320*38fd1498Szrj * @return Pair of iterators that possibly points to the subsequence 1321*38fd1498Szrj * matching given key. 1322*38fd1498Szrj * 1323*38fd1498Szrj * This function is equivalent to 1324*38fd1498Szrj * @code 1325*38fd1498Szrj * std::make_pair(c.lower_bound(val), 1326*38fd1498Szrj * c.upper_bound(val)) 1327*38fd1498Szrj * @endcode 1328*38fd1498Szrj * (but is faster than making the calls separately). 1329*38fd1498Szrj * 1330*38fd1498Szrj * This function probably only makes sense for multimaps. 1331*38fd1498Szrj */ 1332*38fd1498Szrj std::pair<iterator, iterator> 1333*38fd1498Szrj equal_range(const key_type& __x) 1334*38fd1498Szrj { return _M_t.equal_range(__x); } 1335*38fd1498Szrj 1336*38fd1498Szrj #if __cplusplus > 201103L 1337*38fd1498Szrj template<typename _Kt> 1338*38fd1498Szrj auto 1339*38fd1498Szrj equal_range(const _Kt& __x) 1340*38fd1498Szrj -> decltype(pair<iterator, iterator>(_M_t._M_equal_range_tr(__x))) 1341*38fd1498Szrj { return pair<iterator, iterator>(_M_t._M_equal_range_tr(__x)); } 1342*38fd1498Szrj #endif 1343*38fd1498Szrj //@} 1344*38fd1498Szrj 1345*38fd1498Szrj //@{ 1346*38fd1498Szrj /** 1347*38fd1498Szrj * @brief Finds a subsequence matching given key. 1348*38fd1498Szrj * @param __x Key of (key, value) pairs to be located. 1349*38fd1498Szrj * @return Pair of read-only (constant) iterators that possibly points 1350*38fd1498Szrj * to the subsequence matching given key. 1351*38fd1498Szrj * 1352*38fd1498Szrj * This function is equivalent to 1353*38fd1498Szrj * @code 1354*38fd1498Szrj * std::make_pair(c.lower_bound(val), 1355*38fd1498Szrj * c.upper_bound(val)) 1356*38fd1498Szrj * @endcode 1357*38fd1498Szrj * (but is faster than making the calls separately). 1358*38fd1498Szrj * 1359*38fd1498Szrj * This function probably only makes sense for multimaps. 1360*38fd1498Szrj */ 1361*38fd1498Szrj std::pair<const_iterator, const_iterator> 1362*38fd1498Szrj equal_range(const key_type& __x) const 1363*38fd1498Szrj { return _M_t.equal_range(__x); } 1364*38fd1498Szrj 1365*38fd1498Szrj #if __cplusplus > 201103L 1366*38fd1498Szrj template<typename _Kt> 1367*38fd1498Szrj auto 1368*38fd1498Szrj equal_range(const _Kt& __x) const 1369*38fd1498Szrj -> decltype(pair<const_iterator, const_iterator>( 1370*38fd1498Szrj _M_t._M_equal_range_tr(__x))) 1371*38fd1498Szrj { 1372*38fd1498Szrj return pair<const_iterator, const_iterator>( 1373*38fd1498Szrj _M_t._M_equal_range_tr(__x)); 1374*38fd1498Szrj } 1375*38fd1498Szrj #endif 1376*38fd1498Szrj //@} 1377*38fd1498Szrj 1378*38fd1498Szrj template<typename _K1, typename _T1, typename _C1, typename _A1> 1379*38fd1498Szrj friend bool 1380*38fd1498Szrj operator==(const map<_K1, _T1, _C1, _A1>&, 1381*38fd1498Szrj const map<_K1, _T1, _C1, _A1>&); 1382*38fd1498Szrj 1383*38fd1498Szrj template<typename _K1, typename _T1, typename _C1, typename _A1> 1384*38fd1498Szrj friend bool 1385*38fd1498Szrj operator<(const map<_K1, _T1, _C1, _A1>&, 1386*38fd1498Szrj const map<_K1, _T1, _C1, _A1>&); 1387*38fd1498Szrj }; 1388*38fd1498Szrj 1389*38fd1498Szrj 1390*38fd1498Szrj #if __cpp_deduction_guides >= 201606 1391*38fd1498Szrj 1392*38fd1498Szrj template<typename _InputIterator, 1393*38fd1498Szrj typename _Compare = less<__iter_key_t<_InputIterator>>, 1394*38fd1498Szrj typename _Allocator = allocator<__iter_to_alloc_t<_InputIterator>>, 1395*38fd1498Szrj typename = _RequireInputIter<_InputIterator>, 1396*38fd1498Szrj typename = _RequireAllocator<_Allocator>> 1397*38fd1498Szrj map(_InputIterator, _InputIterator, 1398*38fd1498Szrj _Compare = _Compare(), _Allocator = _Allocator()) 1399*38fd1498Szrj -> map<__iter_key_t<_InputIterator>, __iter_val_t<_InputIterator>, 1400*38fd1498Szrj _Compare, _Allocator>; 1401*38fd1498Szrj 1402*38fd1498Szrj template<typename _Key, typename _Tp, typename _Compare = less<_Key>, 1403*38fd1498Szrj typename _Allocator = allocator<pair<const _Key, _Tp>>, 1404*38fd1498Szrj typename = _RequireAllocator<_Allocator>> 1405*38fd1498Szrj map(initializer_list<pair<_Key, _Tp>>, 1406*38fd1498Szrj _Compare = _Compare(), _Allocator = _Allocator()) 1407*38fd1498Szrj -> map<_Key, _Tp, _Compare, _Allocator>; 1408*38fd1498Szrj 1409*38fd1498Szrj template <typename _InputIterator, typename _Allocator, 1410*38fd1498Szrj typename = _RequireInputIter<_InputIterator>, 1411*38fd1498Szrj typename = _RequireAllocator<_Allocator>> 1412*38fd1498Szrj map(_InputIterator, _InputIterator, _Allocator) 1413*38fd1498Szrj -> map<__iter_key_t<_InputIterator>, __iter_val_t<_InputIterator>, 1414*38fd1498Szrj less<__iter_key_t<_InputIterator>>, _Allocator>; 1415*38fd1498Szrj 1416*38fd1498Szrj template<typename _Key, typename _Tp, typename _Allocator, 1417*38fd1498Szrj typename = _RequireAllocator<_Allocator>> 1418*38fd1498Szrj map(initializer_list<pair<_Key, _Tp>>, _Allocator) 1419*38fd1498Szrj -> map<_Key, _Tp, less<_Key>, _Allocator>; 1420*38fd1498Szrj 1421*38fd1498Szrj #endif 1422*38fd1498Szrj 1423*38fd1498Szrj /** 1424*38fd1498Szrj * @brief Map equality comparison. 1425*38fd1498Szrj * @param __x A %map. 1426*38fd1498Szrj * @param __y A %map of the same type as @a x. 1427*38fd1498Szrj * @return True iff the size and elements of the maps are equal. 1428*38fd1498Szrj * 1429*38fd1498Szrj * This is an equivalence relation. It is linear in the size of the 1430*38fd1498Szrj * maps. Maps are considered equivalent if their sizes are equal, 1431*38fd1498Szrj * and if corresponding elements compare equal. 1432*38fd1498Szrj */ 1433*38fd1498Szrj template<typename _Key, typename _Tp, typename _Compare, typename _Alloc> 1434*38fd1498Szrj inline bool 1435*38fd1498Szrj operator==(const map<_Key, _Tp, _Compare, _Alloc>& __x, 1436*38fd1498Szrj const map<_Key, _Tp, _Compare, _Alloc>& __y) 1437*38fd1498Szrj { return __x._M_t == __y._M_t; } 1438*38fd1498Szrj 1439*38fd1498Szrj /** 1440*38fd1498Szrj * @brief Map ordering relation. 1441*38fd1498Szrj * @param __x A %map. 1442*38fd1498Szrj * @param __y A %map of the same type as @a x. 1443*38fd1498Szrj * @return True iff @a x is lexicographically less than @a y. 1444*38fd1498Szrj * 1445*38fd1498Szrj * This is a total ordering relation. It is linear in the size of the 1446*38fd1498Szrj * maps. The elements must be comparable with @c <. 1447*38fd1498Szrj * 1448*38fd1498Szrj * See std::lexicographical_compare() for how the determination is made. 1449*38fd1498Szrj */ 1450*38fd1498Szrj template<typename _Key, typename _Tp, typename _Compare, typename _Alloc> 1451*38fd1498Szrj inline bool 1452*38fd1498Szrj operator<(const map<_Key, _Tp, _Compare, _Alloc>& __x, 1453*38fd1498Szrj const map<_Key, _Tp, _Compare, _Alloc>& __y) 1454*38fd1498Szrj { return __x._M_t < __y._M_t; } 1455*38fd1498Szrj 1456*38fd1498Szrj /// Based on operator== 1457*38fd1498Szrj template<typename _Key, typename _Tp, typename _Compare, typename _Alloc> 1458*38fd1498Szrj inline bool 1459*38fd1498Szrj operator!=(const map<_Key, _Tp, _Compare, _Alloc>& __x, 1460*38fd1498Szrj const map<_Key, _Tp, _Compare, _Alloc>& __y) 1461*38fd1498Szrj { return !(__x == __y); } 1462*38fd1498Szrj 1463*38fd1498Szrj /// Based on operator< 1464*38fd1498Szrj template<typename _Key, typename _Tp, typename _Compare, typename _Alloc> 1465*38fd1498Szrj inline bool 1466*38fd1498Szrj operator>(const map<_Key, _Tp, _Compare, _Alloc>& __x, 1467*38fd1498Szrj const map<_Key, _Tp, _Compare, _Alloc>& __y) 1468*38fd1498Szrj { return __y < __x; } 1469*38fd1498Szrj 1470*38fd1498Szrj /// Based on operator< 1471*38fd1498Szrj template<typename _Key, typename _Tp, typename _Compare, typename _Alloc> 1472*38fd1498Szrj inline bool 1473*38fd1498Szrj operator<=(const map<_Key, _Tp, _Compare, _Alloc>& __x, 1474*38fd1498Szrj const map<_Key, _Tp, _Compare, _Alloc>& __y) 1475*38fd1498Szrj { return !(__y < __x); } 1476*38fd1498Szrj 1477*38fd1498Szrj /// Based on operator< 1478*38fd1498Szrj template<typename _Key, typename _Tp, typename _Compare, typename _Alloc> 1479*38fd1498Szrj inline bool 1480*38fd1498Szrj operator>=(const map<_Key, _Tp, _Compare, _Alloc>& __x, 1481*38fd1498Szrj const map<_Key, _Tp, _Compare, _Alloc>& __y) 1482*38fd1498Szrj { return !(__x < __y); } 1483*38fd1498Szrj 1484*38fd1498Szrj /// See std::map::swap(). 1485*38fd1498Szrj template<typename _Key, typename _Tp, typename _Compare, typename _Alloc> 1486*38fd1498Szrj inline void 1487*38fd1498Szrj swap(map<_Key, _Tp, _Compare, _Alloc>& __x, 1488*38fd1498Szrj map<_Key, _Tp, _Compare, _Alloc>& __y) 1489*38fd1498Szrj _GLIBCXX_NOEXCEPT_IF(noexcept(__x.swap(__y))) 1490*38fd1498Szrj { __x.swap(__y); } 1491*38fd1498Szrj 1492*38fd1498Szrj _GLIBCXX_END_NAMESPACE_CONTAINER 1493*38fd1498Szrj 1494*38fd1498Szrj #if __cplusplus > 201402L 1495*38fd1498Szrj // Allow std::map access to internals of compatible maps. 1496*38fd1498Szrj template<typename _Key, typename _Val, typename _Cmp1, typename _Alloc, 1497*38fd1498Szrj typename _Cmp2> 1498*38fd1498Szrj struct 1499*38fd1498Szrj _Rb_tree_merge_helper<_GLIBCXX_STD_C::map<_Key, _Val, _Cmp1, _Alloc>, 1500*38fd1498Szrj _Cmp2> 1501*38fd1498Szrj { 1502*38fd1498Szrj private: 1503*38fd1498Szrj friend class _GLIBCXX_STD_C::map<_Key, _Val, _Cmp1, _Alloc>; 1504*38fd1498Szrj 1505*38fd1498Szrj static auto& 1506*38fd1498Szrj _S_get_tree(_GLIBCXX_STD_C::map<_Key, _Val, _Cmp2, _Alloc>& __map) 1507*38fd1498Szrj { return __map._M_t; } 1508*38fd1498Szrj 1509*38fd1498Szrj static auto& 1510*38fd1498Szrj _S_get_tree(_GLIBCXX_STD_C::multimap<_Key, _Val, _Cmp2, _Alloc>& __map) 1511*38fd1498Szrj { return __map._M_t; } 1512*38fd1498Szrj }; 1513*38fd1498Szrj #endif // C++17 1514*38fd1498Szrj 1515*38fd1498Szrj _GLIBCXX_END_NAMESPACE_VERSION 1516*38fd1498Szrj } // namespace std 1517*38fd1498Szrj 1518*38fd1498Szrj #endif /* _STL_MAP_H */ 1519