1*38fd1498Szrj // Multimap 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_multimap.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_MULTIMAP_H 57*38fd1498Szrj #define _STL_MULTIMAP_H 1 58*38fd1498Szrj 59*38fd1498Szrj #include <bits/concept_check.h> 60*38fd1498Szrj #if __cplusplus >= 201103L 61*38fd1498Szrj #include <initializer_list> 62*38fd1498Szrj #endif 63*38fd1498Szrj 64*38fd1498Szrj namespace std _GLIBCXX_VISIBILITY(default) 65*38fd1498Szrj { 66*38fd1498Szrj _GLIBCXX_BEGIN_NAMESPACE_VERSION 67*38fd1498Szrj _GLIBCXX_BEGIN_NAMESPACE_CONTAINER 68*38fd1498Szrj 69*38fd1498Szrj template <typename _Key, typename _Tp, typename _Compare, typename _Alloc> 70*38fd1498Szrj class map; 71*38fd1498Szrj 72*38fd1498Szrj /** 73*38fd1498Szrj * @brief A standard container made up of (key,value) pairs, which can be 74*38fd1498Szrj * retrieved based on a key, in logarithmic time. 75*38fd1498Szrj * 76*38fd1498Szrj * @ingroup associative_containers 77*38fd1498Szrj * 78*38fd1498Szrj * @tparam _Key Type of key objects. 79*38fd1498Szrj * @tparam _Tp Type of mapped objects. 80*38fd1498Szrj * @tparam _Compare Comparison function object type, defaults to less<_Key>. 81*38fd1498Szrj * @tparam _Alloc Allocator type, defaults to 82*38fd1498Szrj * allocator<pair<const _Key, _Tp>. 83*38fd1498Szrj * 84*38fd1498Szrj * Meets the requirements of a <a href="tables.html#65">container</a>, a 85*38fd1498Szrj * <a href="tables.html#66">reversible container</a>, and an 86*38fd1498Szrj * <a href="tables.html#69">associative container</a> (using equivalent 87*38fd1498Szrj * keys). For a @c multimap<Key,T> the key_type is Key, the mapped_type 88*38fd1498Szrj * is T, and the value_type is std::pair<const Key,T>. 89*38fd1498Szrj * 90*38fd1498Szrj * Multimaps support bidirectional iterators. 91*38fd1498Szrj * 92*38fd1498Szrj * The private tree data is declared exactly the same way for map and 93*38fd1498Szrj * multimap; the distinction is made entirely in how the tree functions are 94*38fd1498Szrj * called (*_unique versus *_equal, same as the standard). 95*38fd1498Szrj */ 96*38fd1498Szrj template <typename _Key, typename _Tp, 97*38fd1498Szrj typename _Compare = std::less<_Key>, 98*38fd1498Szrj typename _Alloc = std::allocator<std::pair<const _Key, _Tp> > > 99*38fd1498Szrj class multimap 100*38fd1498Szrj { 101*38fd1498Szrj public: 102*38fd1498Szrj typedef _Key key_type; 103*38fd1498Szrj typedef _Tp mapped_type; 104*38fd1498Szrj typedef std::pair<const _Key, _Tp> value_type; 105*38fd1498Szrj typedef _Compare key_compare; 106*38fd1498Szrj typedef _Alloc allocator_type; 107*38fd1498Szrj 108*38fd1498Szrj private: 109*38fd1498Szrj #ifdef _GLIBCXX_CONCEPT_CHECKS 110*38fd1498Szrj // concept requirements 111*38fd1498Szrj typedef typename _Alloc::value_type _Alloc_value_type; 112*38fd1498Szrj # if __cplusplus < 201103L 113*38fd1498Szrj __glibcxx_class_requires(_Tp, _SGIAssignableConcept) 114*38fd1498Szrj # endif 115*38fd1498Szrj __glibcxx_class_requires4(_Compare, bool, _Key, _Key, 116*38fd1498Szrj _BinaryFunctionConcept) 117*38fd1498Szrj __glibcxx_class_requires2(value_type, _Alloc_value_type, _SameTypeConcept) 118*38fd1498Szrj #endif 119*38fd1498Szrj 120*38fd1498Szrj #if __cplusplus >= 201103L && defined(__STRICT_ANSI__) 121*38fd1498Szrj static_assert(is_same<typename _Alloc::value_type, value_type>::value, 122*38fd1498Szrj "std::multimap must have the same value_type as its allocator"); 123*38fd1498Szrj #endif 124*38fd1498Szrj 125*38fd1498Szrj public: 126*38fd1498Szrj class value_compare 127*38fd1498Szrj : public std::binary_function<value_type, value_type, bool> 128*38fd1498Szrj { 129*38fd1498Szrj friend class multimap<_Key, _Tp, _Compare, _Alloc>; 130*38fd1498Szrj protected: 131*38fd1498Szrj _Compare comp; 132*38fd1498Szrj 133*38fd1498Szrj value_compare(_Compare __c) 134*38fd1498Szrj : comp(__c) { } 135*38fd1498Szrj 136*38fd1498Szrj public: 137*38fd1498Szrj bool operator()(const value_type& __x, const value_type& __y) const 138*38fd1498Szrj { return comp(__x.first, __y.first); } 139*38fd1498Szrj }; 140*38fd1498Szrj 141*38fd1498Szrj private: 142*38fd1498Szrj /// This turns a red-black tree into a [multi]map. 143*38fd1498Szrj typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template 144*38fd1498Szrj rebind<value_type>::other _Pair_alloc_type; 145*38fd1498Szrj 146*38fd1498Szrj typedef _Rb_tree<key_type, value_type, _Select1st<value_type>, 147*38fd1498Szrj key_compare, _Pair_alloc_type> _Rep_type; 148*38fd1498Szrj /// The actual tree structure. 149*38fd1498Szrj _Rep_type _M_t; 150*38fd1498Szrj 151*38fd1498Szrj typedef __gnu_cxx::__alloc_traits<_Pair_alloc_type> _Alloc_traits; 152*38fd1498Szrj 153*38fd1498Szrj public: 154*38fd1498Szrj // many of these are specified differently in ISO, but the following are 155*38fd1498Szrj // "functionally equivalent" 156*38fd1498Szrj typedef typename _Alloc_traits::pointer pointer; 157*38fd1498Szrj typedef typename _Alloc_traits::const_pointer const_pointer; 158*38fd1498Szrj typedef typename _Alloc_traits::reference reference; 159*38fd1498Szrj typedef typename _Alloc_traits::const_reference const_reference; 160*38fd1498Szrj typedef typename _Rep_type::iterator iterator; 161*38fd1498Szrj typedef typename _Rep_type::const_iterator const_iterator; 162*38fd1498Szrj typedef typename _Rep_type::size_type size_type; 163*38fd1498Szrj typedef typename _Rep_type::difference_type difference_type; 164*38fd1498Szrj typedef typename _Rep_type::reverse_iterator reverse_iterator; 165*38fd1498Szrj typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator; 166*38fd1498Szrj 167*38fd1498Szrj #if __cplusplus > 201402L 168*38fd1498Szrj using node_type = typename _Rep_type::node_type; 169*38fd1498Szrj #endif 170*38fd1498Szrj 171*38fd1498Szrj // [23.3.2] construct/copy/destroy 172*38fd1498Szrj // (get_allocator() is also listed in this section) 173*38fd1498Szrj 174*38fd1498Szrj /** 175*38fd1498Szrj * @brief Default constructor creates no elements. 176*38fd1498Szrj */ 177*38fd1498Szrj #if __cplusplus < 201103L 178*38fd1498Szrj multimap() : _M_t() { } 179*38fd1498Szrj #else 180*38fd1498Szrj multimap() = default; 181*38fd1498Szrj #endif 182*38fd1498Szrj 183*38fd1498Szrj /** 184*38fd1498Szrj * @brief Creates a %multimap with no elements. 185*38fd1498Szrj * @param __comp A comparison object. 186*38fd1498Szrj * @param __a An allocator object. 187*38fd1498Szrj */ 188*38fd1498Szrj explicit 189*38fd1498Szrj multimap(const _Compare& __comp, 190*38fd1498Szrj const allocator_type& __a = allocator_type()) 191*38fd1498Szrj : _M_t(__comp, _Pair_alloc_type(__a)) { } 192*38fd1498Szrj 193*38fd1498Szrj /** 194*38fd1498Szrj * @brief %Multimap copy constructor. 195*38fd1498Szrj * 196*38fd1498Szrj * Whether the allocator is copied depends on the allocator traits. 197*38fd1498Szrj */ 198*38fd1498Szrj #if __cplusplus < 201103L 199*38fd1498Szrj multimap(const multimap& __x) 200*38fd1498Szrj : _M_t(__x._M_t) { } 201*38fd1498Szrj #else 202*38fd1498Szrj multimap(const multimap&) = default; 203*38fd1498Szrj 204*38fd1498Szrj /** 205*38fd1498Szrj * @brief %Multimap move constructor. 206*38fd1498Szrj * 207*38fd1498Szrj * The newly-created %multimap contains the exact contents of the 208*38fd1498Szrj * moved instance. The moved instance is a valid, but unspecified 209*38fd1498Szrj * %multimap. 210*38fd1498Szrj */ 211*38fd1498Szrj multimap(multimap&&) = default; 212*38fd1498Szrj 213*38fd1498Szrj /** 214*38fd1498Szrj * @brief Builds a %multimap from an initializer_list. 215*38fd1498Szrj * @param __l An initializer_list. 216*38fd1498Szrj * @param __comp A comparison functor. 217*38fd1498Szrj * @param __a An allocator object. 218*38fd1498Szrj * 219*38fd1498Szrj * Create a %multimap consisting of copies of the elements from 220*38fd1498Szrj * the initializer_list. This is linear in N if the list is already 221*38fd1498Szrj * sorted, and NlogN otherwise (where N is @a __l.size()). 222*38fd1498Szrj */ 223*38fd1498Szrj multimap(initializer_list<value_type> __l, 224*38fd1498Szrj const _Compare& __comp = _Compare(), 225*38fd1498Szrj const allocator_type& __a = allocator_type()) 226*38fd1498Szrj : _M_t(__comp, _Pair_alloc_type(__a)) 227*38fd1498Szrj { _M_t._M_insert_equal(__l.begin(), __l.end()); } 228*38fd1498Szrj 229*38fd1498Szrj /// Allocator-extended default constructor. 230*38fd1498Szrj explicit 231*38fd1498Szrj multimap(const allocator_type& __a) 232*38fd1498Szrj : _M_t(_Compare(), _Pair_alloc_type(__a)) { } 233*38fd1498Szrj 234*38fd1498Szrj /// Allocator-extended copy constructor. 235*38fd1498Szrj multimap(const multimap& __m, const allocator_type& __a) 236*38fd1498Szrj : _M_t(__m._M_t, _Pair_alloc_type(__a)) { } 237*38fd1498Szrj 238*38fd1498Szrj /// Allocator-extended move constructor. 239*38fd1498Szrj multimap(multimap&& __m, const allocator_type& __a) 240*38fd1498Szrj noexcept(is_nothrow_copy_constructible<_Compare>::value 241*38fd1498Szrj && _Alloc_traits::_S_always_equal()) 242*38fd1498Szrj : _M_t(std::move(__m._M_t), _Pair_alloc_type(__a)) { } 243*38fd1498Szrj 244*38fd1498Szrj /// Allocator-extended initialier-list constructor. 245*38fd1498Szrj multimap(initializer_list<value_type> __l, const allocator_type& __a) 246*38fd1498Szrj : _M_t(_Compare(), _Pair_alloc_type(__a)) 247*38fd1498Szrj { _M_t._M_insert_equal(__l.begin(), __l.end()); } 248*38fd1498Szrj 249*38fd1498Szrj /// Allocator-extended range constructor. 250*38fd1498Szrj template<typename _InputIterator> 251*38fd1498Szrj multimap(_InputIterator __first, _InputIterator __last, 252*38fd1498Szrj const allocator_type& __a) 253*38fd1498Szrj : _M_t(_Compare(), _Pair_alloc_type(__a)) 254*38fd1498Szrj { _M_t._M_insert_equal(__first, __last); } 255*38fd1498Szrj #endif 256*38fd1498Szrj 257*38fd1498Szrj /** 258*38fd1498Szrj * @brief Builds a %multimap from a range. 259*38fd1498Szrj * @param __first An input iterator. 260*38fd1498Szrj * @param __last An input iterator. 261*38fd1498Szrj * 262*38fd1498Szrj * Create a %multimap consisting of copies of the elements from 263*38fd1498Szrj * [__first,__last). This is linear in N if the range is already sorted, 264*38fd1498Szrj * and NlogN otherwise (where N is distance(__first,__last)). 265*38fd1498Szrj */ 266*38fd1498Szrj template<typename _InputIterator> 267*38fd1498Szrj multimap(_InputIterator __first, _InputIterator __last) 268*38fd1498Szrj : _M_t() 269*38fd1498Szrj { _M_t._M_insert_equal(__first, __last); } 270*38fd1498Szrj 271*38fd1498Szrj /** 272*38fd1498Szrj * @brief Builds a %multimap from a range. 273*38fd1498Szrj * @param __first An input iterator. 274*38fd1498Szrj * @param __last An input iterator. 275*38fd1498Szrj * @param __comp A comparison functor. 276*38fd1498Szrj * @param __a An allocator object. 277*38fd1498Szrj * 278*38fd1498Szrj * Create a %multimap consisting of copies of the elements from 279*38fd1498Szrj * [__first,__last). This is linear in N if the range is already sorted, 280*38fd1498Szrj * and NlogN otherwise (where N is distance(__first,__last)). 281*38fd1498Szrj */ 282*38fd1498Szrj template<typename _InputIterator> 283*38fd1498Szrj multimap(_InputIterator __first, _InputIterator __last, 284*38fd1498Szrj const _Compare& __comp, 285*38fd1498Szrj const allocator_type& __a = allocator_type()) 286*38fd1498Szrj : _M_t(__comp, _Pair_alloc_type(__a)) 287*38fd1498Szrj { _M_t._M_insert_equal(__first, __last); } 288*38fd1498Szrj 289*38fd1498Szrj #if __cplusplus >= 201103L 290*38fd1498Szrj /** 291*38fd1498Szrj * The dtor only erases the elements, and note that if the elements 292*38fd1498Szrj * themselves are pointers, the pointed-to memory is not touched in any 293*38fd1498Szrj * way. Managing the pointer is the user's responsibility. 294*38fd1498Szrj */ 295*38fd1498Szrj ~multimap() = default; 296*38fd1498Szrj #endif 297*38fd1498Szrj 298*38fd1498Szrj /** 299*38fd1498Szrj * @brief %Multimap assignment operator. 300*38fd1498Szrj * 301*38fd1498Szrj * Whether the allocator is copied depends on the allocator traits. 302*38fd1498Szrj */ 303*38fd1498Szrj #if __cplusplus < 201103L 304*38fd1498Szrj multimap& 305*38fd1498Szrj operator=(const multimap& __x) 306*38fd1498Szrj { 307*38fd1498Szrj _M_t = __x._M_t; 308*38fd1498Szrj return *this; 309*38fd1498Szrj } 310*38fd1498Szrj #else 311*38fd1498Szrj multimap& 312*38fd1498Szrj operator=(const multimap&) = default; 313*38fd1498Szrj 314*38fd1498Szrj /// Move assignment operator. 315*38fd1498Szrj multimap& 316*38fd1498Szrj operator=(multimap&&) = default; 317*38fd1498Szrj 318*38fd1498Szrj /** 319*38fd1498Szrj * @brief %Multimap list assignment operator. 320*38fd1498Szrj * @param __l An initializer_list. 321*38fd1498Szrj * 322*38fd1498Szrj * This function fills a %multimap with copies of the elements 323*38fd1498Szrj * in the initializer list @a __l. 324*38fd1498Szrj * 325*38fd1498Szrj * Note that the assignment completely changes the %multimap and 326*38fd1498Szrj * that the resulting %multimap's size is the same as the number 327*38fd1498Szrj * of elements assigned. 328*38fd1498Szrj */ 329*38fd1498Szrj multimap& 330*38fd1498Szrj operator=(initializer_list<value_type> __l) 331*38fd1498Szrj { 332*38fd1498Szrj _M_t._M_assign_equal(__l.begin(), __l.end()); 333*38fd1498Szrj return *this; 334*38fd1498Szrj } 335*38fd1498Szrj #endif 336*38fd1498Szrj 337*38fd1498Szrj /// Get a copy of the memory allocation object. 338*38fd1498Szrj allocator_type 339*38fd1498Szrj get_allocator() const _GLIBCXX_NOEXCEPT 340*38fd1498Szrj { return allocator_type(_M_t.get_allocator()); } 341*38fd1498Szrj 342*38fd1498Szrj // iterators 343*38fd1498Szrj /** 344*38fd1498Szrj * Returns a read/write iterator that points to the first pair in the 345*38fd1498Szrj * %multimap. Iteration is done in ascending order according to the 346*38fd1498Szrj * keys. 347*38fd1498Szrj */ 348*38fd1498Szrj iterator 349*38fd1498Szrj begin() _GLIBCXX_NOEXCEPT 350*38fd1498Szrj { return _M_t.begin(); } 351*38fd1498Szrj 352*38fd1498Szrj /** 353*38fd1498Szrj * Returns a read-only (constant) iterator that points to the first pair 354*38fd1498Szrj * in the %multimap. Iteration is done in ascending order according to 355*38fd1498Szrj * the keys. 356*38fd1498Szrj */ 357*38fd1498Szrj const_iterator 358*38fd1498Szrj begin() const _GLIBCXX_NOEXCEPT 359*38fd1498Szrj { return _M_t.begin(); } 360*38fd1498Szrj 361*38fd1498Szrj /** 362*38fd1498Szrj * Returns a read/write iterator that points one past the last pair in 363*38fd1498Szrj * the %multimap. Iteration is done in ascending order according to the 364*38fd1498Szrj * keys. 365*38fd1498Szrj */ 366*38fd1498Szrj iterator 367*38fd1498Szrj end() _GLIBCXX_NOEXCEPT 368*38fd1498Szrj { return _M_t.end(); } 369*38fd1498Szrj 370*38fd1498Szrj /** 371*38fd1498Szrj * Returns a read-only (constant) iterator that points one past the last 372*38fd1498Szrj * pair in the %multimap. Iteration is done in ascending order according 373*38fd1498Szrj * to the keys. 374*38fd1498Szrj */ 375*38fd1498Szrj const_iterator 376*38fd1498Szrj end() const _GLIBCXX_NOEXCEPT 377*38fd1498Szrj { return _M_t.end(); } 378*38fd1498Szrj 379*38fd1498Szrj /** 380*38fd1498Szrj * Returns a read/write reverse iterator that points to the last pair in 381*38fd1498Szrj * the %multimap. Iteration is done in descending order according to the 382*38fd1498Szrj * keys. 383*38fd1498Szrj */ 384*38fd1498Szrj reverse_iterator 385*38fd1498Szrj rbegin() _GLIBCXX_NOEXCEPT 386*38fd1498Szrj { return _M_t.rbegin(); } 387*38fd1498Szrj 388*38fd1498Szrj /** 389*38fd1498Szrj * Returns a read-only (constant) reverse iterator that points to the 390*38fd1498Szrj * last pair in the %multimap. Iteration is done in descending order 391*38fd1498Szrj * according to the keys. 392*38fd1498Szrj */ 393*38fd1498Szrj const_reverse_iterator 394*38fd1498Szrj rbegin() const _GLIBCXX_NOEXCEPT 395*38fd1498Szrj { return _M_t.rbegin(); } 396*38fd1498Szrj 397*38fd1498Szrj /** 398*38fd1498Szrj * Returns a read/write reverse iterator that points to one before the 399*38fd1498Szrj * first pair in the %multimap. Iteration is done in descending order 400*38fd1498Szrj * according to the keys. 401*38fd1498Szrj */ 402*38fd1498Szrj reverse_iterator 403*38fd1498Szrj rend() _GLIBCXX_NOEXCEPT 404*38fd1498Szrj { return _M_t.rend(); } 405*38fd1498Szrj 406*38fd1498Szrj /** 407*38fd1498Szrj * Returns a read-only (constant) reverse iterator that points to one 408*38fd1498Szrj * before the first pair in the %multimap. Iteration is done in 409*38fd1498Szrj * descending order according to the keys. 410*38fd1498Szrj */ 411*38fd1498Szrj const_reverse_iterator 412*38fd1498Szrj rend() const _GLIBCXX_NOEXCEPT 413*38fd1498Szrj { return _M_t.rend(); } 414*38fd1498Szrj 415*38fd1498Szrj #if __cplusplus >= 201103L 416*38fd1498Szrj /** 417*38fd1498Szrj * Returns a read-only (constant) iterator that points to the first pair 418*38fd1498Szrj * in the %multimap. Iteration is done in ascending order according to 419*38fd1498Szrj * the keys. 420*38fd1498Szrj */ 421*38fd1498Szrj const_iterator 422*38fd1498Szrj cbegin() const noexcept 423*38fd1498Szrj { return _M_t.begin(); } 424*38fd1498Szrj 425*38fd1498Szrj /** 426*38fd1498Szrj * Returns a read-only (constant) iterator that points one past the last 427*38fd1498Szrj * pair in the %multimap. Iteration is done in ascending order according 428*38fd1498Szrj * to the keys. 429*38fd1498Szrj */ 430*38fd1498Szrj const_iterator 431*38fd1498Szrj cend() const noexcept 432*38fd1498Szrj { return _M_t.end(); } 433*38fd1498Szrj 434*38fd1498Szrj /** 435*38fd1498Szrj * Returns a read-only (constant) reverse iterator that points to the 436*38fd1498Szrj * last pair in the %multimap. Iteration is done in descending order 437*38fd1498Szrj * according to the keys. 438*38fd1498Szrj */ 439*38fd1498Szrj const_reverse_iterator 440*38fd1498Szrj crbegin() const noexcept 441*38fd1498Szrj { return _M_t.rbegin(); } 442*38fd1498Szrj 443*38fd1498Szrj /** 444*38fd1498Szrj * Returns a read-only (constant) reverse iterator that points to one 445*38fd1498Szrj * before the first pair in the %multimap. Iteration is done in 446*38fd1498Szrj * descending order according to the keys. 447*38fd1498Szrj */ 448*38fd1498Szrj const_reverse_iterator 449*38fd1498Szrj crend() const noexcept 450*38fd1498Szrj { return _M_t.rend(); } 451*38fd1498Szrj #endif 452*38fd1498Szrj 453*38fd1498Szrj // capacity 454*38fd1498Szrj /** Returns true if the %multimap is empty. */ 455*38fd1498Szrj bool 456*38fd1498Szrj empty() const _GLIBCXX_NOEXCEPT 457*38fd1498Szrj { return _M_t.empty(); } 458*38fd1498Szrj 459*38fd1498Szrj /** Returns the size of the %multimap. */ 460*38fd1498Szrj size_type 461*38fd1498Szrj size() const _GLIBCXX_NOEXCEPT 462*38fd1498Szrj { return _M_t.size(); } 463*38fd1498Szrj 464*38fd1498Szrj /** Returns the maximum size of the %multimap. */ 465*38fd1498Szrj size_type 466*38fd1498Szrj max_size() const _GLIBCXX_NOEXCEPT 467*38fd1498Szrj { return _M_t.max_size(); } 468*38fd1498Szrj 469*38fd1498Szrj // modifiers 470*38fd1498Szrj #if __cplusplus >= 201103L 471*38fd1498Szrj /** 472*38fd1498Szrj * @brief Build and insert a std::pair into the %multimap. 473*38fd1498Szrj * 474*38fd1498Szrj * @param __args Arguments used to generate a new pair instance (see 475*38fd1498Szrj * std::piecewise_contruct for passing arguments to each 476*38fd1498Szrj * part of the pair constructor). 477*38fd1498Szrj * 478*38fd1498Szrj * @return An iterator that points to the inserted (key,value) pair. 479*38fd1498Szrj * 480*38fd1498Szrj * This function builds and inserts a (key, value) %pair into the 481*38fd1498Szrj * %multimap. 482*38fd1498Szrj * Contrary to a std::map the %multimap does not rely on unique keys and 483*38fd1498Szrj * thus multiple pairs with the same key can be inserted. 484*38fd1498Szrj * 485*38fd1498Szrj * Insertion requires logarithmic time. 486*38fd1498Szrj */ 487*38fd1498Szrj template<typename... _Args> 488*38fd1498Szrj iterator 489*38fd1498Szrj emplace(_Args&&... __args) 490*38fd1498Szrj { return _M_t._M_emplace_equal(std::forward<_Args>(__args)...); } 491*38fd1498Szrj 492*38fd1498Szrj /** 493*38fd1498Szrj * @brief Builds and inserts a std::pair into the %multimap. 494*38fd1498Szrj * 495*38fd1498Szrj * @param __pos An iterator that serves as a hint as to where the pair 496*38fd1498Szrj * should be inserted. 497*38fd1498Szrj * @param __args Arguments used to generate a new pair instance (see 498*38fd1498Szrj * std::piecewise_contruct for passing arguments to each 499*38fd1498Szrj * part of the pair constructor). 500*38fd1498Szrj * @return An iterator that points to the inserted (key,value) pair. 501*38fd1498Szrj * 502*38fd1498Szrj * This function inserts a (key, value) pair into the %multimap. 503*38fd1498Szrj * Contrary to a std::map the %multimap does not rely on unique keys and 504*38fd1498Szrj * thus multiple pairs with the same key can be inserted. 505*38fd1498Szrj * Note that the first parameter is only a hint and can potentially 506*38fd1498Szrj * improve the performance of the insertion process. A bad hint would 507*38fd1498Szrj * cause no gains in efficiency. 508*38fd1498Szrj * 509*38fd1498Szrj * For more on @a hinting, see: 510*38fd1498Szrj * https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints 511*38fd1498Szrj * 512*38fd1498Szrj * Insertion requires logarithmic time (if the hint is not taken). 513*38fd1498Szrj */ 514*38fd1498Szrj template<typename... _Args> 515*38fd1498Szrj iterator 516*38fd1498Szrj emplace_hint(const_iterator __pos, _Args&&... __args) 517*38fd1498Szrj { 518*38fd1498Szrj return _M_t._M_emplace_hint_equal(__pos, 519*38fd1498Szrj std::forward<_Args>(__args)...); 520*38fd1498Szrj } 521*38fd1498Szrj #endif 522*38fd1498Szrj 523*38fd1498Szrj /** 524*38fd1498Szrj * @brief Inserts a std::pair into the %multimap. 525*38fd1498Szrj * @param __x Pair to be inserted (see std::make_pair for easy creation 526*38fd1498Szrj * of pairs). 527*38fd1498Szrj * @return An iterator that points to the inserted (key,value) pair. 528*38fd1498Szrj * 529*38fd1498Szrj * This function inserts a (key, value) pair into the %multimap. 530*38fd1498Szrj * Contrary to a std::map the %multimap does not rely on unique keys and 531*38fd1498Szrj * thus multiple pairs with the same key can be inserted. 532*38fd1498Szrj * 533*38fd1498Szrj * Insertion requires logarithmic time. 534*38fd1498Szrj * @{ 535*38fd1498Szrj */ 536*38fd1498Szrj iterator 537*38fd1498Szrj insert(const value_type& __x) 538*38fd1498Szrj { return _M_t._M_insert_equal(__x); } 539*38fd1498Szrj 540*38fd1498Szrj #if __cplusplus >= 201103L 541*38fd1498Szrj // _GLIBCXX_RESOLVE_LIB_DEFECTS 542*38fd1498Szrj // 2354. Unnecessary copying when inserting into maps with braced-init 543*38fd1498Szrj iterator 544*38fd1498Szrj insert(value_type&& __x) 545*38fd1498Szrj { return _M_t._M_insert_equal(std::move(__x)); } 546*38fd1498Szrj 547*38fd1498Szrj template<typename _Pair, typename = typename 548*38fd1498Szrj std::enable_if<std::is_constructible<value_type, 549*38fd1498Szrj _Pair&&>::value>::type> 550*38fd1498Szrj iterator 551*38fd1498Szrj insert(_Pair&& __x) 552*38fd1498Szrj { return _M_t._M_insert_equal(std::forward<_Pair>(__x)); } 553*38fd1498Szrj #endif 554*38fd1498Szrj // @} 555*38fd1498Szrj 556*38fd1498Szrj /** 557*38fd1498Szrj * @brief Inserts a std::pair into the %multimap. 558*38fd1498Szrj * @param __position An iterator that serves as a hint as to where the 559*38fd1498Szrj * pair should be inserted. 560*38fd1498Szrj * @param __x Pair to be inserted (see std::make_pair for easy creation 561*38fd1498Szrj * of pairs). 562*38fd1498Szrj * @return An iterator that points to the inserted (key,value) pair. 563*38fd1498Szrj * 564*38fd1498Szrj * This function inserts a (key, value) pair into the %multimap. 565*38fd1498Szrj * Contrary to a std::map the %multimap does not rely on unique keys and 566*38fd1498Szrj * thus multiple pairs with the same key can be inserted. 567*38fd1498Szrj * Note that the first parameter is only a hint and can potentially 568*38fd1498Szrj * improve the performance of the insertion process. A bad hint would 569*38fd1498Szrj * cause no gains in efficiency. 570*38fd1498Szrj * 571*38fd1498Szrj * For more on @a hinting, see: 572*38fd1498Szrj * https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints 573*38fd1498Szrj * 574*38fd1498Szrj * Insertion requires logarithmic time (if the hint is not taken). 575*38fd1498Szrj * @{ 576*38fd1498Szrj */ 577*38fd1498Szrj iterator 578*38fd1498Szrj #if __cplusplus >= 201103L 579*38fd1498Szrj insert(const_iterator __position, const value_type& __x) 580*38fd1498Szrj #else 581*38fd1498Szrj insert(iterator __position, const value_type& __x) 582*38fd1498Szrj #endif 583*38fd1498Szrj { return _M_t._M_insert_equal_(__position, __x); } 584*38fd1498Szrj 585*38fd1498Szrj #if __cplusplus >= 201103L 586*38fd1498Szrj // _GLIBCXX_RESOLVE_LIB_DEFECTS 587*38fd1498Szrj // 2354. Unnecessary copying when inserting into maps with braced-init 588*38fd1498Szrj iterator 589*38fd1498Szrj insert(const_iterator __position, value_type&& __x) 590*38fd1498Szrj { return _M_t._M_insert_equal_(__position, std::move(__x)); } 591*38fd1498Szrj 592*38fd1498Szrj template<typename _Pair, typename = typename 593*38fd1498Szrj std::enable_if<std::is_constructible<value_type, 594*38fd1498Szrj _Pair&&>::value>::type> 595*38fd1498Szrj iterator 596*38fd1498Szrj insert(const_iterator __position, _Pair&& __x) 597*38fd1498Szrj { return _M_t._M_insert_equal_(__position, 598*38fd1498Szrj std::forward<_Pair>(__x)); } 599*38fd1498Szrj #endif 600*38fd1498Szrj // @} 601*38fd1498Szrj 602*38fd1498Szrj /** 603*38fd1498Szrj * @brief A template function that attempts to insert a range 604*38fd1498Szrj * of elements. 605*38fd1498Szrj * @param __first Iterator pointing to the start of the range to be 606*38fd1498Szrj * inserted. 607*38fd1498Szrj * @param __last Iterator pointing to the end of the range. 608*38fd1498Szrj * 609*38fd1498Szrj * Complexity similar to that of the range constructor. 610*38fd1498Szrj */ 611*38fd1498Szrj template<typename _InputIterator> 612*38fd1498Szrj void 613*38fd1498Szrj insert(_InputIterator __first, _InputIterator __last) 614*38fd1498Szrj { _M_t._M_insert_equal(__first, __last); } 615*38fd1498Szrj 616*38fd1498Szrj #if __cplusplus >= 201103L 617*38fd1498Szrj /** 618*38fd1498Szrj * @brief Attempts to insert a list of std::pairs into the %multimap. 619*38fd1498Szrj * @param __l A std::initializer_list<value_type> of pairs to be 620*38fd1498Szrj * inserted. 621*38fd1498Szrj * 622*38fd1498Szrj * Complexity similar to that of the range constructor. 623*38fd1498Szrj */ 624*38fd1498Szrj void 625*38fd1498Szrj insert(initializer_list<value_type> __l) 626*38fd1498Szrj { this->insert(__l.begin(), __l.end()); } 627*38fd1498Szrj #endif 628*38fd1498Szrj 629*38fd1498Szrj #if __cplusplus > 201402L 630*38fd1498Szrj /// Extract a node. 631*38fd1498Szrj node_type 632*38fd1498Szrj extract(const_iterator __pos) 633*38fd1498Szrj { 634*38fd1498Szrj __glibcxx_assert(__pos != end()); 635*38fd1498Szrj return _M_t.extract(__pos); 636*38fd1498Szrj } 637*38fd1498Szrj 638*38fd1498Szrj /// Extract a node. 639*38fd1498Szrj node_type 640*38fd1498Szrj extract(const key_type& __x) 641*38fd1498Szrj { return _M_t.extract(__x); } 642*38fd1498Szrj 643*38fd1498Szrj /// Re-insert an extracted node. 644*38fd1498Szrj iterator 645*38fd1498Szrj insert(node_type&& __nh) 646*38fd1498Szrj { return _M_t._M_reinsert_node_equal(std::move(__nh)); } 647*38fd1498Szrj 648*38fd1498Szrj /// Re-insert an extracted node. 649*38fd1498Szrj iterator 650*38fd1498Szrj insert(const_iterator __hint, node_type&& __nh) 651*38fd1498Szrj { return _M_t._M_reinsert_node_hint_equal(__hint, std::move(__nh)); } 652*38fd1498Szrj 653*38fd1498Szrj template<typename, typename> 654*38fd1498Szrj friend class std::_Rb_tree_merge_helper; 655*38fd1498Szrj 656*38fd1498Szrj template<typename _C2> 657*38fd1498Szrj void 658*38fd1498Szrj merge(multimap<_Key, _Tp, _C2, _Alloc>& __source) 659*38fd1498Szrj { 660*38fd1498Szrj using _Merge_helper = _Rb_tree_merge_helper<multimap, _C2>; 661*38fd1498Szrj _M_t._M_merge_equal(_Merge_helper::_S_get_tree(__source)); 662*38fd1498Szrj } 663*38fd1498Szrj 664*38fd1498Szrj template<typename _C2> 665*38fd1498Szrj void 666*38fd1498Szrj merge(multimap<_Key, _Tp, _C2, _Alloc>&& __source) 667*38fd1498Szrj { merge(__source); } 668*38fd1498Szrj 669*38fd1498Szrj template<typename _C2> 670*38fd1498Szrj void 671*38fd1498Szrj merge(map<_Key, _Tp, _C2, _Alloc>& __source) 672*38fd1498Szrj { 673*38fd1498Szrj using _Merge_helper = _Rb_tree_merge_helper<multimap, _C2>; 674*38fd1498Szrj _M_t._M_merge_equal(_Merge_helper::_S_get_tree(__source)); 675*38fd1498Szrj } 676*38fd1498Szrj 677*38fd1498Szrj template<typename _C2> 678*38fd1498Szrj void 679*38fd1498Szrj merge(map<_Key, _Tp, _C2, _Alloc>&& __source) 680*38fd1498Szrj { merge(__source); } 681*38fd1498Szrj #endif // C++17 682*38fd1498Szrj 683*38fd1498Szrj #if __cplusplus >= 201103L 684*38fd1498Szrj // _GLIBCXX_RESOLVE_LIB_DEFECTS 685*38fd1498Szrj // DR 130. Associative erase should return an iterator. 686*38fd1498Szrj /** 687*38fd1498Szrj * @brief Erases an element from a %multimap. 688*38fd1498Szrj * @param __position An iterator pointing to the element to be erased. 689*38fd1498Szrj * @return An iterator pointing to the element immediately following 690*38fd1498Szrj * @a position prior to the element being erased. If no such 691*38fd1498Szrj * element exists, end() is returned. 692*38fd1498Szrj * 693*38fd1498Szrj * This function erases an element, pointed to by the given iterator, 694*38fd1498Szrj * from a %multimap. Note that this function only erases the element, 695*38fd1498Szrj * and that if the element is itself a pointer, the pointed-to memory is 696*38fd1498Szrj * not touched in any way. Managing the pointer is the user's 697*38fd1498Szrj * responsibility. 698*38fd1498Szrj * 699*38fd1498Szrj * @{ 700*38fd1498Szrj */ 701*38fd1498Szrj iterator 702*38fd1498Szrj erase(const_iterator __position) 703*38fd1498Szrj { return _M_t.erase(__position); } 704*38fd1498Szrj 705*38fd1498Szrj // LWG 2059. 706*38fd1498Szrj _GLIBCXX_ABI_TAG_CXX11 707*38fd1498Szrj iterator 708*38fd1498Szrj erase(iterator __position) 709*38fd1498Szrj { return _M_t.erase(__position); } 710*38fd1498Szrj // @} 711*38fd1498Szrj #else 712*38fd1498Szrj /** 713*38fd1498Szrj * @brief Erases an element from a %multimap. 714*38fd1498Szrj * @param __position An iterator pointing to the element to be erased. 715*38fd1498Szrj * 716*38fd1498Szrj * This function erases an element, pointed to by the given iterator, 717*38fd1498Szrj * from a %multimap. Note that this function only erases the element, 718*38fd1498Szrj * and that if the element is itself a pointer, the pointed-to memory is 719*38fd1498Szrj * not touched in any way. Managing the pointer is the user's 720*38fd1498Szrj * responsibility. 721*38fd1498Szrj */ 722*38fd1498Szrj void 723*38fd1498Szrj erase(iterator __position) 724*38fd1498Szrj { _M_t.erase(__position); } 725*38fd1498Szrj #endif 726*38fd1498Szrj 727*38fd1498Szrj /** 728*38fd1498Szrj * @brief Erases elements according to the provided key. 729*38fd1498Szrj * @param __x Key of element to be erased. 730*38fd1498Szrj * @return The number of elements erased. 731*38fd1498Szrj * 732*38fd1498Szrj * This function erases all elements located by the given key from a 733*38fd1498Szrj * %multimap. 734*38fd1498Szrj * Note that this function only erases the element, and that if 735*38fd1498Szrj * the element is itself a pointer, the pointed-to memory is not touched 736*38fd1498Szrj * in any way. Managing the pointer is the user's responsibility. 737*38fd1498Szrj */ 738*38fd1498Szrj size_type 739*38fd1498Szrj erase(const key_type& __x) 740*38fd1498Szrj { return _M_t.erase(__x); } 741*38fd1498Szrj 742*38fd1498Szrj #if __cplusplus >= 201103L 743*38fd1498Szrj // _GLIBCXX_RESOLVE_LIB_DEFECTS 744*38fd1498Szrj // DR 130. Associative erase should return an iterator. 745*38fd1498Szrj /** 746*38fd1498Szrj * @brief Erases a [first,last) range of elements from a %multimap. 747*38fd1498Szrj * @param __first Iterator pointing to the start of the range to be 748*38fd1498Szrj * erased. 749*38fd1498Szrj * @param __last Iterator pointing to the end of the range to be 750*38fd1498Szrj * erased . 751*38fd1498Szrj * @return The iterator @a __last. 752*38fd1498Szrj * 753*38fd1498Szrj * This function erases a sequence of elements from a %multimap. 754*38fd1498Szrj * Note that this function only erases the elements, and that if 755*38fd1498Szrj * the elements themselves are pointers, the pointed-to memory is not 756*38fd1498Szrj * touched in any way. Managing the pointer is the user's 757*38fd1498Szrj * responsibility. 758*38fd1498Szrj */ 759*38fd1498Szrj iterator 760*38fd1498Szrj erase(const_iterator __first, const_iterator __last) 761*38fd1498Szrj { return _M_t.erase(__first, __last); } 762*38fd1498Szrj #else 763*38fd1498Szrj // _GLIBCXX_RESOLVE_LIB_DEFECTS 764*38fd1498Szrj // DR 130. Associative erase should return an iterator. 765*38fd1498Szrj /** 766*38fd1498Szrj * @brief Erases a [first,last) range of elements from a %multimap. 767*38fd1498Szrj * @param __first Iterator pointing to the start of the range to be 768*38fd1498Szrj * erased. 769*38fd1498Szrj * @param __last Iterator pointing to the end of the range to 770*38fd1498Szrj * be erased. 771*38fd1498Szrj * 772*38fd1498Szrj * This function erases a sequence of elements from a %multimap. 773*38fd1498Szrj * Note that this function only erases the elements, and that if 774*38fd1498Szrj * the elements themselves are pointers, the pointed-to memory is not 775*38fd1498Szrj * touched in any way. Managing the pointer is the user's 776*38fd1498Szrj * responsibility. 777*38fd1498Szrj */ 778*38fd1498Szrj void 779*38fd1498Szrj erase(iterator __first, iterator __last) 780*38fd1498Szrj { _M_t.erase(__first, __last); } 781*38fd1498Szrj #endif 782*38fd1498Szrj 783*38fd1498Szrj /** 784*38fd1498Szrj * @brief Swaps data with another %multimap. 785*38fd1498Szrj * @param __x A %multimap of the same element and allocator types. 786*38fd1498Szrj * 787*38fd1498Szrj * This exchanges the elements between two multimaps in constant time. 788*38fd1498Szrj * (It is only swapping a pointer, an integer, and an instance of 789*38fd1498Szrj * the @c Compare type (which itself is often stateless and empty), so it 790*38fd1498Szrj * should be quite fast.) 791*38fd1498Szrj * Note that the global std::swap() function is specialized such that 792*38fd1498Szrj * std::swap(m1,m2) will feed to this function. 793*38fd1498Szrj * 794*38fd1498Szrj * Whether the allocators are swapped depends on the allocator traits. 795*38fd1498Szrj */ 796*38fd1498Szrj void 797*38fd1498Szrj swap(multimap& __x) 798*38fd1498Szrj _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value) 799*38fd1498Szrj { _M_t.swap(__x._M_t); } 800*38fd1498Szrj 801*38fd1498Szrj /** 802*38fd1498Szrj * Erases all elements in a %multimap. Note that this function only 803*38fd1498Szrj * erases the elements, and that if the elements themselves are pointers, 804*38fd1498Szrj * the pointed-to memory is not touched in any way. Managing the pointer 805*38fd1498Szrj * is the user's responsibility. 806*38fd1498Szrj */ 807*38fd1498Szrj void 808*38fd1498Szrj clear() _GLIBCXX_NOEXCEPT 809*38fd1498Szrj { _M_t.clear(); } 810*38fd1498Szrj 811*38fd1498Szrj // observers 812*38fd1498Szrj /** 813*38fd1498Szrj * Returns the key comparison object out of which the %multimap 814*38fd1498Szrj * was constructed. 815*38fd1498Szrj */ 816*38fd1498Szrj key_compare 817*38fd1498Szrj key_comp() const 818*38fd1498Szrj { return _M_t.key_comp(); } 819*38fd1498Szrj 820*38fd1498Szrj /** 821*38fd1498Szrj * Returns a value comparison object, built from the key comparison 822*38fd1498Szrj * object out of which the %multimap was constructed. 823*38fd1498Szrj */ 824*38fd1498Szrj value_compare 825*38fd1498Szrj value_comp() const 826*38fd1498Szrj { return value_compare(_M_t.key_comp()); } 827*38fd1498Szrj 828*38fd1498Szrj // multimap operations 829*38fd1498Szrj 830*38fd1498Szrj //@{ 831*38fd1498Szrj /** 832*38fd1498Szrj * @brief Tries to locate an element in a %multimap. 833*38fd1498Szrj * @param __x Key of (key, value) pair to be located. 834*38fd1498Szrj * @return Iterator pointing to sought-after element, 835*38fd1498Szrj * or end() if not found. 836*38fd1498Szrj * 837*38fd1498Szrj * This function takes a key and tries to locate the element with which 838*38fd1498Szrj * the key matches. If successful the function returns an iterator 839*38fd1498Szrj * pointing to the sought after %pair. If unsuccessful it returns the 840*38fd1498Szrj * past-the-end ( @c end() ) iterator. 841*38fd1498Szrj */ 842*38fd1498Szrj iterator 843*38fd1498Szrj find(const key_type& __x) 844*38fd1498Szrj { return _M_t.find(__x); } 845*38fd1498Szrj 846*38fd1498Szrj #if __cplusplus > 201103L 847*38fd1498Szrj template<typename _Kt> 848*38fd1498Szrj auto 849*38fd1498Szrj find(const _Kt& __x) -> decltype(_M_t._M_find_tr(__x)) 850*38fd1498Szrj { return _M_t._M_find_tr(__x); } 851*38fd1498Szrj #endif 852*38fd1498Szrj //@} 853*38fd1498Szrj 854*38fd1498Szrj //@{ 855*38fd1498Szrj /** 856*38fd1498Szrj * @brief Tries to locate an element in a %multimap. 857*38fd1498Szrj * @param __x Key of (key, value) pair to be located. 858*38fd1498Szrj * @return Read-only (constant) iterator pointing to sought-after 859*38fd1498Szrj * element, or end() if not found. 860*38fd1498Szrj * 861*38fd1498Szrj * This function takes a key and tries to locate the element with which 862*38fd1498Szrj * the key matches. If successful the function returns a constant 863*38fd1498Szrj * iterator pointing to the sought after %pair. If unsuccessful it 864*38fd1498Szrj * returns the past-the-end ( @c end() ) iterator. 865*38fd1498Szrj */ 866*38fd1498Szrj const_iterator 867*38fd1498Szrj find(const key_type& __x) const 868*38fd1498Szrj { return _M_t.find(__x); } 869*38fd1498Szrj 870*38fd1498Szrj #if __cplusplus > 201103L 871*38fd1498Szrj template<typename _Kt> 872*38fd1498Szrj auto 873*38fd1498Szrj find(const _Kt& __x) const -> decltype(_M_t._M_find_tr(__x)) 874*38fd1498Szrj { return _M_t._M_find_tr(__x); } 875*38fd1498Szrj #endif 876*38fd1498Szrj //@} 877*38fd1498Szrj 878*38fd1498Szrj //@{ 879*38fd1498Szrj /** 880*38fd1498Szrj * @brief Finds the number of elements with given key. 881*38fd1498Szrj * @param __x Key of (key, value) pairs to be located. 882*38fd1498Szrj * @return Number of elements with specified key. 883*38fd1498Szrj */ 884*38fd1498Szrj size_type 885*38fd1498Szrj count(const key_type& __x) const 886*38fd1498Szrj { return _M_t.count(__x); } 887*38fd1498Szrj 888*38fd1498Szrj #if __cplusplus > 201103L 889*38fd1498Szrj template<typename _Kt> 890*38fd1498Szrj auto 891*38fd1498Szrj count(const _Kt& __x) const -> decltype(_M_t._M_count_tr(__x)) 892*38fd1498Szrj { return _M_t._M_count_tr(__x); } 893*38fd1498Szrj #endif 894*38fd1498Szrj //@} 895*38fd1498Szrj 896*38fd1498Szrj //@{ 897*38fd1498Szrj /** 898*38fd1498Szrj * @brief Finds the beginning of a subsequence matching given key. 899*38fd1498Szrj * @param __x Key of (key, value) pair to be located. 900*38fd1498Szrj * @return Iterator pointing to first element equal to or greater 901*38fd1498Szrj * than key, or end(). 902*38fd1498Szrj * 903*38fd1498Szrj * This function returns the first element of a subsequence of elements 904*38fd1498Szrj * that matches the given key. If unsuccessful it returns an iterator 905*38fd1498Szrj * pointing to the first element that has a greater value than given key 906*38fd1498Szrj * or end() if no such element exists. 907*38fd1498Szrj */ 908*38fd1498Szrj iterator 909*38fd1498Szrj lower_bound(const key_type& __x) 910*38fd1498Szrj { return _M_t.lower_bound(__x); } 911*38fd1498Szrj 912*38fd1498Szrj #if __cplusplus > 201103L 913*38fd1498Szrj template<typename _Kt> 914*38fd1498Szrj auto 915*38fd1498Szrj lower_bound(const _Kt& __x) 916*38fd1498Szrj -> decltype(iterator(_M_t._M_lower_bound_tr(__x))) 917*38fd1498Szrj { return iterator(_M_t._M_lower_bound_tr(__x)); } 918*38fd1498Szrj #endif 919*38fd1498Szrj //@} 920*38fd1498Szrj 921*38fd1498Szrj //@{ 922*38fd1498Szrj /** 923*38fd1498Szrj * @brief Finds the beginning of a subsequence matching given key. 924*38fd1498Szrj * @param __x Key of (key, value) pair to be located. 925*38fd1498Szrj * @return Read-only (constant) iterator pointing to first element 926*38fd1498Szrj * equal to or greater than key, or end(). 927*38fd1498Szrj * 928*38fd1498Szrj * This function returns the first element of a subsequence of 929*38fd1498Szrj * elements that matches the given key. If unsuccessful the 930*38fd1498Szrj * iterator will point to the next greatest element or, if no 931*38fd1498Szrj * such greater element exists, to end(). 932*38fd1498Szrj */ 933*38fd1498Szrj const_iterator 934*38fd1498Szrj lower_bound(const key_type& __x) const 935*38fd1498Szrj { return _M_t.lower_bound(__x); } 936*38fd1498Szrj 937*38fd1498Szrj #if __cplusplus > 201103L 938*38fd1498Szrj template<typename _Kt> 939*38fd1498Szrj auto 940*38fd1498Szrj lower_bound(const _Kt& __x) const 941*38fd1498Szrj -> decltype(const_iterator(_M_t._M_lower_bound_tr(__x))) 942*38fd1498Szrj { return const_iterator(_M_t._M_lower_bound_tr(__x)); } 943*38fd1498Szrj #endif 944*38fd1498Szrj //@} 945*38fd1498Szrj 946*38fd1498Szrj //@{ 947*38fd1498Szrj /** 948*38fd1498Szrj * @brief Finds the end of a subsequence matching given key. 949*38fd1498Szrj * @param __x Key of (key, value) pair to be located. 950*38fd1498Szrj * @return Iterator pointing to the first element 951*38fd1498Szrj * greater than key, or end(). 952*38fd1498Szrj */ 953*38fd1498Szrj iterator 954*38fd1498Szrj upper_bound(const key_type& __x) 955*38fd1498Szrj { return _M_t.upper_bound(__x); } 956*38fd1498Szrj 957*38fd1498Szrj #if __cplusplus > 201103L 958*38fd1498Szrj template<typename _Kt> 959*38fd1498Szrj auto 960*38fd1498Szrj upper_bound(const _Kt& __x) 961*38fd1498Szrj -> decltype(iterator(_M_t._M_upper_bound_tr(__x))) 962*38fd1498Szrj { return iterator(_M_t._M_upper_bound_tr(__x)); } 963*38fd1498Szrj #endif 964*38fd1498Szrj //@} 965*38fd1498Szrj 966*38fd1498Szrj //@{ 967*38fd1498Szrj /** 968*38fd1498Szrj * @brief Finds the end of a subsequence matching given key. 969*38fd1498Szrj * @param __x Key of (key, value) pair to be located. 970*38fd1498Szrj * @return Read-only (constant) iterator pointing to first iterator 971*38fd1498Szrj * greater than key, or end(). 972*38fd1498Szrj */ 973*38fd1498Szrj const_iterator 974*38fd1498Szrj upper_bound(const key_type& __x) const 975*38fd1498Szrj { return _M_t.upper_bound(__x); } 976*38fd1498Szrj 977*38fd1498Szrj #if __cplusplus > 201103L 978*38fd1498Szrj template<typename _Kt> 979*38fd1498Szrj auto 980*38fd1498Szrj upper_bound(const _Kt& __x) const 981*38fd1498Szrj -> decltype(const_iterator(_M_t._M_upper_bound_tr(__x))) 982*38fd1498Szrj { return const_iterator(_M_t._M_upper_bound_tr(__x)); } 983*38fd1498Szrj #endif 984*38fd1498Szrj //@} 985*38fd1498Szrj 986*38fd1498Szrj //@{ 987*38fd1498Szrj /** 988*38fd1498Szrj * @brief Finds a subsequence matching given key. 989*38fd1498Szrj * @param __x Key of (key, value) pairs to be located. 990*38fd1498Szrj * @return Pair of iterators that possibly points to the subsequence 991*38fd1498Szrj * matching given key. 992*38fd1498Szrj * 993*38fd1498Szrj * This function is equivalent to 994*38fd1498Szrj * @code 995*38fd1498Szrj * std::make_pair(c.lower_bound(val), 996*38fd1498Szrj * c.upper_bound(val)) 997*38fd1498Szrj * @endcode 998*38fd1498Szrj * (but is faster than making the calls separately). 999*38fd1498Szrj */ 1000*38fd1498Szrj std::pair<iterator, iterator> 1001*38fd1498Szrj equal_range(const key_type& __x) 1002*38fd1498Szrj { return _M_t.equal_range(__x); } 1003*38fd1498Szrj 1004*38fd1498Szrj #if __cplusplus > 201103L 1005*38fd1498Szrj template<typename _Kt> 1006*38fd1498Szrj auto 1007*38fd1498Szrj equal_range(const _Kt& __x) 1008*38fd1498Szrj -> decltype(pair<iterator, iterator>(_M_t._M_equal_range_tr(__x))) 1009*38fd1498Szrj { return pair<iterator, iterator>(_M_t._M_equal_range_tr(__x)); } 1010*38fd1498Szrj #endif 1011*38fd1498Szrj //@} 1012*38fd1498Szrj 1013*38fd1498Szrj //@{ 1014*38fd1498Szrj /** 1015*38fd1498Szrj * @brief Finds a subsequence matching given key. 1016*38fd1498Szrj * @param __x Key of (key, value) pairs to be located. 1017*38fd1498Szrj * @return Pair of read-only (constant) iterators that possibly points 1018*38fd1498Szrj * to the subsequence matching given key. 1019*38fd1498Szrj * 1020*38fd1498Szrj * This function is equivalent to 1021*38fd1498Szrj * @code 1022*38fd1498Szrj * std::make_pair(c.lower_bound(val), 1023*38fd1498Szrj * c.upper_bound(val)) 1024*38fd1498Szrj * @endcode 1025*38fd1498Szrj * (but is faster than making the calls separately). 1026*38fd1498Szrj */ 1027*38fd1498Szrj std::pair<const_iterator, const_iterator> 1028*38fd1498Szrj equal_range(const key_type& __x) const 1029*38fd1498Szrj { return _M_t.equal_range(__x); } 1030*38fd1498Szrj 1031*38fd1498Szrj #if __cplusplus > 201103L 1032*38fd1498Szrj template<typename _Kt> 1033*38fd1498Szrj auto 1034*38fd1498Szrj equal_range(const _Kt& __x) const 1035*38fd1498Szrj -> decltype(pair<const_iterator, const_iterator>( 1036*38fd1498Szrj _M_t._M_equal_range_tr(__x))) 1037*38fd1498Szrj { 1038*38fd1498Szrj return pair<const_iterator, const_iterator>( 1039*38fd1498Szrj _M_t._M_equal_range_tr(__x)); 1040*38fd1498Szrj } 1041*38fd1498Szrj #endif 1042*38fd1498Szrj //@} 1043*38fd1498Szrj 1044*38fd1498Szrj template<typename _K1, typename _T1, typename _C1, typename _A1> 1045*38fd1498Szrj friend bool 1046*38fd1498Szrj operator==(const multimap<_K1, _T1, _C1, _A1>&, 1047*38fd1498Szrj const multimap<_K1, _T1, _C1, _A1>&); 1048*38fd1498Szrj 1049*38fd1498Szrj template<typename _K1, typename _T1, typename _C1, typename _A1> 1050*38fd1498Szrj friend bool 1051*38fd1498Szrj operator<(const multimap<_K1, _T1, _C1, _A1>&, 1052*38fd1498Szrj const multimap<_K1, _T1, _C1, _A1>&); 1053*38fd1498Szrj }; 1054*38fd1498Szrj 1055*38fd1498Szrj #if __cpp_deduction_guides >= 201606 1056*38fd1498Szrj 1057*38fd1498Szrj template<typename _InputIterator, 1058*38fd1498Szrj typename _Compare = less<__iter_key_t<_InputIterator>>, 1059*38fd1498Szrj typename _Allocator = allocator<__iter_to_alloc_t<_InputIterator>>, 1060*38fd1498Szrj typename = _RequireInputIter<_InputIterator>, 1061*38fd1498Szrj typename = _RequireAllocator<_Allocator>> 1062*38fd1498Szrj multimap(_InputIterator, _InputIterator, 1063*38fd1498Szrj _Compare = _Compare(), _Allocator = _Allocator()) 1064*38fd1498Szrj -> multimap<__iter_key_t<_InputIterator>, __iter_val_t<_InputIterator>, 1065*38fd1498Szrj _Compare, _Allocator>; 1066*38fd1498Szrj 1067*38fd1498Szrj template<typename _Key, typename _Tp, typename _Compare = less<_Key>, 1068*38fd1498Szrj typename _Allocator = allocator<pair<const _Key, _Tp>>, 1069*38fd1498Szrj typename = _RequireAllocator<_Allocator>> 1070*38fd1498Szrj multimap(initializer_list<pair<_Key, _Tp>>, 1071*38fd1498Szrj _Compare = _Compare(), _Allocator = _Allocator()) 1072*38fd1498Szrj -> multimap<_Key, _Tp, _Compare, _Allocator>; 1073*38fd1498Szrj 1074*38fd1498Szrj template<typename _InputIterator, typename _Allocator, 1075*38fd1498Szrj typename = _RequireInputIter<_InputIterator>, 1076*38fd1498Szrj typename = _RequireAllocator<_Allocator>> 1077*38fd1498Szrj multimap(_InputIterator, _InputIterator, _Allocator) 1078*38fd1498Szrj -> multimap<__iter_key_t<_InputIterator>, __iter_val_t<_InputIterator>, 1079*38fd1498Szrj less<__iter_key_t<_InputIterator>>, _Allocator>; 1080*38fd1498Szrj 1081*38fd1498Szrj template<typename _Key, typename _Tp, typename _Allocator, 1082*38fd1498Szrj typename = _RequireAllocator<_Allocator>> 1083*38fd1498Szrj multimap(initializer_list<pair<_Key, _Tp>>, _Allocator) 1084*38fd1498Szrj -> multimap<_Key, _Tp, less<_Key>, _Allocator>; 1085*38fd1498Szrj 1086*38fd1498Szrj #endif 1087*38fd1498Szrj 1088*38fd1498Szrj /** 1089*38fd1498Szrj * @brief Multimap equality comparison. 1090*38fd1498Szrj * @param __x A %multimap. 1091*38fd1498Szrj * @param __y A %multimap of the same type as @a __x. 1092*38fd1498Szrj * @return True iff the size and elements of the maps are equal. 1093*38fd1498Szrj * 1094*38fd1498Szrj * This is an equivalence relation. It is linear in the size of the 1095*38fd1498Szrj * multimaps. Multimaps are considered equivalent if their sizes are equal, 1096*38fd1498Szrj * and if corresponding elements compare equal. 1097*38fd1498Szrj */ 1098*38fd1498Szrj template<typename _Key, typename _Tp, typename _Compare, typename _Alloc> 1099*38fd1498Szrj inline bool 1100*38fd1498Szrj operator==(const multimap<_Key, _Tp, _Compare, _Alloc>& __x, 1101*38fd1498Szrj const multimap<_Key, _Tp, _Compare, _Alloc>& __y) 1102*38fd1498Szrj { return __x._M_t == __y._M_t; } 1103*38fd1498Szrj 1104*38fd1498Szrj /** 1105*38fd1498Szrj * @brief Multimap ordering relation. 1106*38fd1498Szrj * @param __x A %multimap. 1107*38fd1498Szrj * @param __y A %multimap of the same type as @a __x. 1108*38fd1498Szrj * @return True iff @a x is lexicographically less than @a y. 1109*38fd1498Szrj * 1110*38fd1498Szrj * This is a total ordering relation. It is linear in the size of the 1111*38fd1498Szrj * multimaps. The elements must be comparable with @c <. 1112*38fd1498Szrj * 1113*38fd1498Szrj * See std::lexicographical_compare() for how the determination is made. 1114*38fd1498Szrj */ 1115*38fd1498Szrj template<typename _Key, typename _Tp, typename _Compare, typename _Alloc> 1116*38fd1498Szrj inline bool 1117*38fd1498Szrj operator<(const multimap<_Key, _Tp, _Compare, _Alloc>& __x, 1118*38fd1498Szrj const multimap<_Key, _Tp, _Compare, _Alloc>& __y) 1119*38fd1498Szrj { return __x._M_t < __y._M_t; } 1120*38fd1498Szrj 1121*38fd1498Szrj /// Based on operator== 1122*38fd1498Szrj template<typename _Key, typename _Tp, typename _Compare, typename _Alloc> 1123*38fd1498Szrj inline bool 1124*38fd1498Szrj operator!=(const multimap<_Key, _Tp, _Compare, _Alloc>& __x, 1125*38fd1498Szrj const multimap<_Key, _Tp, _Compare, _Alloc>& __y) 1126*38fd1498Szrj { return !(__x == __y); } 1127*38fd1498Szrj 1128*38fd1498Szrj /// Based on operator< 1129*38fd1498Szrj template<typename _Key, typename _Tp, typename _Compare, typename _Alloc> 1130*38fd1498Szrj inline bool 1131*38fd1498Szrj operator>(const multimap<_Key, _Tp, _Compare, _Alloc>& __x, 1132*38fd1498Szrj const multimap<_Key, _Tp, _Compare, _Alloc>& __y) 1133*38fd1498Szrj { return __y < __x; } 1134*38fd1498Szrj 1135*38fd1498Szrj /// Based on operator< 1136*38fd1498Szrj template<typename _Key, typename _Tp, typename _Compare, typename _Alloc> 1137*38fd1498Szrj inline bool 1138*38fd1498Szrj operator<=(const multimap<_Key, _Tp, _Compare, _Alloc>& __x, 1139*38fd1498Szrj const multimap<_Key, _Tp, _Compare, _Alloc>& __y) 1140*38fd1498Szrj { return !(__y < __x); } 1141*38fd1498Szrj 1142*38fd1498Szrj /// Based on operator< 1143*38fd1498Szrj template<typename _Key, typename _Tp, typename _Compare, typename _Alloc> 1144*38fd1498Szrj inline bool 1145*38fd1498Szrj operator>=(const multimap<_Key, _Tp, _Compare, _Alloc>& __x, 1146*38fd1498Szrj const multimap<_Key, _Tp, _Compare, _Alloc>& __y) 1147*38fd1498Szrj { return !(__x < __y); } 1148*38fd1498Szrj 1149*38fd1498Szrj /// See std::multimap::swap(). 1150*38fd1498Szrj template<typename _Key, typename _Tp, typename _Compare, typename _Alloc> 1151*38fd1498Szrj inline void 1152*38fd1498Szrj swap(multimap<_Key, _Tp, _Compare, _Alloc>& __x, 1153*38fd1498Szrj multimap<_Key, _Tp, _Compare, _Alloc>& __y) 1154*38fd1498Szrj _GLIBCXX_NOEXCEPT_IF(noexcept(__x.swap(__y))) 1155*38fd1498Szrj { __x.swap(__y); } 1156*38fd1498Szrj 1157*38fd1498Szrj _GLIBCXX_END_NAMESPACE_CONTAINER 1158*38fd1498Szrj 1159*38fd1498Szrj #if __cplusplus > 201402L 1160*38fd1498Szrj // Allow std::multimap access to internals of compatible maps. 1161*38fd1498Szrj template<typename _Key, typename _Val, typename _Cmp1, typename _Alloc, 1162*38fd1498Szrj typename _Cmp2> 1163*38fd1498Szrj struct 1164*38fd1498Szrj _Rb_tree_merge_helper<_GLIBCXX_STD_C::multimap<_Key, _Val, _Cmp1, _Alloc>, 1165*38fd1498Szrj _Cmp2> 1166*38fd1498Szrj { 1167*38fd1498Szrj private: 1168*38fd1498Szrj friend class _GLIBCXX_STD_C::multimap<_Key, _Val, _Cmp1, _Alloc>; 1169*38fd1498Szrj 1170*38fd1498Szrj static auto& 1171*38fd1498Szrj _S_get_tree(_GLIBCXX_STD_C::map<_Key, _Val, _Cmp2, _Alloc>& __map) 1172*38fd1498Szrj { return __map._M_t; } 1173*38fd1498Szrj 1174*38fd1498Szrj static auto& 1175*38fd1498Szrj _S_get_tree(_GLIBCXX_STD_C::multimap<_Key, _Val, _Cmp2, _Alloc>& __map) 1176*38fd1498Szrj { return __map._M_t; } 1177*38fd1498Szrj }; 1178*38fd1498Szrj #endif // C++17 1179*38fd1498Szrj 1180*38fd1498Szrj _GLIBCXX_END_NAMESPACE_VERSION 1181*38fd1498Szrj } // namespace std 1182*38fd1498Szrj 1183*38fd1498Szrj #endif /* _STL_MULTIMAP_H */ 1184