1 // Multimap implementation -*- C++ -*-
3 // Copyright (C) 2001-2017 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
28 * Hewlett-Packard Company
30 * Permission to use, copy, modify, distribute and sell this software
31 * and its documentation for any purpose is hereby granted without fee,
32 * provided that the above copyright notice appear in all copies and
33 * that both that copyright notice and this permission notice appear
34 * in supporting documentation. Hewlett-Packard Company makes no
35 * representations about the suitability of this software for any
36 * purpose. It is provided "as is" without express or implied warranty.
39 * Copyright (c) 1996,1997
40 * Silicon Graphics Computer Systems, Inc.
42 * Permission to use, copy, modify, distribute and sell this software
43 * and its documentation for any purpose is hereby granted without fee,
44 * provided that the above copyright notice appear in all copies and
45 * that both that copyright notice and this permission notice appear
46 * in supporting documentation. Silicon Graphics makes no
47 * representations about the suitability of this software for any
48 * purpose. It is provided "as is" without express or implied warranty.
51 /** @file bits/stl_multimap.h
52 * This is an internal header file, included by other library headers.
53 * Do not attempt to use it directly. @headername{map}
56 #ifndef _STL_MULTIMAP_H
57 #define _STL_MULTIMAP_H 1
59 #include <bits/concept_check.h>
60 #if __cplusplus >= 201103L
61 #include <initializer_list>
64 namespace std
_GLIBCXX_VISIBILITY(default)
66 _GLIBCXX_BEGIN_NAMESPACE_VERSION
67 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
69 template <typename _Key
, typename _Tp
, typename _Compare
, typename _Alloc
>
73 * @brief A standard container made up of (key,value) pairs, which can be
74 * retrieved based on a key, in logarithmic time.
76 * @ingroup associative_containers
78 * @tparam _Key Type of key objects.
79 * @tparam _Tp Type of mapped objects.
80 * @tparam _Compare Comparison function object type, defaults to less<_Key>.
81 * @tparam _Alloc Allocator type, defaults to
82 * allocator<pair<const _Key, _Tp>.
84 * Meets the requirements of a <a href="tables.html#65">container</a>, a
85 * <a href="tables.html#66">reversible container</a>, and an
86 * <a href="tables.html#69">associative container</a> (using equivalent
87 * keys). For a @c multimap<Key,T> the key_type is Key, the mapped_type
88 * is T, and the value_type is std::pair<const Key,T>.
90 * Multimaps support bidirectional iterators.
92 * The private tree data is declared exactly the same way for map and
93 * multimap; the distinction is made entirely in how the tree functions are
94 * called (*_unique versus *_equal, same as the standard).
96 template <typename _Key
, typename _Tp
,
97 typename _Compare
= std::less
<_Key
>,
98 typename _Alloc
= std::allocator
<std::pair
<const _Key
, _Tp
> > >
102 typedef _Key key_type
;
103 typedef _Tp mapped_type
;
104 typedef std::pair
<const _Key
, _Tp
> value_type
;
105 typedef _Compare key_compare
;
106 typedef _Alloc allocator_type
;
109 #ifdef _GLIBCXX_CONCEPT_CHECKS
110 // concept requirements
111 typedef typename
_Alloc::value_type _Alloc_value_type
;
112 # if __cplusplus < 201103L
113 __glibcxx_class_requires(_Tp
, _SGIAssignableConcept
)
115 __glibcxx_class_requires4(_Compare
, bool, _Key
, _Key
,
116 _BinaryFunctionConcept
)
117 __glibcxx_class_requires2(value_type
, _Alloc_value_type
, _SameTypeConcept
)
122 : public std::binary_function
<value_type
, value_type
, bool>
124 friend class multimap
<_Key
, _Tp
, _Compare
, _Alloc
>;
128 value_compare(_Compare __c
)
132 bool operator()(const value_type
& __x
, const value_type
& __y
) const
133 { return comp(__x
.first
, __y
.first
); }
137 /// This turns a red-black tree into a [multi]map.
138 typedef typename
__gnu_cxx::__alloc_traits
<_Alloc
>::template
139 rebind
<value_type
>::other _Pair_alloc_type
;
141 typedef _Rb_tree
<key_type
, value_type
, _Select1st
<value_type
>,
142 key_compare
, _Pair_alloc_type
> _Rep_type
;
143 /// The actual tree structure.
146 typedef __gnu_cxx::__alloc_traits
<_Pair_alloc_type
> _Alloc_traits
;
149 // many of these are specified differently in ISO, but the following are
150 // "functionally equivalent"
151 typedef typename
_Alloc_traits::pointer pointer
;
152 typedef typename
_Alloc_traits::const_pointer const_pointer
;
153 typedef typename
_Alloc_traits::reference reference
;
154 typedef typename
_Alloc_traits::const_reference const_reference
;
155 typedef typename
_Rep_type::iterator iterator
;
156 typedef typename
_Rep_type::const_iterator const_iterator
;
157 typedef typename
_Rep_type::size_type size_type
;
158 typedef typename
_Rep_type::difference_type difference_type
;
159 typedef typename
_Rep_type::reverse_iterator reverse_iterator
;
160 typedef typename
_Rep_type::const_reverse_iterator const_reverse_iterator
;
162 #if __cplusplus > 201402L
163 using node_type
= typename
_Rep_type::node_type
;
166 // [23.3.2] construct/copy/destroy
167 // (get_allocator() is also listed in this section)
170 * @brief Default constructor creates no elements.
172 #if __cplusplus < 201103L
173 multimap() : _M_t() { }
175 multimap() = default;
179 * @brief Creates a %multimap with no elements.
180 * @param __comp A comparison object.
181 * @param __a An allocator object.
184 multimap(const _Compare
& __comp
,
185 const allocator_type
& __a
= allocator_type())
186 : _M_t(__comp
, _Pair_alloc_type(__a
)) { }
189 * @brief %Multimap copy constructor.
191 * Whether the allocator is copied depends on the allocator traits.
193 #if __cplusplus < 201103L
194 multimap(const multimap
& __x
)
197 multimap(const multimap
&) = default;
200 * @brief %Multimap move constructor.
202 * The newly-created %multimap contains the exact contents of the
203 * moved instance. The moved instance is a valid, but unspecified
206 multimap(multimap
&&) = default;
209 * @brief Builds a %multimap from an initializer_list.
210 * @param __l An initializer_list.
211 * @param __comp A comparison functor.
212 * @param __a An allocator object.
214 * Create a %multimap consisting of copies of the elements from
215 * the initializer_list. This is linear in N if the list is already
216 * sorted, and NlogN otherwise (where N is @a __l.size()).
218 multimap(initializer_list
<value_type
> __l
,
219 const _Compare
& __comp
= _Compare(),
220 const allocator_type
& __a
= allocator_type())
221 : _M_t(__comp
, _Pair_alloc_type(__a
))
222 { _M_t
._M_insert_equal(__l
.begin(), __l
.end()); }
224 /// Allocator-extended default constructor.
226 multimap(const allocator_type
& __a
)
227 : _M_t(_Compare(), _Pair_alloc_type(__a
)) { }
229 /// Allocator-extended copy constructor.
230 multimap(const multimap
& __m
, const allocator_type
& __a
)
231 : _M_t(__m
._M_t
, _Pair_alloc_type(__a
)) { }
233 /// Allocator-extended move constructor.
234 multimap(multimap
&& __m
, const allocator_type
& __a
)
235 noexcept(is_nothrow_copy_constructible
<_Compare
>::value
236 && _Alloc_traits::_S_always_equal())
237 : _M_t(std::move(__m
._M_t
), _Pair_alloc_type(__a
)) { }
239 /// Allocator-extended initialier-list constructor.
240 multimap(initializer_list
<value_type
> __l
, const allocator_type
& __a
)
241 : _M_t(_Compare(), _Pair_alloc_type(__a
))
242 { _M_t
._M_insert_equal(__l
.begin(), __l
.end()); }
244 /// Allocator-extended range constructor.
245 template<typename _InputIterator
>
246 multimap(_InputIterator __first
, _InputIterator __last
,
247 const allocator_type
& __a
)
248 : _M_t(_Compare(), _Pair_alloc_type(__a
))
249 { _M_t
._M_insert_equal(__first
, __last
); }
253 * @brief Builds a %multimap from a range.
254 * @param __first An input iterator.
255 * @param __last An input iterator.
257 * Create a %multimap consisting of copies of the elements from
258 * [__first,__last). This is linear in N if the range is already sorted,
259 * and NlogN otherwise (where N is distance(__first,__last)).
261 template<typename _InputIterator
>
262 multimap(_InputIterator __first
, _InputIterator __last
)
264 { _M_t
._M_insert_equal(__first
, __last
); }
267 * @brief Builds a %multimap from a range.
268 * @param __first An input iterator.
269 * @param __last An input iterator.
270 * @param __comp A comparison functor.
271 * @param __a An allocator object.
273 * Create a %multimap consisting of copies of the elements from
274 * [__first,__last). This is linear in N if the range is already sorted,
275 * and NlogN otherwise (where N is distance(__first,__last)).
277 template<typename _InputIterator
>
278 multimap(_InputIterator __first
, _InputIterator __last
,
279 const _Compare
& __comp
,
280 const allocator_type
& __a
= allocator_type())
281 : _M_t(__comp
, _Pair_alloc_type(__a
))
282 { _M_t
._M_insert_equal(__first
, __last
); }
284 #if __cplusplus >= 201103L
286 * The dtor only erases the elements, and note that if the elements
287 * themselves are pointers, the pointed-to memory is not touched in any
288 * way. Managing the pointer is the user's responsibility.
290 ~multimap() = default;
294 * @brief %Multimap assignment operator.
296 * Whether the allocator is copied depends on the allocator traits.
298 #if __cplusplus < 201103L
300 operator=(const multimap
& __x
)
307 operator=(const multimap
&) = default;
309 /// Move assignment operator.
311 operator=(multimap
&&) = default;
314 * @brief %Multimap list assignment operator.
315 * @param __l An initializer_list.
317 * This function fills a %multimap with copies of the elements
318 * in the initializer list @a __l.
320 * Note that the assignment completely changes the %multimap and
321 * that the resulting %multimap's size is the same as the number
322 * of elements assigned.
325 operator=(initializer_list
<value_type
> __l
)
327 _M_t
._M_assign_equal(__l
.begin(), __l
.end());
332 /// Get a copy of the memory allocation object.
334 get_allocator() const _GLIBCXX_NOEXCEPT
335 { return allocator_type(_M_t
.get_allocator()); }
339 * Returns a read/write iterator that points to the first pair in the
340 * %multimap. Iteration is done in ascending order according to the
344 begin() _GLIBCXX_NOEXCEPT
345 { return _M_t
.begin(); }
348 * Returns a read-only (constant) iterator that points to the first pair
349 * in the %multimap. Iteration is done in ascending order according to
353 begin() const _GLIBCXX_NOEXCEPT
354 { return _M_t
.begin(); }
357 * Returns a read/write iterator that points one past the last pair in
358 * the %multimap. Iteration is done in ascending order according to the
362 end() _GLIBCXX_NOEXCEPT
363 { return _M_t
.end(); }
366 * Returns a read-only (constant) iterator that points one past the last
367 * pair in the %multimap. Iteration is done in ascending order according
371 end() const _GLIBCXX_NOEXCEPT
372 { return _M_t
.end(); }
375 * Returns a read/write reverse iterator that points to the last pair in
376 * the %multimap. Iteration is done in descending order according to the
380 rbegin() _GLIBCXX_NOEXCEPT
381 { return _M_t
.rbegin(); }
384 * Returns a read-only (constant) reverse iterator that points to the
385 * last pair in the %multimap. Iteration is done in descending order
386 * according to the keys.
388 const_reverse_iterator
389 rbegin() const _GLIBCXX_NOEXCEPT
390 { return _M_t
.rbegin(); }
393 * Returns a read/write reverse iterator that points to one before the
394 * first pair in the %multimap. Iteration is done in descending order
395 * according to the keys.
398 rend() _GLIBCXX_NOEXCEPT
399 { return _M_t
.rend(); }
402 * Returns a read-only (constant) reverse iterator that points to one
403 * before the first pair in the %multimap. Iteration is done in
404 * descending order according to the keys.
406 const_reverse_iterator
407 rend() const _GLIBCXX_NOEXCEPT
408 { return _M_t
.rend(); }
410 #if __cplusplus >= 201103L
412 * Returns a read-only (constant) iterator that points to the first pair
413 * in the %multimap. Iteration is done in ascending order according to
417 cbegin() const noexcept
418 { return _M_t
.begin(); }
421 * Returns a read-only (constant) iterator that points one past the last
422 * pair in the %multimap. Iteration is done in ascending order according
426 cend() const noexcept
427 { return _M_t
.end(); }
430 * Returns a read-only (constant) reverse iterator that points to the
431 * last pair in the %multimap. Iteration is done in descending order
432 * according to the keys.
434 const_reverse_iterator
435 crbegin() const noexcept
436 { return _M_t
.rbegin(); }
439 * Returns a read-only (constant) reverse iterator that points to one
440 * before the first pair in the %multimap. Iteration is done in
441 * descending order according to the keys.
443 const_reverse_iterator
444 crend() const noexcept
445 { return _M_t
.rend(); }
449 /** Returns true if the %multimap is empty. */
451 empty() const _GLIBCXX_NOEXCEPT
452 { return _M_t
.empty(); }
454 /** Returns the size of the %multimap. */
456 size() const _GLIBCXX_NOEXCEPT
457 { return _M_t
.size(); }
459 /** Returns the maximum size of the %multimap. */
461 max_size() const _GLIBCXX_NOEXCEPT
462 { return _M_t
.max_size(); }
465 #if __cplusplus >= 201103L
467 * @brief Build and insert a std::pair into the %multimap.
469 * @param __args Arguments used to generate a new pair instance (see
470 * std::piecewise_contruct for passing arguments to each
471 * part of the pair constructor).
473 * @return An iterator that points to the inserted (key,value) pair.
475 * This function builds and inserts a (key, value) %pair into the
477 * Contrary to a std::map the %multimap does not rely on unique keys and
478 * thus multiple pairs with the same key can be inserted.
480 * Insertion requires logarithmic time.
482 template<typename
... _Args
>
484 emplace(_Args
&&... __args
)
485 { return _M_t
._M_emplace_equal(std::forward
<_Args
>(__args
)...); }
488 * @brief Builds and inserts a std::pair into the %multimap.
490 * @param __pos An iterator that serves as a hint as to where the pair
491 * should be inserted.
492 * @param __args Arguments used to generate a new pair instance (see
493 * std::piecewise_contruct for passing arguments to each
494 * part of the pair constructor).
495 * @return An iterator that points to the inserted (key,value) pair.
497 * This function inserts a (key, value) pair into the %multimap.
498 * Contrary to a std::map the %multimap does not rely on unique keys and
499 * thus multiple pairs with the same key can be inserted.
500 * Note that the first parameter is only a hint and can potentially
501 * improve the performance of the insertion process. A bad hint would
502 * cause no gains in efficiency.
504 * For more on @a hinting, see:
505 * https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints
507 * Insertion requires logarithmic time (if the hint is not taken).
509 template<typename
... _Args
>
511 emplace_hint(const_iterator __pos
, _Args
&&... __args
)
513 return _M_t
._M_emplace_hint_equal(__pos
,
514 std::forward
<_Args
>(__args
)...);
519 * @brief Inserts a std::pair into the %multimap.
520 * @param __x Pair to be inserted (see std::make_pair for easy creation
522 * @return An iterator that points to the inserted (key,value) pair.
524 * This function inserts a (key, value) pair into the %multimap.
525 * Contrary to a std::map the %multimap does not rely on unique keys and
526 * thus multiple pairs with the same key can be inserted.
528 * Insertion requires logarithmic time.
532 insert(const value_type
& __x
)
533 { return _M_t
._M_insert_equal(__x
); }
535 #if __cplusplus >= 201103L
536 // _GLIBCXX_RESOLVE_LIB_DEFECTS
537 // 2354. Unnecessary copying when inserting into maps with braced-init
539 insert(value_type
&& __x
)
540 { return _M_t
._M_insert_equal(std::move(__x
)); }
542 template<typename _Pair
, typename
= typename
543 std::enable_if
<std::is_constructible
<value_type
,
544 _Pair
&&>::value
>::type
>
547 { return _M_t
._M_insert_equal(std::forward
<_Pair
>(__x
)); }
552 * @brief Inserts a std::pair into the %multimap.
553 * @param __position An iterator that serves as a hint as to where the
554 * pair should be inserted.
555 * @param __x Pair to be inserted (see std::make_pair for easy creation
557 * @return An iterator that points to the inserted (key,value) pair.
559 * This function inserts a (key, value) pair into the %multimap.
560 * Contrary to a std::map the %multimap does not rely on unique keys and
561 * thus multiple pairs with the same key can be inserted.
562 * Note that the first parameter is only a hint and can potentially
563 * improve the performance of the insertion process. A bad hint would
564 * cause no gains in efficiency.
566 * For more on @a hinting, see:
567 * https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints
569 * Insertion requires logarithmic time (if the hint is not taken).
573 #if __cplusplus >= 201103L
574 insert(const_iterator __position
, const value_type
& __x
)
576 insert(iterator __position
, const value_type
& __x
)
578 { return _M_t
._M_insert_equal_(__position
, __x
); }
580 #if __cplusplus >= 201103L
581 // _GLIBCXX_RESOLVE_LIB_DEFECTS
582 // 2354. Unnecessary copying when inserting into maps with braced-init
584 insert(const_iterator __position
, value_type
&& __x
)
585 { return _M_t
._M_insert_equal_(__position
, std::move(__x
)); }
587 template<typename _Pair
, typename
= typename
588 std::enable_if
<std::is_constructible
<value_type
,
589 _Pair
&&>::value
>::type
>
591 insert(const_iterator __position
, _Pair
&& __x
)
592 { return _M_t
._M_insert_equal_(__position
,
593 std::forward
<_Pair
>(__x
)); }
598 * @brief A template function that attempts to insert a range
600 * @param __first Iterator pointing to the start of the range to be
602 * @param __last Iterator pointing to the end of the range.
604 * Complexity similar to that of the range constructor.
606 template<typename _InputIterator
>
608 insert(_InputIterator __first
, _InputIterator __last
)
609 { _M_t
._M_insert_equal(__first
, __last
); }
611 #if __cplusplus >= 201103L
613 * @brief Attempts to insert a list of std::pairs into the %multimap.
614 * @param __l A std::initializer_list<value_type> of pairs to be
617 * Complexity similar to that of the range constructor.
620 insert(initializer_list
<value_type
> __l
)
621 { this->insert(__l
.begin(), __l
.end()); }
624 #if __cplusplus > 201402L
627 extract(const_iterator __pos
)
629 __glibcxx_assert(__pos
!= end());
630 return _M_t
.extract(__pos
);
635 extract(const key_type
& __x
)
636 { return _M_t
.extract(__x
); }
638 /// Re-insert an extracted node.
640 insert(node_type
&& __nh
)
641 { return _M_t
._M_reinsert_node_equal(std::move(__nh
)); }
643 /// Re-insert an extracted node.
645 insert(const_iterator __hint
, node_type
&& __nh
)
646 { return _M_t
._M_reinsert_node_hint_equal(__hint
, std::move(__nh
)); }
648 template<typename
, typename
>
649 friend class _Rb_tree_merge_helper
;
651 template<typename _C2
>
653 merge(multimap
<_Key
, _Tp
, _C2
, _Alloc
>& __source
)
655 using _Merge_helper
= _Rb_tree_merge_helper
<multimap
, _C2
>;
656 _M_t
._M_merge_equal(_Merge_helper::_S_get_tree(__source
));
659 template<typename _C2
>
661 merge(multimap
<_Key
, _Tp
, _C2
, _Alloc
>&& __source
)
664 template<typename _C2
>
666 merge(map
<_Key
, _Tp
, _C2
, _Alloc
>& __source
)
668 using _Merge_helper
= _Rb_tree_merge_helper
<multimap
, _C2
>;
669 _M_t
._M_merge_equal(_Merge_helper::_S_get_tree(__source
));
672 template<typename _C2
>
674 merge(map
<_Key
, _Tp
, _C2
, _Alloc
>&& __source
)
678 #if __cplusplus >= 201103L
679 // _GLIBCXX_RESOLVE_LIB_DEFECTS
680 // DR 130. Associative erase should return an iterator.
682 * @brief Erases an element from a %multimap.
683 * @param __position An iterator pointing to the element to be erased.
684 * @return An iterator pointing to the element immediately following
685 * @a position prior to the element being erased. If no such
686 * element exists, end() is returned.
688 * This function erases an element, pointed to by the given iterator,
689 * from a %multimap. Note that this function only erases the element,
690 * and that if the element is itself a pointer, the pointed-to memory is
691 * not touched in any way. Managing the pointer is the user's
697 erase(const_iterator __position
)
698 { return _M_t
.erase(__position
); }
701 _GLIBCXX_ABI_TAG_CXX11
703 erase(iterator __position
)
704 { return _M_t
.erase(__position
); }
708 * @brief Erases an element from a %multimap.
709 * @param __position An iterator pointing to the element to be erased.
711 * This function erases an element, pointed to by the given iterator,
712 * from a %multimap. Note that this function only erases the element,
713 * and that if the element is itself a pointer, the pointed-to memory is
714 * not touched in any way. Managing the pointer is the user's
718 erase(iterator __position
)
719 { _M_t
.erase(__position
); }
723 * @brief Erases elements according to the provided key.
724 * @param __x Key of element to be erased.
725 * @return The number of elements erased.
727 * This function erases all elements located by the given key from a
729 * Note that this function only erases the element, and that if
730 * the element is itself a pointer, the pointed-to memory is not touched
731 * in any way. Managing the pointer is the user's responsibility.
734 erase(const key_type
& __x
)
735 { return _M_t
.erase(__x
); }
737 #if __cplusplus >= 201103L
738 // _GLIBCXX_RESOLVE_LIB_DEFECTS
739 // DR 130. Associative erase should return an iterator.
741 * @brief Erases a [first,last) range of elements from a %multimap.
742 * @param __first Iterator pointing to the start of the range to be
744 * @param __last Iterator pointing to the end of the range to be
746 * @return The iterator @a __last.
748 * This function erases a sequence of elements from a %multimap.
749 * Note that this function only erases the elements, and that if
750 * the elements themselves are pointers, the pointed-to memory is not
751 * touched in any way. Managing the pointer is the user's
755 erase(const_iterator __first
, const_iterator __last
)
756 { return _M_t
.erase(__first
, __last
); }
758 // _GLIBCXX_RESOLVE_LIB_DEFECTS
759 // DR 130. Associative erase should return an iterator.
761 * @brief Erases a [first,last) range of elements from a %multimap.
762 * @param __first Iterator pointing to the start of the range to be
764 * @param __last Iterator pointing to the end of the range to
767 * This function erases a sequence of elements from a %multimap.
768 * Note that this function only erases the elements, and that if
769 * the elements themselves are pointers, the pointed-to memory is not
770 * touched in any way. Managing the pointer is the user's
774 erase(iterator __first
, iterator __last
)
775 { _M_t
.erase(__first
, __last
); }
779 * @brief Swaps data with another %multimap.
780 * @param __x A %multimap of the same element and allocator types.
782 * This exchanges the elements between two multimaps in constant time.
783 * (It is only swapping a pointer, an integer, and an instance of
784 * the @c Compare type (which itself is often stateless and empty), so it
785 * should be quite fast.)
786 * Note that the global std::swap() function is specialized such that
787 * std::swap(m1,m2) will feed to this function.
789 * Whether the allocators are swapped depends on the allocator traits.
793 _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable
<_Compare
>::value
)
794 { _M_t
.swap(__x
._M_t
); }
797 * Erases all elements in a %multimap. Note that this function only
798 * erases the elements, and that if the elements themselves are pointers,
799 * the pointed-to memory is not touched in any way. Managing the pointer
800 * is the user's responsibility.
803 clear() _GLIBCXX_NOEXCEPT
808 * Returns the key comparison object out of which the %multimap
813 { return _M_t
.key_comp(); }
816 * Returns a value comparison object, built from the key comparison
817 * object out of which the %multimap was constructed.
821 { return value_compare(_M_t
.key_comp()); }
823 // multimap operations
827 * @brief Tries to locate an element in a %multimap.
828 * @param __x Key of (key, value) pair to be located.
829 * @return Iterator pointing to sought-after element,
830 * or end() if not found.
832 * This function takes a key and tries to locate the element with which
833 * the key matches. If successful the function returns an iterator
834 * pointing to the sought after %pair. If unsuccessful it returns the
835 * past-the-end ( @c end() ) iterator.
838 find(const key_type
& __x
)
839 { return _M_t
.find(__x
); }
841 #if __cplusplus > 201103L
842 template<typename _Kt
>
844 find(const _Kt
& __x
) -> decltype(_M_t
._M_find_tr(__x
))
845 { return _M_t
._M_find_tr(__x
); }
851 * @brief Tries to locate an element in a %multimap.
852 * @param __x Key of (key, value) pair to be located.
853 * @return Read-only (constant) iterator pointing to sought-after
854 * element, or end() if not found.
856 * This function takes a key and tries to locate the element with which
857 * the key matches. If successful the function returns a constant
858 * iterator pointing to the sought after %pair. If unsuccessful it
859 * returns the past-the-end ( @c end() ) iterator.
862 find(const key_type
& __x
) const
863 { return _M_t
.find(__x
); }
865 #if __cplusplus > 201103L
866 template<typename _Kt
>
868 find(const _Kt
& __x
) const -> decltype(_M_t
._M_find_tr(__x
))
869 { return _M_t
._M_find_tr(__x
); }
875 * @brief Finds the number of elements with given key.
876 * @param __x Key of (key, value) pairs to be located.
877 * @return Number of elements with specified key.
880 count(const key_type
& __x
) const
881 { return _M_t
.count(__x
); }
883 #if __cplusplus > 201103L
884 template<typename _Kt
>
886 count(const _Kt
& __x
) const -> decltype(_M_t
._M_count_tr(__x
))
887 { return _M_t
._M_count_tr(__x
); }
893 * @brief Finds the beginning of a subsequence matching given key.
894 * @param __x Key of (key, value) pair to be located.
895 * @return Iterator pointing to first element equal to or greater
896 * than key, or end().
898 * This function returns the first element of a subsequence of elements
899 * that matches the given key. If unsuccessful it returns an iterator
900 * pointing to the first element that has a greater value than given key
901 * or end() if no such element exists.
904 lower_bound(const key_type
& __x
)
905 { return _M_t
.lower_bound(__x
); }
907 #if __cplusplus > 201103L
908 template<typename _Kt
>
910 lower_bound(const _Kt
& __x
)
911 -> decltype(iterator(_M_t
._M_lower_bound_tr(__x
)))
912 { return iterator(_M_t
._M_lower_bound_tr(__x
)); }
918 * @brief Finds the beginning of a subsequence matching given key.
919 * @param __x Key of (key, value) pair to be located.
920 * @return Read-only (constant) iterator pointing to first element
921 * equal to or greater than key, or end().
923 * This function returns the first element of a subsequence of
924 * elements that matches the given key. If unsuccessful the
925 * iterator will point to the next greatest element or, if no
926 * such greater element exists, to end().
929 lower_bound(const key_type
& __x
) const
930 { return _M_t
.lower_bound(__x
); }
932 #if __cplusplus > 201103L
933 template<typename _Kt
>
935 lower_bound(const _Kt
& __x
) const
936 -> decltype(const_iterator(_M_t
._M_lower_bound_tr(__x
)))
937 { return const_iterator(_M_t
._M_lower_bound_tr(__x
)); }
943 * @brief Finds the end of a subsequence matching given key.
944 * @param __x Key of (key, value) pair to be located.
945 * @return Iterator pointing to the first element
946 * greater than key, or end().
949 upper_bound(const key_type
& __x
)
950 { return _M_t
.upper_bound(__x
); }
952 #if __cplusplus > 201103L
953 template<typename _Kt
>
955 upper_bound(const _Kt
& __x
)
956 -> decltype(iterator(_M_t
._M_upper_bound_tr(__x
)))
957 { return iterator(_M_t
._M_upper_bound_tr(__x
)); }
963 * @brief Finds the end of a subsequence matching given key.
964 * @param __x Key of (key, value) pair to be located.
965 * @return Read-only (constant) iterator pointing to first iterator
966 * greater than key, or end().
969 upper_bound(const key_type
& __x
) const
970 { return _M_t
.upper_bound(__x
); }
972 #if __cplusplus > 201103L
973 template<typename _Kt
>
975 upper_bound(const _Kt
& __x
) const
976 -> decltype(const_iterator(_M_t
._M_upper_bound_tr(__x
)))
977 { return const_iterator(_M_t
._M_upper_bound_tr(__x
)); }
983 * @brief Finds a subsequence matching given key.
984 * @param __x Key of (key, value) pairs to be located.
985 * @return Pair of iterators that possibly points to the subsequence
986 * matching given key.
988 * This function is equivalent to
990 * std::make_pair(c.lower_bound(val),
991 * c.upper_bound(val))
993 * (but is faster than making the calls separately).
995 std::pair
<iterator
, iterator
>
996 equal_range(const key_type
& __x
)
997 { return _M_t
.equal_range(__x
); }
999 #if __cplusplus > 201103L
1000 template<typename _Kt
>
1002 equal_range(const _Kt
& __x
)
1003 -> decltype(pair
<iterator
, iterator
>(_M_t
._M_equal_range_tr(__x
)))
1004 { return pair
<iterator
, iterator
>(_M_t
._M_equal_range_tr(__x
)); }
1010 * @brief Finds a subsequence matching given key.
1011 * @param __x Key of (key, value) pairs to be located.
1012 * @return Pair of read-only (constant) iterators that possibly points
1013 * to the subsequence matching given key.
1015 * This function is equivalent to
1017 * std::make_pair(c.lower_bound(val),
1018 * c.upper_bound(val))
1020 * (but is faster than making the calls separately).
1022 std::pair
<const_iterator
, const_iterator
>
1023 equal_range(const key_type
& __x
) const
1024 { return _M_t
.equal_range(__x
); }
1026 #if __cplusplus > 201103L
1027 template<typename _Kt
>
1029 equal_range(const _Kt
& __x
) const
1030 -> decltype(pair
<const_iterator
, const_iterator
>(
1031 _M_t
._M_equal_range_tr(__x
)))
1033 return pair
<const_iterator
, const_iterator
>(
1034 _M_t
._M_equal_range_tr(__x
));
1039 template<typename _K1
, typename _T1
, typename _C1
, typename _A1
>
1041 operator==(const multimap
<_K1
, _T1
, _C1
, _A1
>&,
1042 const multimap
<_K1
, _T1
, _C1
, _A1
>&);
1044 template<typename _K1
, typename _T1
, typename _C1
, typename _A1
>
1046 operator<(const multimap
<_K1
, _T1
, _C1
, _A1
>&,
1047 const multimap
<_K1
, _T1
, _C1
, _A1
>&);
1051 * @brief Multimap equality comparison.
1052 * @param __x A %multimap.
1053 * @param __y A %multimap of the same type as @a __x.
1054 * @return True iff the size and elements of the maps are equal.
1056 * This is an equivalence relation. It is linear in the size of the
1057 * multimaps. Multimaps are considered equivalent if their sizes are equal,
1058 * and if corresponding elements compare equal.
1060 template<typename _Key
, typename _Tp
, typename _Compare
, typename _Alloc
>
1062 operator==(const multimap
<_Key
, _Tp
, _Compare
, _Alloc
>& __x
,
1063 const multimap
<_Key
, _Tp
, _Compare
, _Alloc
>& __y
)
1064 { return __x
._M_t
== __y
._M_t
; }
1067 * @brief Multimap ordering relation.
1068 * @param __x A %multimap.
1069 * @param __y A %multimap of the same type as @a __x.
1070 * @return True iff @a x is lexicographically less than @a y.
1072 * This is a total ordering relation. It is linear in the size of the
1073 * multimaps. The elements must be comparable with @c <.
1075 * See std::lexicographical_compare() for how the determination is made.
1077 template<typename _Key
, typename _Tp
, typename _Compare
, typename _Alloc
>
1079 operator<(const multimap
<_Key
, _Tp
, _Compare
, _Alloc
>& __x
,
1080 const multimap
<_Key
, _Tp
, _Compare
, _Alloc
>& __y
)
1081 { return __x
._M_t
< __y
._M_t
; }
1083 /// Based on operator==
1084 template<typename _Key
, typename _Tp
, typename _Compare
, typename _Alloc
>
1086 operator!=(const multimap
<_Key
, _Tp
, _Compare
, _Alloc
>& __x
,
1087 const multimap
<_Key
, _Tp
, _Compare
, _Alloc
>& __y
)
1088 { return !(__x
== __y
); }
1090 /// Based on operator<
1091 template<typename _Key
, typename _Tp
, typename _Compare
, typename _Alloc
>
1093 operator>(const multimap
<_Key
, _Tp
, _Compare
, _Alloc
>& __x
,
1094 const multimap
<_Key
, _Tp
, _Compare
, _Alloc
>& __y
)
1095 { return __y
< __x
; }
1097 /// Based on operator<
1098 template<typename _Key
, typename _Tp
, typename _Compare
, typename _Alloc
>
1100 operator<=(const multimap
<_Key
, _Tp
, _Compare
, _Alloc
>& __x
,
1101 const multimap
<_Key
, _Tp
, _Compare
, _Alloc
>& __y
)
1102 { return !(__y
< __x
); }
1104 /// Based on operator<
1105 template<typename _Key
, typename _Tp
, typename _Compare
, typename _Alloc
>
1107 operator>=(const multimap
<_Key
, _Tp
, _Compare
, _Alloc
>& __x
,
1108 const multimap
<_Key
, _Tp
, _Compare
, _Alloc
>& __y
)
1109 { return !(__x
< __y
); }
1111 /// See std::multimap::swap().
1112 template<typename _Key
, typename _Tp
, typename _Compare
, typename _Alloc
>
1114 swap(multimap
<_Key
, _Tp
, _Compare
, _Alloc
>& __x
,
1115 multimap
<_Key
, _Tp
, _Compare
, _Alloc
>& __y
)
1116 _GLIBCXX_NOEXCEPT_IF(noexcept(__x
.swap(__y
)))
1119 _GLIBCXX_END_NAMESPACE_CONTAINER
1121 #if __cplusplus > 201402L
1122 // Allow std::multimap access to internals of compatible maps.
1123 template<typename _Key
, typename _Val
, typename _Cmp1
, typename _Alloc
,
1126 _Rb_tree_merge_helper
<_GLIBCXX_STD_C::multimap
<_Key
, _Val
, _Cmp1
, _Alloc
>,
1130 friend class _GLIBCXX_STD_C::multimap
<_Key
, _Val
, _Cmp1
, _Alloc
>;
1133 _S_get_tree(_GLIBCXX_STD_C::map
<_Key
, _Val
, _Cmp2
, _Alloc
>& __map
)
1134 { return __map
._M_t
; }
1137 _S_get_tree(_GLIBCXX_STD_C::multimap
<_Key
, _Val
, _Cmp2
, _Alloc
>& __map
)
1138 { return __map
._M_t
; }
1142 _GLIBCXX_END_NAMESPACE_VERSION
1145 #endif /* _STL_MULTIMAP_H */