110d565efSmrg // Multimap implementation -*- C++ -*-
210d565efSmrg 
3*ec02198aSmrg // Copyright (C) 2001-2020 Free Software Foundation, Inc.
410d565efSmrg //
510d565efSmrg // This file is part of the GNU ISO C++ Library.  This library is free
610d565efSmrg // software; you can redistribute it and/or modify it under the
710d565efSmrg // terms of the GNU General Public License as published by the
810d565efSmrg // Free Software Foundation; either version 3, or (at your option)
910d565efSmrg // any later version.
1010d565efSmrg 
1110d565efSmrg // This library is distributed in the hope that it will be useful,
1210d565efSmrg // but WITHOUT ANY WARRANTY; without even the implied warranty of
1310d565efSmrg // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1410d565efSmrg // GNU General Public License for more details.
1510d565efSmrg 
1610d565efSmrg // Under Section 7 of GPL version 3, you are granted additional
1710d565efSmrg // permissions described in the GCC Runtime Library Exception, version
1810d565efSmrg // 3.1, as published by the Free Software Foundation.
1910d565efSmrg 
2010d565efSmrg // You should have received a copy of the GNU General Public License and
2110d565efSmrg // a copy of the GCC Runtime Library Exception along with this program;
2210d565efSmrg // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
2310d565efSmrg // <http://www.gnu.org/licenses/>.
2410d565efSmrg 
2510d565efSmrg /*
2610d565efSmrg  *
2710d565efSmrg  * Copyright (c) 1994
2810d565efSmrg  * Hewlett-Packard Company
2910d565efSmrg  *
3010d565efSmrg  * Permission to use, copy, modify, distribute and sell this software
3110d565efSmrg  * and its documentation for any purpose is hereby granted without fee,
3210d565efSmrg  * provided that the above copyright notice appear in all copies and
3310d565efSmrg  * that both that copyright notice and this permission notice appear
3410d565efSmrg  * in supporting documentation.  Hewlett-Packard Company makes no
3510d565efSmrg  * representations about the suitability of this software for any
3610d565efSmrg  * purpose.  It is provided "as is" without express or implied warranty.
3710d565efSmrg  *
3810d565efSmrg  *
3910d565efSmrg  * Copyright (c) 1996,1997
4010d565efSmrg  * Silicon Graphics Computer Systems, Inc.
4110d565efSmrg  *
4210d565efSmrg  * Permission to use, copy, modify, distribute and sell this software
4310d565efSmrg  * and its documentation for any purpose is hereby granted without fee,
4410d565efSmrg  * provided that the above copyright notice appear in all copies and
4510d565efSmrg  * that both that copyright notice and this permission notice appear
4610d565efSmrg  * in supporting documentation.  Silicon Graphics makes no
4710d565efSmrg  * representations about the suitability of this software for any
4810d565efSmrg  * purpose.  It is provided "as is" without express or implied warranty.
4910d565efSmrg  */
5010d565efSmrg 
5110d565efSmrg /** @file bits/stl_multimap.h
5210d565efSmrg  *  This is an internal header file, included by other library headers.
5310d565efSmrg  *  Do not attempt to use it directly. @headername{map}
5410d565efSmrg  */
5510d565efSmrg 
5610d565efSmrg #ifndef _STL_MULTIMAP_H
5710d565efSmrg #define _STL_MULTIMAP_H 1
5810d565efSmrg 
5910d565efSmrg #include <bits/concept_check.h>
6010d565efSmrg #if __cplusplus >= 201103L
6110d565efSmrg #include <initializer_list>
6210d565efSmrg #endif
6310d565efSmrg 
_GLIBCXX_VISIBILITY(default)6410d565efSmrg namespace std _GLIBCXX_VISIBILITY(default)
6510d565efSmrg {
66c7a68eb7Smrg _GLIBCXX_BEGIN_NAMESPACE_VERSION
6710d565efSmrg _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
6810d565efSmrg 
6910d565efSmrg   template <typename _Key, typename _Tp, typename _Compare, typename _Alloc>
7010d565efSmrg     class map;
7110d565efSmrg 
7210d565efSmrg   /**
7310d565efSmrg    *  @brief A standard container made up of (key,value) pairs, which can be
7410d565efSmrg    *  retrieved based on a key, in logarithmic time.
7510d565efSmrg    *
7610d565efSmrg    *  @ingroup associative_containers
7710d565efSmrg    *
7810d565efSmrg    *  @tparam _Key  Type of key objects.
7910d565efSmrg    *  @tparam  _Tp  Type of mapped objects.
8010d565efSmrg    *  @tparam _Compare  Comparison function object type, defaults to less<_Key>.
8110d565efSmrg    *  @tparam _Alloc  Allocator type, defaults to
8210d565efSmrg    *                  allocator<pair<const _Key, _Tp>.
8310d565efSmrg    *
8410d565efSmrg    *  Meets the requirements of a <a href="tables.html#65">container</a>, a
8510d565efSmrg    *  <a href="tables.html#66">reversible container</a>, and an
8610d565efSmrg    *  <a href="tables.html#69">associative container</a> (using equivalent
8710d565efSmrg    *  keys).  For a @c multimap<Key,T> the key_type is Key, the mapped_type
8810d565efSmrg    *  is T, and the value_type is std::pair<const Key,T>.
8910d565efSmrg    *
9010d565efSmrg    *  Multimaps support bidirectional iterators.
9110d565efSmrg    *
9210d565efSmrg    *  The private tree data is declared exactly the same way for map and
9310d565efSmrg    *  multimap; the distinction is made entirely in how the tree functions are
9410d565efSmrg    *  called (*_unique versus *_equal, same as the standard).
9510d565efSmrg   */
9610d565efSmrg   template <typename _Key, typename _Tp,
9710d565efSmrg 	    typename _Compare = std::less<_Key>,
9810d565efSmrg 	    typename _Alloc = std::allocator<std::pair<const _Key, _Tp> > >
9910d565efSmrg     class multimap
10010d565efSmrg     {
10110d565efSmrg     public:
10210d565efSmrg       typedef _Key					key_type;
10310d565efSmrg       typedef _Tp					mapped_type;
10410d565efSmrg       typedef std::pair<const _Key, _Tp>		value_type;
10510d565efSmrg       typedef _Compare					key_compare;
10610d565efSmrg       typedef _Alloc					allocator_type;
10710d565efSmrg 
10810d565efSmrg     private:
10910d565efSmrg #ifdef _GLIBCXX_CONCEPT_CHECKS
11010d565efSmrg       // concept requirements
11110d565efSmrg       typedef typename _Alloc::value_type		_Alloc_value_type;
11210d565efSmrg # if __cplusplus < 201103L
11310d565efSmrg       __glibcxx_class_requires(_Tp, _SGIAssignableConcept)
11410d565efSmrg # endif
11510d565efSmrg       __glibcxx_class_requires4(_Compare, bool, _Key, _Key,
11610d565efSmrg 				_BinaryFunctionConcept)
11710d565efSmrg       __glibcxx_class_requires2(value_type, _Alloc_value_type, _SameTypeConcept)
11810d565efSmrg #endif
11910d565efSmrg 
120*ec02198aSmrg #if __cplusplus >= 201103L
121*ec02198aSmrg #if __cplusplus > 201703L || defined __STRICT_ANSI__
122c7a68eb7Smrg       static_assert(is_same<typename _Alloc::value_type, value_type>::value,
123c7a68eb7Smrg 	  "std::multimap must have the same value_type as its allocator");
124c7a68eb7Smrg #endif
125*ec02198aSmrg #endif
126c7a68eb7Smrg 
12710d565efSmrg     public:
12810d565efSmrg       class value_compare
12910d565efSmrg       : public std::binary_function<value_type, value_type, bool>
13010d565efSmrg       {
13110d565efSmrg 	friend class multimap<_Key, _Tp, _Compare, _Alloc>;
13210d565efSmrg       protected:
13310d565efSmrg 	_Compare comp;
13410d565efSmrg 
13510d565efSmrg 	value_compare(_Compare __c)
13610d565efSmrg 	: comp(__c) { }
13710d565efSmrg 
13810d565efSmrg       public:
13910d565efSmrg 	bool operator()(const value_type& __x, const value_type& __y) const
14010d565efSmrg 	{ return comp(__x.first, __y.first); }
14110d565efSmrg       };
14210d565efSmrg 
14310d565efSmrg     private:
14410d565efSmrg       /// This turns a red-black tree into a [multi]map.
14510d565efSmrg       typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template
14610d565efSmrg 	rebind<value_type>::other _Pair_alloc_type;
14710d565efSmrg 
14810d565efSmrg       typedef _Rb_tree<key_type, value_type, _Select1st<value_type>,
14910d565efSmrg 		       key_compare, _Pair_alloc_type> _Rep_type;
15010d565efSmrg       /// The actual tree structure.
15110d565efSmrg       _Rep_type _M_t;
15210d565efSmrg 
15310d565efSmrg       typedef __gnu_cxx::__alloc_traits<_Pair_alloc_type> _Alloc_traits;
15410d565efSmrg 
15510d565efSmrg     public:
15610d565efSmrg       // many of these are specified differently in ISO, but the following are
15710d565efSmrg       // "functionally equivalent"
15810d565efSmrg       typedef typename _Alloc_traits::pointer		 pointer;
15910d565efSmrg       typedef typename _Alloc_traits::const_pointer	 const_pointer;
16010d565efSmrg       typedef typename _Alloc_traits::reference		 reference;
16110d565efSmrg       typedef typename _Alloc_traits::const_reference	 const_reference;
16210d565efSmrg       typedef typename _Rep_type::iterator		 iterator;
16310d565efSmrg       typedef typename _Rep_type::const_iterator	 const_iterator;
16410d565efSmrg       typedef typename _Rep_type::size_type		 size_type;
16510d565efSmrg       typedef typename _Rep_type::difference_type	 difference_type;
16610d565efSmrg       typedef typename _Rep_type::reverse_iterator	 reverse_iterator;
16710d565efSmrg       typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
16810d565efSmrg 
16910d565efSmrg #if __cplusplus > 201402L
17010d565efSmrg       using node_type = typename _Rep_type::node_type;
17110d565efSmrg #endif
17210d565efSmrg 
17310d565efSmrg       // [23.3.2] construct/copy/destroy
17410d565efSmrg       // (get_allocator() is also listed in this section)
17510d565efSmrg 
17610d565efSmrg       /**
17710d565efSmrg        *  @brief  Default constructor creates no elements.
17810d565efSmrg        */
17910d565efSmrg #if __cplusplus < 201103L
18010d565efSmrg       multimap() : _M_t() { }
18110d565efSmrg #else
18210d565efSmrg       multimap() = default;
18310d565efSmrg #endif
18410d565efSmrg 
18510d565efSmrg       /**
18610d565efSmrg        *  @brief  Creates a %multimap with no elements.
18710d565efSmrg        *  @param  __comp  A comparison object.
18810d565efSmrg        *  @param  __a  An allocator object.
18910d565efSmrg        */
19010d565efSmrg       explicit
19110d565efSmrg       multimap(const _Compare& __comp,
19210d565efSmrg 	       const allocator_type& __a = allocator_type())
19310d565efSmrg       : _M_t(__comp, _Pair_alloc_type(__a)) { }
19410d565efSmrg 
19510d565efSmrg       /**
19610d565efSmrg        *  @brief  %Multimap copy constructor.
19710d565efSmrg        *
19810d565efSmrg        *  Whether the allocator is copied depends on the allocator traits.
19910d565efSmrg        */
20010d565efSmrg #if __cplusplus < 201103L
20110d565efSmrg       multimap(const multimap& __x)
20210d565efSmrg       : _M_t(__x._M_t) { }
20310d565efSmrg #else
20410d565efSmrg       multimap(const multimap&) = default;
20510d565efSmrg 
20610d565efSmrg       /**
20710d565efSmrg        *  @brief  %Multimap move constructor.
20810d565efSmrg        *
20910d565efSmrg        *  The newly-created %multimap contains the exact contents of the
21010d565efSmrg        *  moved instance. The moved instance is a valid, but unspecified
21110d565efSmrg        *  %multimap.
21210d565efSmrg        */
21310d565efSmrg       multimap(multimap&&) = default;
21410d565efSmrg 
21510d565efSmrg       /**
21610d565efSmrg        *  @brief  Builds a %multimap from an initializer_list.
21710d565efSmrg        *  @param  __l  An initializer_list.
21810d565efSmrg        *  @param  __comp  A comparison functor.
21910d565efSmrg        *  @param  __a  An allocator object.
22010d565efSmrg        *
22110d565efSmrg        *  Create a %multimap consisting of copies of the elements from
22210d565efSmrg        *  the initializer_list.  This is linear in N if the list is already
22310d565efSmrg        *  sorted, and NlogN otherwise (where N is @a __l.size()).
22410d565efSmrg        */
22510d565efSmrg       multimap(initializer_list<value_type> __l,
22610d565efSmrg 	       const _Compare& __comp = _Compare(),
22710d565efSmrg 	       const allocator_type& __a = allocator_type())
22810d565efSmrg       : _M_t(__comp, _Pair_alloc_type(__a))
2290fc04c29Smrg       { _M_t._M_insert_range_equal(__l.begin(), __l.end()); }
23010d565efSmrg 
23110d565efSmrg       /// Allocator-extended default constructor.
23210d565efSmrg       explicit
23310d565efSmrg       multimap(const allocator_type& __a)
2340fc04c29Smrg       : _M_t(_Pair_alloc_type(__a)) { }
23510d565efSmrg 
23610d565efSmrg       /// Allocator-extended copy constructor.
23710d565efSmrg       multimap(const multimap& __m, const allocator_type& __a)
23810d565efSmrg       : _M_t(__m._M_t, _Pair_alloc_type(__a)) { }
23910d565efSmrg 
24010d565efSmrg       /// Allocator-extended move constructor.
24110d565efSmrg       multimap(multimap&& __m, const allocator_type& __a)
24210d565efSmrg       noexcept(is_nothrow_copy_constructible<_Compare>::value
24310d565efSmrg 	       && _Alloc_traits::_S_always_equal())
24410d565efSmrg       : _M_t(std::move(__m._M_t), _Pair_alloc_type(__a)) { }
24510d565efSmrg 
24610d565efSmrg       /// Allocator-extended initialier-list constructor.
24710d565efSmrg       multimap(initializer_list<value_type> __l, const allocator_type& __a)
2480fc04c29Smrg       : _M_t(_Pair_alloc_type(__a))
2490fc04c29Smrg       { _M_t._M_insert_range_equal(__l.begin(), __l.end()); }
25010d565efSmrg 
25110d565efSmrg       /// Allocator-extended range constructor.
25210d565efSmrg       template<typename _InputIterator>
25310d565efSmrg 	multimap(_InputIterator __first, _InputIterator __last,
25410d565efSmrg 		 const allocator_type& __a)
2550fc04c29Smrg 	: _M_t(_Pair_alloc_type(__a))
2560fc04c29Smrg 	{ _M_t._M_insert_range_equal(__first, __last); }
25710d565efSmrg #endif
25810d565efSmrg 
25910d565efSmrg       /**
26010d565efSmrg        *  @brief  Builds a %multimap from a range.
26110d565efSmrg        *  @param  __first  An input iterator.
26210d565efSmrg        *  @param  __last  An input iterator.
26310d565efSmrg        *
26410d565efSmrg        *  Create a %multimap consisting of copies of the elements from
26510d565efSmrg        *  [__first,__last).  This is linear in N if the range is already sorted,
26610d565efSmrg        *  and NlogN otherwise (where N is distance(__first,__last)).
26710d565efSmrg        */
26810d565efSmrg       template<typename _InputIterator>
26910d565efSmrg 	multimap(_InputIterator __first, _InputIterator __last)
27010d565efSmrg 	: _M_t()
2710fc04c29Smrg 	{ _M_t._M_insert_range_equal(__first, __last); }
27210d565efSmrg 
27310d565efSmrg       /**
27410d565efSmrg        *  @brief  Builds a %multimap from a range.
27510d565efSmrg        *  @param  __first  An input iterator.
27610d565efSmrg        *  @param  __last  An input iterator.
27710d565efSmrg        *  @param  __comp  A comparison functor.
27810d565efSmrg        *  @param  __a  An allocator object.
27910d565efSmrg        *
28010d565efSmrg        *  Create a %multimap consisting of copies of the elements from
28110d565efSmrg        *  [__first,__last).  This is linear in N if the range is already sorted,
28210d565efSmrg        *  and NlogN otherwise (where N is distance(__first,__last)).
28310d565efSmrg        */
28410d565efSmrg       template<typename _InputIterator>
28510d565efSmrg 	multimap(_InputIterator __first, _InputIterator __last,
28610d565efSmrg 		 const _Compare& __comp,
28710d565efSmrg 		 const allocator_type& __a = allocator_type())
28810d565efSmrg 	: _M_t(__comp, _Pair_alloc_type(__a))
2890fc04c29Smrg 	{ _M_t._M_insert_range_equal(__first, __last); }
29010d565efSmrg 
29110d565efSmrg #if __cplusplus >= 201103L
29210d565efSmrg       /**
29310d565efSmrg        *  The dtor only erases the elements, and note that if the elements
29410d565efSmrg        *  themselves are pointers, the pointed-to memory is not touched in any
29510d565efSmrg        *  way. Managing the pointer is the user's responsibility.
29610d565efSmrg        */
29710d565efSmrg       ~multimap() = default;
29810d565efSmrg #endif
29910d565efSmrg 
30010d565efSmrg       /**
30110d565efSmrg        *  @brief  %Multimap assignment operator.
30210d565efSmrg        *
30310d565efSmrg        *  Whether the allocator is copied depends on the allocator traits.
30410d565efSmrg        */
30510d565efSmrg #if __cplusplus < 201103L
30610d565efSmrg       multimap&
30710d565efSmrg       operator=(const multimap& __x)
30810d565efSmrg       {
30910d565efSmrg 	_M_t = __x._M_t;
31010d565efSmrg 	return *this;
31110d565efSmrg       }
31210d565efSmrg #else
31310d565efSmrg       multimap&
31410d565efSmrg       operator=(const multimap&) = default;
31510d565efSmrg 
31610d565efSmrg       /// Move assignment operator.
31710d565efSmrg       multimap&
31810d565efSmrg       operator=(multimap&&) = default;
31910d565efSmrg 
32010d565efSmrg       /**
32110d565efSmrg        *  @brief  %Multimap list assignment operator.
32210d565efSmrg        *  @param  __l  An initializer_list.
32310d565efSmrg        *
32410d565efSmrg        *  This function fills a %multimap with copies of the elements
32510d565efSmrg        *  in the initializer list @a __l.
32610d565efSmrg        *
32710d565efSmrg        *  Note that the assignment completely changes the %multimap and
32810d565efSmrg        *  that the resulting %multimap's size is the same as the number
32910d565efSmrg        *  of elements assigned.
33010d565efSmrg        */
33110d565efSmrg       multimap&
33210d565efSmrg       operator=(initializer_list<value_type> __l)
33310d565efSmrg       {
33410d565efSmrg 	_M_t._M_assign_equal(__l.begin(), __l.end());
33510d565efSmrg 	return *this;
33610d565efSmrg       }
33710d565efSmrg #endif
33810d565efSmrg 
33910d565efSmrg       /// Get a copy of the memory allocation object.
34010d565efSmrg       allocator_type
34110d565efSmrg       get_allocator() const _GLIBCXX_NOEXCEPT
34210d565efSmrg       { return allocator_type(_M_t.get_allocator()); }
34310d565efSmrg 
34410d565efSmrg       // iterators
34510d565efSmrg       /**
34610d565efSmrg        *  Returns a read/write iterator that points to the first pair in the
34710d565efSmrg        *  %multimap.  Iteration is done in ascending order according to the
34810d565efSmrg        *  keys.
34910d565efSmrg        */
35010d565efSmrg       iterator
35110d565efSmrg       begin() _GLIBCXX_NOEXCEPT
35210d565efSmrg       { return _M_t.begin(); }
35310d565efSmrg 
35410d565efSmrg       /**
35510d565efSmrg        *  Returns a read-only (constant) iterator that points to the first pair
35610d565efSmrg        *  in the %multimap.  Iteration is done in ascending order according to
35710d565efSmrg        *  the keys.
35810d565efSmrg        */
35910d565efSmrg       const_iterator
36010d565efSmrg       begin() const _GLIBCXX_NOEXCEPT
36110d565efSmrg       { return _M_t.begin(); }
36210d565efSmrg 
36310d565efSmrg       /**
36410d565efSmrg        *  Returns a read/write iterator that points one past the last pair in
36510d565efSmrg        *  the %multimap.  Iteration is done in ascending order according to the
36610d565efSmrg        *  keys.
36710d565efSmrg        */
36810d565efSmrg       iterator
36910d565efSmrg       end() _GLIBCXX_NOEXCEPT
37010d565efSmrg       { return _M_t.end(); }
37110d565efSmrg 
37210d565efSmrg       /**
37310d565efSmrg        *  Returns a read-only (constant) iterator that points one past the last
37410d565efSmrg        *  pair in the %multimap.  Iteration is done in ascending order according
37510d565efSmrg        *  to the keys.
37610d565efSmrg        */
37710d565efSmrg       const_iterator
37810d565efSmrg       end() const _GLIBCXX_NOEXCEPT
37910d565efSmrg       { return _M_t.end(); }
38010d565efSmrg 
38110d565efSmrg       /**
38210d565efSmrg        *  Returns a read/write reverse iterator that points to the last pair in
38310d565efSmrg        *  the %multimap.  Iteration is done in descending order according to the
38410d565efSmrg        *  keys.
38510d565efSmrg        */
38610d565efSmrg       reverse_iterator
38710d565efSmrg       rbegin() _GLIBCXX_NOEXCEPT
38810d565efSmrg       { return _M_t.rbegin(); }
38910d565efSmrg 
39010d565efSmrg       /**
39110d565efSmrg        *  Returns a read-only (constant) reverse iterator that points to the
39210d565efSmrg        *  last pair in the %multimap.  Iteration is done in descending order
39310d565efSmrg        *  according to the keys.
39410d565efSmrg        */
39510d565efSmrg       const_reverse_iterator
39610d565efSmrg       rbegin() const _GLIBCXX_NOEXCEPT
39710d565efSmrg       { return _M_t.rbegin(); }
39810d565efSmrg 
39910d565efSmrg       /**
40010d565efSmrg        *  Returns a read/write reverse iterator that points to one before the
40110d565efSmrg        *  first pair in the %multimap.  Iteration is done in descending order
40210d565efSmrg        *  according to the keys.
40310d565efSmrg        */
40410d565efSmrg       reverse_iterator
40510d565efSmrg       rend() _GLIBCXX_NOEXCEPT
40610d565efSmrg       { return _M_t.rend(); }
40710d565efSmrg 
40810d565efSmrg       /**
40910d565efSmrg        *  Returns a read-only (constant) reverse iterator that points to one
41010d565efSmrg        *  before the first pair in the %multimap.  Iteration is done in
41110d565efSmrg        *  descending order according to the keys.
41210d565efSmrg        */
41310d565efSmrg       const_reverse_iterator
41410d565efSmrg       rend() const _GLIBCXX_NOEXCEPT
41510d565efSmrg       { return _M_t.rend(); }
41610d565efSmrg 
41710d565efSmrg #if __cplusplus >= 201103L
41810d565efSmrg       /**
41910d565efSmrg        *  Returns a read-only (constant) iterator that points to the first pair
42010d565efSmrg        *  in the %multimap.  Iteration is done in ascending order according to
42110d565efSmrg        *  the keys.
42210d565efSmrg        */
42310d565efSmrg       const_iterator
42410d565efSmrg       cbegin() const noexcept
42510d565efSmrg       { return _M_t.begin(); }
42610d565efSmrg 
42710d565efSmrg       /**
42810d565efSmrg        *  Returns a read-only (constant) iterator that points one past the last
42910d565efSmrg        *  pair in the %multimap.  Iteration is done in ascending order according
43010d565efSmrg        *  to the keys.
43110d565efSmrg        */
43210d565efSmrg       const_iterator
43310d565efSmrg       cend() const noexcept
43410d565efSmrg       { return _M_t.end(); }
43510d565efSmrg 
43610d565efSmrg       /**
43710d565efSmrg        *  Returns a read-only (constant) reverse iterator that points to the
43810d565efSmrg        *  last pair in the %multimap.  Iteration is done in descending order
43910d565efSmrg        *  according to the keys.
44010d565efSmrg        */
44110d565efSmrg       const_reverse_iterator
44210d565efSmrg       crbegin() const noexcept
44310d565efSmrg       { return _M_t.rbegin(); }
44410d565efSmrg 
44510d565efSmrg       /**
44610d565efSmrg        *  Returns a read-only (constant) reverse iterator that points to one
44710d565efSmrg        *  before the first pair in the %multimap.  Iteration is done in
44810d565efSmrg        *  descending order according to the keys.
44910d565efSmrg        */
45010d565efSmrg       const_reverse_iterator
45110d565efSmrg       crend() const noexcept
45210d565efSmrg       { return _M_t.rend(); }
45310d565efSmrg #endif
45410d565efSmrg 
45510d565efSmrg       // capacity
45610d565efSmrg       /** Returns true if the %multimap is empty.  */
4570fc04c29Smrg       _GLIBCXX_NODISCARD bool
45810d565efSmrg       empty() const _GLIBCXX_NOEXCEPT
45910d565efSmrg       { return _M_t.empty(); }
46010d565efSmrg 
46110d565efSmrg       /** Returns the size of the %multimap.  */
46210d565efSmrg       size_type
46310d565efSmrg       size() const _GLIBCXX_NOEXCEPT
46410d565efSmrg       { return _M_t.size(); }
46510d565efSmrg 
46610d565efSmrg       /** Returns the maximum size of the %multimap.  */
46710d565efSmrg       size_type
46810d565efSmrg       max_size() const _GLIBCXX_NOEXCEPT
46910d565efSmrg       { return _M_t.max_size(); }
47010d565efSmrg 
47110d565efSmrg       // modifiers
47210d565efSmrg #if __cplusplus >= 201103L
47310d565efSmrg       /**
47410d565efSmrg        *  @brief Build and insert a std::pair into the %multimap.
47510d565efSmrg        *
47610d565efSmrg        *  @param __args  Arguments used to generate a new pair instance (see
47710d565efSmrg        *	        std::piecewise_contruct for passing arguments to each
47810d565efSmrg        *	        part of the pair constructor).
47910d565efSmrg        *
48010d565efSmrg        *  @return An iterator that points to the inserted (key,value) pair.
48110d565efSmrg        *
48210d565efSmrg        *  This function builds and inserts a (key, value) %pair into the
48310d565efSmrg        *  %multimap.
48410d565efSmrg        *  Contrary to a std::map the %multimap does not rely on unique keys and
48510d565efSmrg        *  thus multiple pairs with the same key can be inserted.
48610d565efSmrg        *
48710d565efSmrg        *  Insertion requires logarithmic time.
48810d565efSmrg        */
48910d565efSmrg       template<typename... _Args>
49010d565efSmrg 	iterator
49110d565efSmrg 	emplace(_Args&&... __args)
49210d565efSmrg 	{ return _M_t._M_emplace_equal(std::forward<_Args>(__args)...); }
49310d565efSmrg 
49410d565efSmrg       /**
49510d565efSmrg        *  @brief Builds and inserts a std::pair into the %multimap.
49610d565efSmrg        *
49710d565efSmrg        *  @param  __pos  An iterator that serves as a hint as to where the pair
49810d565efSmrg        *                should be inserted.
49910d565efSmrg        *  @param  __args  Arguments used to generate a new pair instance (see
50010d565efSmrg        *	         std::piecewise_contruct for passing arguments to each
50110d565efSmrg        *	         part of the pair constructor).
50210d565efSmrg        *  @return An iterator that points to the inserted (key,value) pair.
50310d565efSmrg        *
50410d565efSmrg        *  This function inserts a (key, value) pair into the %multimap.
50510d565efSmrg        *  Contrary to a std::map the %multimap does not rely on unique keys and
50610d565efSmrg        *  thus multiple pairs with the same key can be inserted.
50710d565efSmrg        *  Note that the first parameter is only a hint and can potentially
50810d565efSmrg        *  improve the performance of the insertion process.  A bad hint would
50910d565efSmrg        *  cause no gains in efficiency.
51010d565efSmrg        *
51110d565efSmrg        *  For more on @a hinting, see:
51210d565efSmrg        *  https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints
51310d565efSmrg        *
51410d565efSmrg        *  Insertion requires logarithmic time (if the hint is not taken).
51510d565efSmrg        */
51610d565efSmrg       template<typename... _Args>
51710d565efSmrg 	iterator
51810d565efSmrg 	emplace_hint(const_iterator __pos, _Args&&... __args)
51910d565efSmrg 	{
52010d565efSmrg 	  return _M_t._M_emplace_hint_equal(__pos,
52110d565efSmrg 					    std::forward<_Args>(__args)...);
52210d565efSmrg 	}
52310d565efSmrg #endif
52410d565efSmrg 
52510d565efSmrg       /**
52610d565efSmrg        *  @brief Inserts a std::pair into the %multimap.
52710d565efSmrg        *  @param  __x  Pair to be inserted (see std::make_pair for easy creation
52810d565efSmrg        *             of pairs).
52910d565efSmrg        *  @return An iterator that points to the inserted (key,value) pair.
53010d565efSmrg        *
53110d565efSmrg        *  This function inserts a (key, value) pair into the %multimap.
53210d565efSmrg        *  Contrary to a std::map the %multimap does not rely on unique keys and
53310d565efSmrg        *  thus multiple pairs with the same key can be inserted.
53410d565efSmrg        *
53510d565efSmrg        *  Insertion requires logarithmic time.
53610d565efSmrg        *  @{
53710d565efSmrg        */
53810d565efSmrg       iterator
53910d565efSmrg       insert(const value_type& __x)
54010d565efSmrg       { return _M_t._M_insert_equal(__x); }
54110d565efSmrg 
54210d565efSmrg #if __cplusplus >= 201103L
54310d565efSmrg       // _GLIBCXX_RESOLVE_LIB_DEFECTS
54410d565efSmrg       // 2354. Unnecessary copying when inserting into maps with braced-init
54510d565efSmrg       iterator
54610d565efSmrg       insert(value_type&& __x)
54710d565efSmrg       { return _M_t._M_insert_equal(std::move(__x)); }
54810d565efSmrg 
54910d565efSmrg       template<typename _Pair>
55010d565efSmrg 	__enable_if_t<is_constructible<value_type, _Pair>::value, iterator>
55110d565efSmrg 	insert(_Pair&& __x)
55210d565efSmrg 	{ return _M_t._M_emplace_equal(std::forward<_Pair>(__x)); }
55310d565efSmrg #endif
554*ec02198aSmrg       /// @}
55510d565efSmrg 
55610d565efSmrg       /**
55710d565efSmrg        *  @brief Inserts a std::pair into the %multimap.
55810d565efSmrg        *  @param  __position  An iterator that serves as a hint as to where the
55910d565efSmrg        *                      pair should be inserted.
56010d565efSmrg        *  @param  __x  Pair to be inserted (see std::make_pair for easy creation
56110d565efSmrg        *               of pairs).
56210d565efSmrg        *  @return An iterator that points to the inserted (key,value) pair.
56310d565efSmrg        *
56410d565efSmrg        *  This function inserts a (key, value) pair into the %multimap.
56510d565efSmrg        *  Contrary to a std::map the %multimap does not rely on unique keys and
56610d565efSmrg        *  thus multiple pairs with the same key can be inserted.
56710d565efSmrg        *  Note that the first parameter is only a hint and can potentially
56810d565efSmrg        *  improve the performance of the insertion process.  A bad hint would
56910d565efSmrg        *  cause no gains in efficiency.
57010d565efSmrg        *
57110d565efSmrg        *  For more on @a hinting, see:
57210d565efSmrg        *  https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints
57310d565efSmrg        *
57410d565efSmrg        *  Insertion requires logarithmic time (if the hint is not taken).
57510d565efSmrg        * @{
57610d565efSmrg        */
57710d565efSmrg       iterator
57810d565efSmrg #if __cplusplus >= 201103L
57910d565efSmrg       insert(const_iterator __position, const value_type& __x)
58010d565efSmrg #else
58110d565efSmrg       insert(iterator __position, const value_type& __x)
58210d565efSmrg #endif
58310d565efSmrg       { return _M_t._M_insert_equal_(__position, __x); }
58410d565efSmrg 
58510d565efSmrg #if __cplusplus >= 201103L
58610d565efSmrg       // _GLIBCXX_RESOLVE_LIB_DEFECTS
58710d565efSmrg       // 2354. Unnecessary copying when inserting into maps with braced-init
58810d565efSmrg       iterator
58910d565efSmrg       insert(const_iterator __position, value_type&& __x)
59010d565efSmrg       { return _M_t._M_insert_equal_(__position, std::move(__x)); }
59110d565efSmrg 
59210d565efSmrg       template<typename _Pair>
59310d565efSmrg 	__enable_if_t<is_constructible<value_type, _Pair&&>::value, iterator>
59410d565efSmrg 	insert(const_iterator __position, _Pair&& __x)
59510d565efSmrg 	{
59610d565efSmrg 	  return _M_t._M_emplace_hint_equal(__position,
59710d565efSmrg 					    std::forward<_Pair>(__x));
59810d565efSmrg 	}
59910d565efSmrg #endif
600*ec02198aSmrg       /// @}
60110d565efSmrg 
60210d565efSmrg       /**
60310d565efSmrg        *  @brief A template function that attempts to insert a range
60410d565efSmrg        *  of elements.
60510d565efSmrg        *  @param  __first  Iterator pointing to the start of the range to be
60610d565efSmrg        *                   inserted.
60710d565efSmrg        *  @param  __last  Iterator pointing to the end of the range.
60810d565efSmrg        *
60910d565efSmrg        *  Complexity similar to that of the range constructor.
61010d565efSmrg        */
61110d565efSmrg       template<typename _InputIterator>
61210d565efSmrg 	void
61310d565efSmrg 	insert(_InputIterator __first, _InputIterator __last)
6140fc04c29Smrg 	{ _M_t._M_insert_range_equal(__first, __last); }
61510d565efSmrg 
61610d565efSmrg #if __cplusplus >= 201103L
61710d565efSmrg       /**
61810d565efSmrg        *  @brief Attempts to insert a list of std::pairs into the %multimap.
61910d565efSmrg        *  @param  __l  A std::initializer_list<value_type> of pairs to be
62010d565efSmrg        *               inserted.
62110d565efSmrg        *
62210d565efSmrg        *  Complexity similar to that of the range constructor.
62310d565efSmrg        */
62410d565efSmrg       void
62510d565efSmrg       insert(initializer_list<value_type> __l)
62610d565efSmrg       { this->insert(__l.begin(), __l.end()); }
62710d565efSmrg #endif
62810d565efSmrg 
62910d565efSmrg #if __cplusplus > 201402L
63010d565efSmrg       /// Extract a node.
63110d565efSmrg       node_type
63210d565efSmrg       extract(const_iterator __pos)
63310d565efSmrg       {
63410d565efSmrg 	__glibcxx_assert(__pos != end());
63510d565efSmrg 	return _M_t.extract(__pos);
63610d565efSmrg       }
63710d565efSmrg 
63810d565efSmrg       /// Extract a node.
63910d565efSmrg       node_type
64010d565efSmrg       extract(const key_type& __x)
64110d565efSmrg       { return _M_t.extract(__x); }
64210d565efSmrg 
64310d565efSmrg       /// Re-insert an extracted node.
64410d565efSmrg       iterator
64510d565efSmrg       insert(node_type&& __nh)
64610d565efSmrg       { return _M_t._M_reinsert_node_equal(std::move(__nh)); }
64710d565efSmrg 
64810d565efSmrg       /// Re-insert an extracted node.
64910d565efSmrg       iterator
65010d565efSmrg       insert(const_iterator __hint, node_type&& __nh)
65110d565efSmrg       { return _M_t._M_reinsert_node_hint_equal(__hint, std::move(__nh)); }
65210d565efSmrg 
65310d565efSmrg       template<typename, typename>
654c7a68eb7Smrg 	friend class std::_Rb_tree_merge_helper;
65510d565efSmrg 
656*ec02198aSmrg       template<typename _Cmp2>
65710d565efSmrg 	void
658*ec02198aSmrg 	merge(multimap<_Key, _Tp, _Cmp2, _Alloc>& __source)
65910d565efSmrg 	{
660*ec02198aSmrg 	  using _Merge_helper = _Rb_tree_merge_helper<multimap, _Cmp2>;
66110d565efSmrg 	  _M_t._M_merge_equal(_Merge_helper::_S_get_tree(__source));
66210d565efSmrg 	}
66310d565efSmrg 
664*ec02198aSmrg       template<typename _Cmp2>
66510d565efSmrg 	void
666*ec02198aSmrg 	merge(multimap<_Key, _Tp, _Cmp2, _Alloc>&& __source)
66710d565efSmrg 	{ merge(__source); }
66810d565efSmrg 
669*ec02198aSmrg       template<typename _Cmp2>
67010d565efSmrg 	void
671*ec02198aSmrg 	merge(map<_Key, _Tp, _Cmp2, _Alloc>& __source)
67210d565efSmrg 	{
673*ec02198aSmrg 	  using _Merge_helper = _Rb_tree_merge_helper<multimap, _Cmp2>;
67410d565efSmrg 	  _M_t._M_merge_equal(_Merge_helper::_S_get_tree(__source));
67510d565efSmrg 	}
67610d565efSmrg 
677*ec02198aSmrg       template<typename _Cmp2>
67810d565efSmrg 	void
679*ec02198aSmrg 	merge(map<_Key, _Tp, _Cmp2, _Alloc>&& __source)
68010d565efSmrg 	{ merge(__source); }
68110d565efSmrg #endif // C++17
68210d565efSmrg 
68310d565efSmrg #if __cplusplus >= 201103L
68410d565efSmrg       // _GLIBCXX_RESOLVE_LIB_DEFECTS
68510d565efSmrg       // DR 130. Associative erase should return an iterator.
68610d565efSmrg       /**
68710d565efSmrg        *  @brief Erases an element from a %multimap.
68810d565efSmrg        *  @param  __position  An iterator pointing to the element to be erased.
68910d565efSmrg        *  @return An iterator pointing to the element immediately following
69010d565efSmrg        *          @a position prior to the element being erased. If no such
69110d565efSmrg        *          element exists, end() is returned.
69210d565efSmrg        *
69310d565efSmrg        *  This function erases an element, pointed to by the given iterator,
69410d565efSmrg        *  from a %multimap.  Note that this function only erases the element,
69510d565efSmrg        *  and that if the element is itself a pointer, the pointed-to memory is
69610d565efSmrg        *  not touched in any way.  Managing the pointer is the user's
69710d565efSmrg        *  responsibility.
69810d565efSmrg        *
69910d565efSmrg        * @{
70010d565efSmrg        */
70110d565efSmrg       iterator
70210d565efSmrg       erase(const_iterator __position)
70310d565efSmrg       { return _M_t.erase(__position); }
70410d565efSmrg 
70510d565efSmrg       // LWG 2059.
70610d565efSmrg       _GLIBCXX_ABI_TAG_CXX11
70710d565efSmrg       iterator
70810d565efSmrg       erase(iterator __position)
70910d565efSmrg       { return _M_t.erase(__position); }
710*ec02198aSmrg       /// @}
71110d565efSmrg #else
71210d565efSmrg       /**
71310d565efSmrg        *  @brief Erases an element from a %multimap.
71410d565efSmrg        *  @param  __position  An iterator pointing to the element to be erased.
71510d565efSmrg        *
71610d565efSmrg        *  This function erases an element, pointed to by the given iterator,
71710d565efSmrg        *  from a %multimap.  Note that this function only erases the element,
71810d565efSmrg        *  and that if the element is itself a pointer, the pointed-to memory is
71910d565efSmrg        *  not touched in any way.  Managing the pointer is the user's
72010d565efSmrg        *  responsibility.
72110d565efSmrg        */
72210d565efSmrg       void
72310d565efSmrg       erase(iterator __position)
72410d565efSmrg       { _M_t.erase(__position); }
72510d565efSmrg #endif
72610d565efSmrg 
72710d565efSmrg       /**
72810d565efSmrg        *  @brief Erases elements according to the provided key.
72910d565efSmrg        *  @param  __x  Key of element to be erased.
73010d565efSmrg        *  @return  The number of elements erased.
73110d565efSmrg        *
73210d565efSmrg        *  This function erases all elements located by the given key from a
73310d565efSmrg        *  %multimap.
73410d565efSmrg        *  Note that this function only erases the element, and that if
73510d565efSmrg        *  the element is itself a pointer, the pointed-to memory is not touched
73610d565efSmrg        *  in any way.  Managing the pointer is the user's responsibility.
73710d565efSmrg        */
73810d565efSmrg       size_type
73910d565efSmrg       erase(const key_type& __x)
74010d565efSmrg       { return _M_t.erase(__x); }
74110d565efSmrg 
74210d565efSmrg #if __cplusplus >= 201103L
74310d565efSmrg       // _GLIBCXX_RESOLVE_LIB_DEFECTS
74410d565efSmrg       // DR 130. Associative erase should return an iterator.
74510d565efSmrg       /**
74610d565efSmrg        *  @brief Erases a [first,last) range of elements from a %multimap.
74710d565efSmrg        *  @param  __first  Iterator pointing to the start of the range to be
74810d565efSmrg        *                   erased.
74910d565efSmrg        *  @param __last Iterator pointing to the end of the range to be
75010d565efSmrg        *                erased .
75110d565efSmrg        *  @return The iterator @a __last.
75210d565efSmrg        *
75310d565efSmrg        *  This function erases a sequence of elements from a %multimap.
75410d565efSmrg        *  Note that this function only erases the elements, and that if
75510d565efSmrg        *  the elements themselves are pointers, the pointed-to memory is not
75610d565efSmrg        *  touched in any way.  Managing the pointer is the user's
75710d565efSmrg        *  responsibility.
75810d565efSmrg        */
75910d565efSmrg       iterator
76010d565efSmrg       erase(const_iterator __first, const_iterator __last)
76110d565efSmrg       { return _M_t.erase(__first, __last); }
76210d565efSmrg #else
76310d565efSmrg       // _GLIBCXX_RESOLVE_LIB_DEFECTS
76410d565efSmrg       // DR 130. Associative erase should return an iterator.
76510d565efSmrg       /**
76610d565efSmrg        *  @brief Erases a [first,last) range of elements from a %multimap.
76710d565efSmrg        *  @param  __first  Iterator pointing to the start of the range to be
76810d565efSmrg        *                 erased.
76910d565efSmrg        *  @param __last Iterator pointing to the end of the range to
77010d565efSmrg        *                be erased.
77110d565efSmrg        *
77210d565efSmrg        *  This function erases a sequence of elements from a %multimap.
77310d565efSmrg        *  Note that this function only erases the elements, and that if
77410d565efSmrg        *  the elements themselves are pointers, the pointed-to memory is not
77510d565efSmrg        *  touched in any way.  Managing the pointer is the user's
77610d565efSmrg        *  responsibility.
77710d565efSmrg        */
77810d565efSmrg       void
77910d565efSmrg       erase(iterator __first, iterator __last)
78010d565efSmrg       { _M_t.erase(__first, __last); }
78110d565efSmrg #endif
78210d565efSmrg 
78310d565efSmrg       /**
78410d565efSmrg        *  @brief  Swaps data with another %multimap.
78510d565efSmrg        *  @param  __x  A %multimap of the same element and allocator types.
78610d565efSmrg        *
78710d565efSmrg        *  This exchanges the elements between two multimaps in constant time.
78810d565efSmrg        *  (It is only swapping a pointer, an integer, and an instance of
78910d565efSmrg        *  the @c Compare type (which itself is often stateless and empty), so it
79010d565efSmrg        *  should be quite fast.)
79110d565efSmrg        *  Note that the global std::swap() function is specialized such that
79210d565efSmrg        *  std::swap(m1,m2) will feed to this function.
79310d565efSmrg        *
79410d565efSmrg        *  Whether the allocators are swapped depends on the allocator traits.
79510d565efSmrg        */
79610d565efSmrg       void
79710d565efSmrg       swap(multimap& __x)
79810d565efSmrg       _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value)
79910d565efSmrg       { _M_t.swap(__x._M_t); }
80010d565efSmrg 
80110d565efSmrg       /**
80210d565efSmrg        *  Erases all elements in a %multimap.  Note that this function only
80310d565efSmrg        *  erases the elements, and that if the elements themselves are pointers,
80410d565efSmrg        *  the pointed-to memory is not touched in any way.  Managing the pointer
80510d565efSmrg        *  is the user's responsibility.
80610d565efSmrg        */
80710d565efSmrg       void
80810d565efSmrg       clear() _GLIBCXX_NOEXCEPT
80910d565efSmrg       { _M_t.clear(); }
81010d565efSmrg 
81110d565efSmrg       // observers
81210d565efSmrg       /**
81310d565efSmrg        *  Returns the key comparison object out of which the %multimap
81410d565efSmrg        *  was constructed.
81510d565efSmrg        */
81610d565efSmrg       key_compare
81710d565efSmrg       key_comp() const
81810d565efSmrg       { return _M_t.key_comp(); }
81910d565efSmrg 
82010d565efSmrg       /**
82110d565efSmrg        *  Returns a value comparison object, built from the key comparison
82210d565efSmrg        *  object out of which the %multimap was constructed.
82310d565efSmrg        */
82410d565efSmrg       value_compare
82510d565efSmrg       value_comp() const
82610d565efSmrg       { return value_compare(_M_t.key_comp()); }
82710d565efSmrg 
82810d565efSmrg       // multimap operations
82910d565efSmrg 
830*ec02198aSmrg       ///@{
83110d565efSmrg       /**
83210d565efSmrg        *  @brief Tries to locate an element in a %multimap.
83310d565efSmrg        *  @param  __x  Key of (key, value) pair to be located.
83410d565efSmrg        *  @return  Iterator pointing to sought-after element,
83510d565efSmrg        *           or end() if not found.
83610d565efSmrg        *
83710d565efSmrg        *  This function takes a key and tries to locate the element with which
83810d565efSmrg        *  the key matches.  If successful the function returns an iterator
83910d565efSmrg        *  pointing to the sought after %pair.  If unsuccessful it returns the
84010d565efSmrg        *  past-the-end ( @c end() ) iterator.
84110d565efSmrg        */
84210d565efSmrg       iterator
84310d565efSmrg       find(const key_type& __x)
84410d565efSmrg       { return _M_t.find(__x); }
84510d565efSmrg 
84610d565efSmrg #if __cplusplus > 201103L
84710d565efSmrg       template<typename _Kt>
84810d565efSmrg 	auto
84910d565efSmrg 	find(const _Kt& __x) -> decltype(_M_t._M_find_tr(__x))
85010d565efSmrg 	{ return _M_t._M_find_tr(__x); }
85110d565efSmrg #endif
852*ec02198aSmrg       ///@}
85310d565efSmrg 
854*ec02198aSmrg       ///@{
85510d565efSmrg       /**
85610d565efSmrg        *  @brief Tries to locate an element in a %multimap.
85710d565efSmrg        *  @param  __x  Key of (key, value) pair to be located.
85810d565efSmrg        *  @return  Read-only (constant) iterator pointing to sought-after
85910d565efSmrg        *           element, or end() if not found.
86010d565efSmrg        *
86110d565efSmrg        *  This function takes a key and tries to locate the element with which
86210d565efSmrg        *  the key matches.  If successful the function returns a constant
86310d565efSmrg        *  iterator pointing to the sought after %pair.  If unsuccessful it
86410d565efSmrg        *  returns the past-the-end ( @c end() ) iterator.
86510d565efSmrg        */
86610d565efSmrg       const_iterator
86710d565efSmrg       find(const key_type& __x) const
86810d565efSmrg       { return _M_t.find(__x); }
86910d565efSmrg 
87010d565efSmrg #if __cplusplus > 201103L
87110d565efSmrg       template<typename _Kt>
87210d565efSmrg 	auto
87310d565efSmrg 	find(const _Kt& __x) const -> decltype(_M_t._M_find_tr(__x))
87410d565efSmrg 	{ return _M_t._M_find_tr(__x); }
87510d565efSmrg #endif
876*ec02198aSmrg       ///@}
87710d565efSmrg 
878*ec02198aSmrg       ///@{
87910d565efSmrg       /**
88010d565efSmrg        *  @brief Finds the number of elements with given key.
88110d565efSmrg        *  @param  __x  Key of (key, value) pairs to be located.
88210d565efSmrg        *  @return Number of elements with specified key.
88310d565efSmrg        */
88410d565efSmrg       size_type
88510d565efSmrg       count(const key_type& __x) const
88610d565efSmrg       { return _M_t.count(__x); }
88710d565efSmrg 
88810d565efSmrg #if __cplusplus > 201103L
88910d565efSmrg       template<typename _Kt>
89010d565efSmrg 	auto
89110d565efSmrg 	count(const _Kt& __x) const -> decltype(_M_t._M_count_tr(__x))
89210d565efSmrg 	{ return _M_t._M_count_tr(__x); }
89310d565efSmrg #endif
894*ec02198aSmrg       ///@}
89510d565efSmrg 
8960fc04c29Smrg #if __cplusplus > 201703L
897*ec02198aSmrg       ///@{
8980fc04c29Smrg       /**
8990fc04c29Smrg        *  @brief  Finds whether an element with the given key exists.
9000fc04c29Smrg        *  @param  __x  Key of (key, value) pairs to be located.
9010fc04c29Smrg        *  @return  True if there is any element with the specified key.
9020fc04c29Smrg        */
9030fc04c29Smrg       bool
9040fc04c29Smrg       contains(const key_type& __x) const
9050fc04c29Smrg       { return _M_t.find(__x) != _M_t.end(); }
9060fc04c29Smrg 
9070fc04c29Smrg       template<typename _Kt>
9080fc04c29Smrg 	auto
9090fc04c29Smrg 	contains(const _Kt& __x) const
9100fc04c29Smrg 	-> decltype(_M_t._M_find_tr(__x), void(), true)
9110fc04c29Smrg 	{ return _M_t._M_find_tr(__x) != _M_t.end(); }
912*ec02198aSmrg       ///@}
9130fc04c29Smrg #endif
9140fc04c29Smrg 
915*ec02198aSmrg       ///@{
91610d565efSmrg       /**
91710d565efSmrg        *  @brief Finds the beginning of a subsequence matching given key.
91810d565efSmrg        *  @param  __x  Key of (key, value) pair to be located.
91910d565efSmrg        *  @return  Iterator pointing to first element equal to or greater
92010d565efSmrg        *           than key, or end().
92110d565efSmrg        *
92210d565efSmrg        *  This function returns the first element of a subsequence of elements
92310d565efSmrg        *  that matches the given key.  If unsuccessful it returns an iterator
92410d565efSmrg        *  pointing to the first element that has a greater value than given key
92510d565efSmrg        *  or end() if no such element exists.
92610d565efSmrg        */
92710d565efSmrg       iterator
92810d565efSmrg       lower_bound(const key_type& __x)
92910d565efSmrg       { return _M_t.lower_bound(__x); }
93010d565efSmrg 
93110d565efSmrg #if __cplusplus > 201103L
93210d565efSmrg       template<typename _Kt>
93310d565efSmrg 	auto
93410d565efSmrg 	lower_bound(const _Kt& __x)
93510d565efSmrg 	-> decltype(iterator(_M_t._M_lower_bound_tr(__x)))
93610d565efSmrg 	{ return iterator(_M_t._M_lower_bound_tr(__x)); }
93710d565efSmrg #endif
938*ec02198aSmrg       ///@}
93910d565efSmrg 
940*ec02198aSmrg       ///@{
94110d565efSmrg       /**
94210d565efSmrg        *  @brief Finds the beginning of a subsequence matching given key.
94310d565efSmrg        *  @param  __x  Key of (key, value) pair to be located.
94410d565efSmrg        *  @return  Read-only (constant) iterator pointing to first element
94510d565efSmrg        *           equal to or greater than key, or end().
94610d565efSmrg        *
94710d565efSmrg        *  This function returns the first element of a subsequence of
94810d565efSmrg        *  elements that matches the given key.  If unsuccessful the
94910d565efSmrg        *  iterator will point to the next greatest element or, if no
95010d565efSmrg        *  such greater element exists, to end().
95110d565efSmrg        */
95210d565efSmrg       const_iterator
95310d565efSmrg       lower_bound(const key_type& __x) const
95410d565efSmrg       { return _M_t.lower_bound(__x); }
95510d565efSmrg 
95610d565efSmrg #if __cplusplus > 201103L
95710d565efSmrg       template<typename _Kt>
95810d565efSmrg 	auto
95910d565efSmrg 	lower_bound(const _Kt& __x) const
96010d565efSmrg 	-> decltype(const_iterator(_M_t._M_lower_bound_tr(__x)))
96110d565efSmrg 	{ return const_iterator(_M_t._M_lower_bound_tr(__x)); }
96210d565efSmrg #endif
963*ec02198aSmrg       ///@}
96410d565efSmrg 
965*ec02198aSmrg       ///@{
96610d565efSmrg       /**
96710d565efSmrg        *  @brief Finds the end of a subsequence matching given key.
96810d565efSmrg        *  @param  __x  Key of (key, value) pair to be located.
96910d565efSmrg        *  @return Iterator pointing to the first element
97010d565efSmrg        *          greater than key, or end().
97110d565efSmrg        */
97210d565efSmrg       iterator
97310d565efSmrg       upper_bound(const key_type& __x)
97410d565efSmrg       { return _M_t.upper_bound(__x); }
97510d565efSmrg 
97610d565efSmrg #if __cplusplus > 201103L
97710d565efSmrg       template<typename _Kt>
97810d565efSmrg 	auto
97910d565efSmrg 	upper_bound(const _Kt& __x)
98010d565efSmrg 	-> decltype(iterator(_M_t._M_upper_bound_tr(__x)))
98110d565efSmrg 	{ return iterator(_M_t._M_upper_bound_tr(__x)); }
98210d565efSmrg #endif
983*ec02198aSmrg       ///@}
98410d565efSmrg 
985*ec02198aSmrg       ///@{
98610d565efSmrg       /**
98710d565efSmrg        *  @brief Finds the end of a subsequence matching given key.
98810d565efSmrg        *  @param  __x  Key of (key, value) pair to be located.
98910d565efSmrg        *  @return  Read-only (constant) iterator pointing to first iterator
99010d565efSmrg        *           greater than key, or end().
99110d565efSmrg        */
99210d565efSmrg       const_iterator
99310d565efSmrg       upper_bound(const key_type& __x) const
99410d565efSmrg       { return _M_t.upper_bound(__x); }
99510d565efSmrg 
99610d565efSmrg #if __cplusplus > 201103L
99710d565efSmrg       template<typename _Kt>
99810d565efSmrg 	auto
99910d565efSmrg 	upper_bound(const _Kt& __x) const
100010d565efSmrg 	-> decltype(const_iterator(_M_t._M_upper_bound_tr(__x)))
100110d565efSmrg 	{ return const_iterator(_M_t._M_upper_bound_tr(__x)); }
100210d565efSmrg #endif
1003*ec02198aSmrg       ///@}
100410d565efSmrg 
1005*ec02198aSmrg       ///@{
100610d565efSmrg       /**
100710d565efSmrg        *  @brief Finds a subsequence matching given key.
100810d565efSmrg        *  @param  __x  Key of (key, value) pairs to be located.
100910d565efSmrg        *  @return  Pair of iterators that possibly points to the subsequence
101010d565efSmrg        *           matching given key.
101110d565efSmrg        *
101210d565efSmrg        *  This function is equivalent to
101310d565efSmrg        *  @code
101410d565efSmrg        *    std::make_pair(c.lower_bound(val),
101510d565efSmrg        *                   c.upper_bound(val))
101610d565efSmrg        *  @endcode
101710d565efSmrg        *  (but is faster than making the calls separately).
101810d565efSmrg        */
101910d565efSmrg       std::pair<iterator, iterator>
102010d565efSmrg       equal_range(const key_type& __x)
102110d565efSmrg       { return _M_t.equal_range(__x); }
102210d565efSmrg 
102310d565efSmrg #if __cplusplus > 201103L
102410d565efSmrg       template<typename _Kt>
102510d565efSmrg 	auto
102610d565efSmrg 	equal_range(const _Kt& __x)
102710d565efSmrg 	-> decltype(pair<iterator, iterator>(_M_t._M_equal_range_tr(__x)))
102810d565efSmrg 	{ return pair<iterator, iterator>(_M_t._M_equal_range_tr(__x)); }
102910d565efSmrg #endif
1030*ec02198aSmrg       ///@}
103110d565efSmrg 
1032*ec02198aSmrg       ///@{
103310d565efSmrg       /**
103410d565efSmrg        *  @brief Finds a subsequence matching given key.
103510d565efSmrg        *  @param  __x  Key of (key, value) pairs to be located.
103610d565efSmrg        *  @return  Pair of read-only (constant) iterators that possibly points
103710d565efSmrg        *           to the subsequence matching given key.
103810d565efSmrg        *
103910d565efSmrg        *  This function is equivalent to
104010d565efSmrg        *  @code
104110d565efSmrg        *    std::make_pair(c.lower_bound(val),
104210d565efSmrg        *                   c.upper_bound(val))
104310d565efSmrg        *  @endcode
104410d565efSmrg        *  (but is faster than making the calls separately).
104510d565efSmrg        */
104610d565efSmrg       std::pair<const_iterator, const_iterator>
104710d565efSmrg       equal_range(const key_type& __x) const
104810d565efSmrg       { return _M_t.equal_range(__x); }
104910d565efSmrg 
105010d565efSmrg #if __cplusplus > 201103L
105110d565efSmrg       template<typename _Kt>
105210d565efSmrg 	auto
105310d565efSmrg 	equal_range(const _Kt& __x) const
105410d565efSmrg 	-> decltype(pair<const_iterator, const_iterator>(
105510d565efSmrg 	      _M_t._M_equal_range_tr(__x)))
105610d565efSmrg 	{
105710d565efSmrg 	  return pair<const_iterator, const_iterator>(
105810d565efSmrg 	      _M_t._M_equal_range_tr(__x));
105910d565efSmrg 	}
106010d565efSmrg #endif
1061*ec02198aSmrg       ///@}
106210d565efSmrg 
106310d565efSmrg       template<typename _K1, typename _T1, typename _C1, typename _A1>
106410d565efSmrg 	friend bool
106510d565efSmrg 	operator==(const multimap<_K1, _T1, _C1, _A1>&,
106610d565efSmrg 		   const multimap<_K1, _T1, _C1, _A1>&);
106710d565efSmrg 
1068*ec02198aSmrg #if __cpp_lib_three_way_comparison
1069*ec02198aSmrg       template<typename _K1, typename _T1, typename _C1, typename _A1>
1070*ec02198aSmrg 	friend __detail::__synth3way_t<pair<const _K1, _T1>>
1071*ec02198aSmrg 	operator<=>(const multimap<_K1, _T1, _C1, _A1>&,
1072*ec02198aSmrg 		    const multimap<_K1, _T1, _C1, _A1>&);
1073*ec02198aSmrg #else
107410d565efSmrg       template<typename _K1, typename _T1, typename _C1, typename _A1>
107510d565efSmrg 	friend bool
107610d565efSmrg 	operator<(const multimap<_K1, _T1, _C1, _A1>&,
107710d565efSmrg 		  const multimap<_K1, _T1, _C1, _A1>&);
1078*ec02198aSmrg #endif
107910d565efSmrg   };
108010d565efSmrg 
1081c7a68eb7Smrg #if __cpp_deduction_guides >= 201606
1082c7a68eb7Smrg 
1083c7a68eb7Smrg   template<typename _InputIterator,
1084c7a68eb7Smrg 	   typename _Compare = less<__iter_key_t<_InputIterator>>,
1085c7a68eb7Smrg 	   typename _Allocator = allocator<__iter_to_alloc_t<_InputIterator>>,
1086c7a68eb7Smrg 	   typename = _RequireInputIter<_InputIterator>,
10870fc04c29Smrg 	   typename = _RequireNotAllocator<_Compare>,
1088c7a68eb7Smrg 	   typename = _RequireAllocator<_Allocator>>
1089c7a68eb7Smrg     multimap(_InputIterator, _InputIterator,
1090c7a68eb7Smrg 	     _Compare = _Compare(), _Allocator = _Allocator())
1091c7a68eb7Smrg     -> multimap<__iter_key_t<_InputIterator>, __iter_val_t<_InputIterator>,
1092c7a68eb7Smrg 		_Compare, _Allocator>;
1093c7a68eb7Smrg 
1094c7a68eb7Smrg   template<typename _Key, typename _Tp, typename _Compare = less<_Key>,
1095c7a68eb7Smrg 	   typename _Allocator = allocator<pair<const _Key, _Tp>>,
10960fc04c29Smrg 	   typename = _RequireNotAllocator<_Compare>,
1097c7a68eb7Smrg 	   typename = _RequireAllocator<_Allocator>>
1098c7a68eb7Smrg     multimap(initializer_list<pair<_Key, _Tp>>,
1099c7a68eb7Smrg 	     _Compare = _Compare(), _Allocator = _Allocator())
1100c7a68eb7Smrg     -> multimap<_Key, _Tp, _Compare, _Allocator>;
1101c7a68eb7Smrg 
1102c7a68eb7Smrg   template<typename _InputIterator, typename _Allocator,
1103c7a68eb7Smrg 	   typename = _RequireInputIter<_InputIterator>,
1104c7a68eb7Smrg 	   typename = _RequireAllocator<_Allocator>>
1105c7a68eb7Smrg     multimap(_InputIterator, _InputIterator, _Allocator)
1106c7a68eb7Smrg     -> multimap<__iter_key_t<_InputIterator>, __iter_val_t<_InputIterator>,
1107c7a68eb7Smrg 		less<__iter_key_t<_InputIterator>>, _Allocator>;
1108c7a68eb7Smrg 
1109c7a68eb7Smrg   template<typename _Key, typename _Tp, typename _Allocator,
1110c7a68eb7Smrg 	   typename = _RequireAllocator<_Allocator>>
1111c7a68eb7Smrg     multimap(initializer_list<pair<_Key, _Tp>>, _Allocator)
1112c7a68eb7Smrg     -> multimap<_Key, _Tp, less<_Key>, _Allocator>;
1113c7a68eb7Smrg 
1114*ec02198aSmrg #endif // deduction guides
1115c7a68eb7Smrg 
111610d565efSmrg   /**
111710d565efSmrg    *  @brief  Multimap equality comparison.
111810d565efSmrg    *  @param  __x  A %multimap.
111910d565efSmrg    *  @param  __y  A %multimap of the same type as @a __x.
112010d565efSmrg    *  @return  True iff the size and elements of the maps are equal.
112110d565efSmrg    *
112210d565efSmrg    *  This is an equivalence relation.  It is linear in the size of the
112310d565efSmrg    *  multimaps.  Multimaps are considered equivalent if their sizes are equal,
112410d565efSmrg    *  and if corresponding elements compare equal.
112510d565efSmrg   */
112610d565efSmrg   template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
112710d565efSmrg     inline bool
112810d565efSmrg     operator==(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
112910d565efSmrg 	       const multimap<_Key, _Tp, _Compare, _Alloc>& __y)
113010d565efSmrg     { return __x._M_t == __y._M_t; }
113110d565efSmrg 
1132*ec02198aSmrg #if __cpp_lib_three_way_comparison
1133*ec02198aSmrg   /**
1134*ec02198aSmrg    *  @brief  Multimap ordering relation.
1135*ec02198aSmrg    *  @param  __x  A `multimap`.
1136*ec02198aSmrg    *  @param  __y  A `multimap` of the same type as `x`.
1137*ec02198aSmrg    *  @return  A value indicating whether `__x` is less than, equal to,
1138*ec02198aSmrg    *           greater than, or incomparable with `__y`.
1139*ec02198aSmrg    *
1140*ec02198aSmrg    *  This is a total ordering relation.  It is linear in the size of the
1141*ec02198aSmrg    *  maps.  The elements must be comparable with @c <.
1142*ec02198aSmrg    *
1143*ec02198aSmrg    *  See `std::lexicographical_compare_three_way()` for how the determination
1144*ec02198aSmrg    *  is made. This operator is used to synthesize relational operators like
1145*ec02198aSmrg    *  `<` and `>=` etc.
1146*ec02198aSmrg   */
1147*ec02198aSmrg   template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
1148*ec02198aSmrg     inline __detail::__synth3way_t<pair<const _Key, _Tp>>
1149*ec02198aSmrg     operator<=>(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
1150*ec02198aSmrg 		const multimap<_Key, _Tp, _Compare, _Alloc>& __y)
1151*ec02198aSmrg     { return __x._M_t <=> __y._M_t; }
1152*ec02198aSmrg #else
115310d565efSmrg   /**
115410d565efSmrg    *  @brief  Multimap ordering relation.
115510d565efSmrg    *  @param  __x  A %multimap.
115610d565efSmrg    *  @param  __y  A %multimap of the same type as @a __x.
115710d565efSmrg    *  @return  True iff @a x is lexicographically less than @a y.
115810d565efSmrg    *
115910d565efSmrg    *  This is a total ordering relation.  It is linear in the size of the
116010d565efSmrg    *  multimaps.  The elements must be comparable with @c <.
116110d565efSmrg    *
116210d565efSmrg    *  See std::lexicographical_compare() for how the determination is made.
116310d565efSmrg   */
116410d565efSmrg   template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
116510d565efSmrg     inline bool
116610d565efSmrg     operator<(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
116710d565efSmrg 	      const multimap<_Key, _Tp, _Compare, _Alloc>& __y)
116810d565efSmrg     { return __x._M_t < __y._M_t; }
116910d565efSmrg 
117010d565efSmrg   /// Based on operator==
117110d565efSmrg   template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
117210d565efSmrg     inline bool
117310d565efSmrg     operator!=(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
117410d565efSmrg 	       const multimap<_Key, _Tp, _Compare, _Alloc>& __y)
117510d565efSmrg     { return !(__x == __y); }
117610d565efSmrg 
117710d565efSmrg   /// Based on operator<
117810d565efSmrg   template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
117910d565efSmrg     inline bool
118010d565efSmrg     operator>(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
118110d565efSmrg 	      const multimap<_Key, _Tp, _Compare, _Alloc>& __y)
118210d565efSmrg     { return __y < __x; }
118310d565efSmrg 
118410d565efSmrg   /// Based on operator<
118510d565efSmrg   template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
118610d565efSmrg     inline bool
118710d565efSmrg     operator<=(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
118810d565efSmrg 	       const multimap<_Key, _Tp, _Compare, _Alloc>& __y)
118910d565efSmrg     { return !(__y < __x); }
119010d565efSmrg 
119110d565efSmrg   /// Based on operator<
119210d565efSmrg   template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
119310d565efSmrg     inline bool
119410d565efSmrg     operator>=(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
119510d565efSmrg 	       const multimap<_Key, _Tp, _Compare, _Alloc>& __y)
119610d565efSmrg     { return !(__x < __y); }
1197*ec02198aSmrg #endif // three-way comparison
119810d565efSmrg 
119910d565efSmrg   /// See std::multimap::swap().
120010d565efSmrg   template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
120110d565efSmrg     inline void
120210d565efSmrg     swap(multimap<_Key, _Tp, _Compare, _Alloc>& __x,
120310d565efSmrg 	 multimap<_Key, _Tp, _Compare, _Alloc>& __y)
120410d565efSmrg     _GLIBCXX_NOEXCEPT_IF(noexcept(__x.swap(__y)))
120510d565efSmrg     { __x.swap(__y); }
120610d565efSmrg 
120710d565efSmrg _GLIBCXX_END_NAMESPACE_CONTAINER
120810d565efSmrg 
120910d565efSmrg #if __cplusplus > 201402L
121010d565efSmrg   // Allow std::multimap access to internals of compatible maps.
121110d565efSmrg   template<typename _Key, typename _Val, typename _Cmp1, typename _Alloc,
121210d565efSmrg 	   typename _Cmp2>
121310d565efSmrg     struct
121410d565efSmrg     _Rb_tree_merge_helper<_GLIBCXX_STD_C::multimap<_Key, _Val, _Cmp1, _Alloc>,
121510d565efSmrg 			  _Cmp2>
121610d565efSmrg     {
121710d565efSmrg     private:
121810d565efSmrg       friend class _GLIBCXX_STD_C::multimap<_Key, _Val, _Cmp1, _Alloc>;
121910d565efSmrg 
122010d565efSmrg       static auto&
122110d565efSmrg       _S_get_tree(_GLIBCXX_STD_C::map<_Key, _Val, _Cmp2, _Alloc>& __map)
122210d565efSmrg       { return __map._M_t; }
122310d565efSmrg 
122410d565efSmrg       static auto&
122510d565efSmrg       _S_get_tree(_GLIBCXX_STD_C::multimap<_Key, _Val, _Cmp2, _Alloc>& __map)
122610d565efSmrg       { return __map._M_t; }
122710d565efSmrg     };
122810d565efSmrg #endif // C++17
122910d565efSmrg 
1230c7a68eb7Smrg _GLIBCXX_END_NAMESPACE_VERSION
123110d565efSmrg } // namespace std
123210d565efSmrg 
123310d565efSmrg #endif /* _STL_MULTIMAP_H */
1234