1 // Multimap implementation -*- C++ -*-
3 // Copyright (C) 2001-2013 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_CONTAINER
69 * @brief A standard container made up of (key,value) pairs, which can be
70 * retrieved based on a key, in logarithmic time.
72 * @ingroup associative_containers
74 * @tparam _Key Type of key objects.
75 * @tparam _Tp Type of mapped objects.
76 * @tparam _Compare Comparison function object type, defaults to less<_Key>.
77 * @tparam _Alloc Allocator type, defaults to
78 * allocator<pair<const _Key, _Tp>.
80 * Meets the requirements of a <a href="tables.html#65">container</a>, a
81 * <a href="tables.html#66">reversible container</a>, and an
82 * <a href="tables.html#69">associative container</a> (using equivalent
83 * keys). For a @c multimap<Key,T> the key_type is Key, the mapped_type
84 * is T, and the value_type is std::pair<const Key,T>.
86 * Multimaps support bidirectional iterators.
88 * The private tree data is declared exactly the same way for map and
89 * multimap; the distinction is made entirely in how the tree functions are
90 * called (*_unique versus *_equal, same as the standard).
92 template <typename _Key
, typename _Tp
,
93 typename _Compare
= std::less
<_Key
>,
94 typename _Alloc
= std::allocator
<std::pair
<const _Key
, _Tp
> > >
98 typedef _Key key_type
;
99 typedef _Tp mapped_type
;
100 typedef std::pair
<const _Key
, _Tp
> value_type
;
101 typedef _Compare key_compare
;
102 typedef _Alloc allocator_type
;
105 // concept requirements
106 typedef typename
_Alloc::value_type _Alloc_value_type
;
107 __glibcxx_class_requires(_Tp
, _SGIAssignableConcept
)
108 __glibcxx_class_requires4(_Compare
, bool, _Key
, _Key
,
109 _BinaryFunctionConcept
)
110 __glibcxx_class_requires2(value_type
, _Alloc_value_type
, _SameTypeConcept
)
114 : public std::binary_function
<value_type
, value_type
, bool>
116 friend class multimap
<_Key
, _Tp
, _Compare
, _Alloc
>;
120 value_compare(_Compare __c
)
124 bool operator()(const value_type
& __x
, const value_type
& __y
) const
125 { return comp(__x
.first
, __y
.first
); }
129 /// This turns a red-black tree into a [multi]map.
130 typedef typename
__gnu_cxx::__alloc_traits
<_Alloc
>::template
131 rebind
<value_type
>::other _Pair_alloc_type
;
133 typedef _Rb_tree
<key_type
, value_type
, _Select1st
<value_type
>,
134 key_compare
, _Pair_alloc_type
> _Rep_type
;
135 /// The actual tree structure.
138 typedef __gnu_cxx::__alloc_traits
<_Pair_alloc_type
> _Alloc_traits
;
141 // many of these are specified differently in ISO, but the following are
142 // "functionally equivalent"
143 typedef typename
_Alloc_traits::pointer pointer
;
144 typedef typename
_Alloc_traits::const_pointer const_pointer
;
145 typedef typename
_Alloc_traits::reference reference
;
146 typedef typename
_Alloc_traits::const_reference const_reference
;
147 typedef typename
_Rep_type::iterator iterator
;
148 typedef typename
_Rep_type::const_iterator const_iterator
;
149 typedef typename
_Rep_type::size_type size_type
;
150 typedef typename
_Rep_type::difference_type difference_type
;
151 typedef typename
_Rep_type::reverse_iterator reverse_iterator
;
152 typedef typename
_Rep_type::const_reverse_iterator const_reverse_iterator
;
154 // [23.3.2] construct/copy/destroy
155 // (get_allocator() is also listed in this section)
157 * @brief Default constructor creates no elements.
163 * @brief Creates a %multimap with no elements.
164 * @param __comp A comparison object.
165 * @param __a An allocator object.
168 multimap(const _Compare
& __comp
,
169 const allocator_type
& __a
= allocator_type())
170 : _M_t(__comp
, _Pair_alloc_type(__a
)) { }
173 * @brief %Multimap copy constructor.
174 * @param __x A %multimap of identical element and allocator types.
176 * The newly-created %multimap uses a copy of the allocation object
179 multimap(const multimap
& __x
)
182 #if __cplusplus >= 201103L
184 * @brief %Multimap move constructor.
185 * @param __x A %multimap of identical element and allocator types.
187 * The newly-created %multimap contains the exact contents of @a __x.
188 * The contents of @a __x are a valid, but unspecified %multimap.
190 multimap(multimap
&& __x
)
191 noexcept(is_nothrow_copy_constructible
<_Compare
>::value
)
192 : _M_t(std::move(__x
._M_t
)) { }
195 * @brief Builds a %multimap from an initializer_list.
196 * @param __l An initializer_list.
197 * @param __comp A comparison functor.
198 * @param __a An allocator object.
200 * Create a %multimap consisting of copies of the elements from
201 * the initializer_list. This is linear in N if the list is already
202 * sorted, and NlogN otherwise (where N is @a __l.size()).
204 multimap(initializer_list
<value_type
> __l
,
205 const _Compare
& __comp
= _Compare(),
206 const allocator_type
& __a
= allocator_type())
207 : _M_t(__comp
, _Pair_alloc_type(__a
))
208 { _M_t
._M_insert_equal(__l
.begin(), __l
.end()); }
210 /// Allocator-extended default constructor.
212 multimap(const allocator_type
& __a
)
213 : _M_t(_Compare(), _Pair_alloc_type(__a
)) { }
215 /// Allocator-extended copy constructor.
216 multimap(const multimap
& __m
, const allocator_type
& __a
)
217 : _M_t(__m
._M_t
, _Pair_alloc_type(__a
)) { }
219 /// Allocator-extended move constructor.
220 multimap(multimap
&& __m
, const allocator_type
& __a
)
221 noexcept(is_nothrow_copy_constructible
<_Compare
>::value
222 && _Alloc_traits::_S_always_equal())
223 : _M_t(std::move(__m
._M_t
), _Pair_alloc_type(__a
)) { }
225 /// Allocator-extended initialier-list constructor.
226 multimap(initializer_list
<value_type
> __l
, const allocator_type
& __a
)
227 : _M_t(_Compare(), _Pair_alloc_type(__a
))
228 { _M_t
._M_insert_equal(__l
.begin(), __l
.end()); }
230 /// Allocator-extended range constructor.
231 template<typename _InputIterator
>
232 multimap(_InputIterator __first
, _InputIterator __last
,
233 const allocator_type
& __a
)
234 : _M_t(_Compare(), _Pair_alloc_type(__a
))
235 { _M_t
._M_insert_equal(__first
, __last
); }
239 * @brief Builds a %multimap from a range.
240 * @param __first An input iterator.
241 * @param __last An input iterator.
243 * Create a %multimap consisting of copies of the elements from
244 * [__first,__last). This is linear in N if the range is already sorted,
245 * and NlogN otherwise (where N is distance(__first,__last)).
247 template<typename _InputIterator
>
248 multimap(_InputIterator __first
, _InputIterator __last
)
250 { _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.
256 * @param __comp A comparison functor.
257 * @param __a An allocator object.
259 * Create a %multimap consisting of copies of the elements from
260 * [__first,__last). This is linear in N if the range is already sorted,
261 * and NlogN otherwise (where N is distance(__first,__last)).
263 template<typename _InputIterator
>
264 multimap(_InputIterator __first
, _InputIterator __last
,
265 const _Compare
& __comp
,
266 const allocator_type
& __a
= allocator_type())
267 : _M_t(__comp
, _Pair_alloc_type(__a
))
268 { _M_t
._M_insert_equal(__first
, __last
); }
270 // FIXME There is no dtor declared, but we should have something generated
271 // by Doxygen. I don't know what tags to add to this paragraph to make
274 * The dtor only erases the elements, and note that if the elements
275 * themselves are pointers, the pointed-to memory is not touched in any
276 * way. Managing the pointer is the user's responsibility.
280 * @brief %Multimap assignment operator.
281 * @param __x A %multimap of identical element and allocator types.
283 * All the elements of @a __x are copied, but unlike the copy
284 * constructor, the allocator object is not copied.
287 operator=(const multimap
& __x
)
293 #if __cplusplus >= 201103L
295 * @brief %Multimap move assignment operator.
296 * @param __x A %multimap of identical element and allocator types.
298 * The contents of @a __x are moved into this multimap (without copying).
299 * @a __x is a valid, but unspecified multimap.
302 operator=(multimap
&& __x
) noexcept(_Alloc_traits::_S_nothrow_move())
304 if (!_M_t
._M_move_assign(__x
._M_t
))
306 // The rvalue's allocator cannot be moved and is not equal,
307 // so we need to individually move each element.
309 insert(std::__make_move_if_noexcept_iterator(__x
.begin()),
310 std::__make_move_if_noexcept_iterator(__x
.end()));
317 * @brief %Multimap list assignment operator.
318 * @param __l An initializer_list.
320 * This function fills a %multimap with copies of the elements
321 * in the initializer list @a __l.
323 * Note that the assignment completely changes the %multimap and
324 * that the resulting %multimap's size is the same as the number
325 * of elements assigned. Old data may be lost.
328 operator=(initializer_list
<value_type
> __l
)
331 this->insert(__l
.begin(), __l
.end());
336 /// Get a copy of the memory allocation object.
338 get_allocator() const _GLIBCXX_NOEXCEPT
339 { return allocator_type(_M_t
.get_allocator()); }
343 * Returns a read/write iterator that points to the first pair in the
344 * %multimap. Iteration is done in ascending order according to the
348 begin() _GLIBCXX_NOEXCEPT
349 { return _M_t
.begin(); }
352 * Returns a read-only (constant) iterator that points to the first pair
353 * in the %multimap. Iteration is done in ascending order according to
357 begin() const _GLIBCXX_NOEXCEPT
358 { return _M_t
.begin(); }
361 * Returns a read/write iterator that points one past the last pair in
362 * the %multimap. Iteration is done in ascending order according to the
366 end() _GLIBCXX_NOEXCEPT
367 { return _M_t
.end(); }
370 * Returns a read-only (constant) iterator that points one past the last
371 * pair in the %multimap. Iteration is done in ascending order according
375 end() const _GLIBCXX_NOEXCEPT
376 { return _M_t
.end(); }
379 * Returns a read/write reverse iterator that points to the last pair in
380 * the %multimap. Iteration is done in descending order according to the
384 rbegin() _GLIBCXX_NOEXCEPT
385 { return _M_t
.rbegin(); }
388 * Returns a read-only (constant) reverse iterator that points to the
389 * last pair in the %multimap. Iteration is done in descending order
390 * according to the keys.
392 const_reverse_iterator
393 rbegin() const _GLIBCXX_NOEXCEPT
394 { return _M_t
.rbegin(); }
397 * Returns a read/write reverse iterator that points to one before the
398 * first pair in the %multimap. Iteration is done in descending order
399 * according to the keys.
402 rend() _GLIBCXX_NOEXCEPT
403 { return _M_t
.rend(); }
406 * Returns a read-only (constant) reverse iterator that points to one
407 * before the first pair in the %multimap. Iteration is done in
408 * descending order according to the keys.
410 const_reverse_iterator
411 rend() const _GLIBCXX_NOEXCEPT
412 { return _M_t
.rend(); }
414 #if __cplusplus >= 201103L
416 * Returns a read-only (constant) iterator that points to the first pair
417 * in the %multimap. Iteration is done in ascending order according to
421 cbegin() const noexcept
422 { return _M_t
.begin(); }
425 * Returns a read-only (constant) iterator that points one past the last
426 * pair in the %multimap. Iteration is done in ascending order according
430 cend() const noexcept
431 { return _M_t
.end(); }
434 * Returns a read-only (constant) reverse iterator that points to the
435 * last pair in the %multimap. Iteration is done in descending order
436 * according to the keys.
438 const_reverse_iterator
439 crbegin() const noexcept
440 { return _M_t
.rbegin(); }
443 * Returns a read-only (constant) reverse iterator that points to one
444 * before the first pair in the %multimap. Iteration is done in
445 * descending order according to the keys.
447 const_reverse_iterator
448 crend() const noexcept
449 { return _M_t
.rend(); }
453 /** Returns true if the %multimap is empty. */
455 empty() const _GLIBCXX_NOEXCEPT
456 { return _M_t
.empty(); }
458 /** Returns the size of the %multimap. */
460 size() const _GLIBCXX_NOEXCEPT
461 { return _M_t
.size(); }
463 /** Returns the maximum size of the %multimap. */
465 max_size() const _GLIBCXX_NOEXCEPT
466 { return _M_t
.max_size(); }
469 #if __cplusplus >= 201103L
471 * @brief Build and insert a std::pair into the %multimap.
473 * @param __args Arguments used to generate a new pair instance (see
474 * std::piecewise_contruct for passing arguments to each
475 * part of the pair constructor).
477 * @return An iterator that points to the inserted (key,value) pair.
479 * This function builds and inserts a (key, value) %pair into the
481 * Contrary to a std::map the %multimap does not rely on unique keys and
482 * thus multiple pairs with the same key can be inserted.
484 * Insertion requires logarithmic time.
486 template<typename
... _Args
>
488 emplace(_Args
&&... __args
)
489 { return _M_t
._M_emplace_equal(std::forward
<_Args
>(__args
)...); }
492 * @brief Builds and inserts a std::pair into the %multimap.
494 * @param __pos An iterator that serves as a hint as to where the pair
495 * should be inserted.
496 * @param __args Arguments used to generate a new pair instance (see
497 * std::piecewise_contruct for passing arguments to each
498 * part of the pair constructor).
499 * @return An iterator that points to the inserted (key,value) pair.
501 * This function inserts a (key, value) pair into the %multimap.
502 * Contrary to a std::map the %multimap does not rely on unique keys and
503 * thus multiple pairs with the same key can be inserted.
504 * Note that the first parameter is only a hint and can potentially
505 * improve the performance of the insertion process. A bad hint would
506 * cause no gains in efficiency.
508 * For more on @a hinting, see:
509 * http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt07ch17.html
511 * Insertion requires logarithmic time (if the hint is not taken).
513 template<typename
... _Args
>
515 emplace_hint(const_iterator __pos
, _Args
&&... __args
)
517 return _M_t
._M_emplace_hint_equal(__pos
,
518 std::forward
<_Args
>(__args
)...);
523 * @brief Inserts a std::pair into the %multimap.
524 * @param __x Pair to be inserted (see std::make_pair for easy creation
526 * @return An iterator that points to the inserted (key,value) pair.
528 * This function inserts a (key, value) pair into the %multimap.
529 * Contrary to a std::map the %multimap does not rely on unique keys and
530 * thus multiple pairs with the same key can be inserted.
532 * Insertion requires logarithmic time.
535 insert(const value_type
& __x
)
536 { return _M_t
._M_insert_equal(__x
); }
538 #if __cplusplus >= 201103L
539 template<typename _Pair
, typename
= typename
540 std::enable_if
<std::is_constructible
<value_type
,
541 _Pair
&&>::value
>::type
>
544 { return _M_t
._M_insert_equal(std::forward
<_Pair
>(__x
)); }
548 * @brief Inserts a std::pair into the %multimap.
549 * @param __position An iterator that serves as a hint as to where the
550 * pair should be inserted.
551 * @param __x Pair to be inserted (see std::make_pair for easy creation
553 * @return An iterator that points to the inserted (key,value) pair.
555 * This function inserts a (key, value) pair into the %multimap.
556 * Contrary to a std::map the %multimap does not rely on unique keys and
557 * thus multiple pairs with the same key can be inserted.
558 * Note that the first parameter is only a hint and can potentially
559 * improve the performance of the insertion process. A bad hint would
560 * cause no gains in efficiency.
562 * For more on @a hinting, see:
563 * http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt07ch17.html
565 * Insertion requires logarithmic time (if the hint is not taken).
568 #if __cplusplus >= 201103L
569 insert(const_iterator __position
, const value_type
& __x
)
571 insert(iterator __position
, const value_type
& __x
)
573 { return _M_t
._M_insert_equal_(__position
, __x
); }
575 #if __cplusplus >= 201103L
576 template<typename _Pair
, typename
= typename
577 std::enable_if
<std::is_constructible
<value_type
,
578 _Pair
&&>::value
>::type
>
580 insert(const_iterator __position
, _Pair
&& __x
)
581 { return _M_t
._M_insert_equal_(__position
,
582 std::forward
<_Pair
>(__x
)); }
586 * @brief A template function that attempts to insert a range
588 * @param __first Iterator pointing to the start of the range to be
590 * @param __last Iterator pointing to the end of the range.
592 * Complexity similar to that of the range constructor.
594 template<typename _InputIterator
>
596 insert(_InputIterator __first
, _InputIterator __last
)
597 { _M_t
._M_insert_equal(__first
, __last
); }
599 #if __cplusplus >= 201103L
601 * @brief Attempts to insert a list of std::pairs into the %multimap.
602 * @param __l A std::initializer_list<value_type> of pairs to be
605 * Complexity similar to that of the range constructor.
608 insert(initializer_list
<value_type
> __l
)
609 { this->insert(__l
.begin(), __l
.end()); }
612 #if __cplusplus >= 201103L
613 // _GLIBCXX_RESOLVE_LIB_DEFECTS
614 // DR 130. Associative erase should return an iterator.
616 * @brief Erases an element from a %multimap.
617 * @param __position An iterator pointing to the element to be erased.
618 * @return An iterator pointing to the element immediately following
619 * @a position prior to the element being erased. If no such
620 * element exists, end() is returned.
622 * This function erases an element, pointed to by the given iterator,
623 * from a %multimap. Note that this function only erases the element,
624 * and that if the element is itself a pointer, the pointed-to memory is
625 * not touched in any way. Managing the pointer is the user's
629 erase(const_iterator __position
)
630 { return _M_t
.erase(__position
); }
633 _GLIBCXX_ABI_TAG_CXX11
635 erase(iterator __position
)
636 { return _M_t
.erase(__position
); }
639 * @brief Erases an element from a %multimap.
640 * @param __position An iterator pointing to the element to be erased.
642 * This function erases an element, pointed to by the given iterator,
643 * from a %multimap. Note that this function only erases the element,
644 * and that if the element is itself a pointer, the pointed-to memory is
645 * not touched in any way. Managing the pointer is the user's
649 erase(iterator __position
)
650 { _M_t
.erase(__position
); }
654 * @brief Erases elements according to the provided key.
655 * @param __x Key of element to be erased.
656 * @return The number of elements erased.
658 * This function erases all elements located by the given key from a
660 * Note that this function only erases the element, and that if
661 * the element is itself a pointer, the pointed-to memory is not touched
662 * in any way. Managing the pointer is the user's responsibility.
665 erase(const key_type
& __x
)
666 { return _M_t
.erase(__x
); }
668 #if __cplusplus >= 201103L
669 // _GLIBCXX_RESOLVE_LIB_DEFECTS
670 // DR 130. Associative erase should return an iterator.
672 * @brief Erases a [first,last) range of elements from a %multimap.
673 * @param __first Iterator pointing to the start of the range to be
675 * @param __last Iterator pointing to the end of the range to be
677 * @return The iterator @a __last.
679 * This function erases a sequence of elements from a %multimap.
680 * Note that this function only erases the elements, and that if
681 * the elements themselves are pointers, the pointed-to memory is not
682 * touched in any way. Managing the pointer is the user's
686 erase(const_iterator __first
, const_iterator __last
)
687 { return _M_t
.erase(__first
, __last
); }
689 // _GLIBCXX_RESOLVE_LIB_DEFECTS
690 // DR 130. Associative erase should return an iterator.
692 * @brief Erases a [first,last) range of elements from a %multimap.
693 * @param __first Iterator pointing to the start of the range to be
695 * @param __last Iterator pointing to the end of the range to
698 * This function erases a sequence of elements from a %multimap.
699 * Note that this function only erases the elements, and that if
700 * the elements themselves are pointers, the pointed-to memory is not
701 * touched in any way. Managing the pointer is the user's
705 erase(iterator __first
, iterator __last
)
706 { _M_t
.erase(__first
, __last
); }
710 * @brief Swaps data with another %multimap.
711 * @param __x A %multimap of the same element and allocator types.
713 * This exchanges the elements between two multimaps in constant time.
714 * (It is only swapping a pointer, an integer, and an instance of
715 * the @c Compare type (which itself is often stateless and empty), so it
716 * should be quite fast.)
717 * Note that the global std::swap() function is specialized such that
718 * std::swap(m1,m2) will feed to this function.
722 #if __cplusplus >= 201103L
723 noexcept(_Alloc_traits::_S_nothrow_swap())
725 { _M_t
.swap(__x
._M_t
); }
728 * Erases all elements in a %multimap. Note that this function only
729 * erases the elements, and that if the elements themselves are pointers,
730 * the pointed-to memory is not touched in any way. Managing the pointer
731 * is the user's responsibility.
734 clear() _GLIBCXX_NOEXCEPT
739 * Returns the key comparison object out of which the %multimap
744 { return _M_t
.key_comp(); }
747 * Returns a value comparison object, built from the key comparison
748 * object out of which the %multimap was constructed.
752 { return value_compare(_M_t
.key_comp()); }
754 // multimap operations
756 * @brief Tries to locate an element in a %multimap.
757 * @param __x Key of (key, value) pair to be located.
758 * @return Iterator pointing to sought-after element,
759 * or end() if not found.
761 * This function takes a key and tries to locate the element with which
762 * the key matches. If successful the function returns an iterator
763 * pointing to the sought after %pair. If unsuccessful it returns the
764 * past-the-end ( @c end() ) iterator.
767 find(const key_type
& __x
)
768 { return _M_t
.find(__x
); }
771 * @brief Tries to locate an element in a %multimap.
772 * @param __x Key of (key, value) pair to be located.
773 * @return Read-only (constant) iterator pointing to sought-after
774 * element, or end() if not found.
776 * This function takes a key and tries to locate the element with which
777 * the key matches. If successful the function returns a constant
778 * iterator pointing to the sought after %pair. If unsuccessful it
779 * returns the past-the-end ( @c end() ) iterator.
782 find(const key_type
& __x
) const
783 { return _M_t
.find(__x
); }
786 * @brief Finds the number of elements with given key.
787 * @param __x Key of (key, value) pairs to be located.
788 * @return Number of elements with specified key.
791 count(const key_type
& __x
) const
792 { return _M_t
.count(__x
); }
795 * @brief Finds the beginning of a subsequence matching given key.
796 * @param __x Key of (key, value) pair to be located.
797 * @return Iterator pointing to first element equal to or greater
798 * than key, or end().
800 * This function returns the first element of a subsequence of elements
801 * that matches the given key. If unsuccessful it returns an iterator
802 * pointing to the first element that has a greater value than given key
803 * or end() if no such element exists.
806 lower_bound(const key_type
& __x
)
807 { return _M_t
.lower_bound(__x
); }
810 * @brief Finds the beginning of a subsequence matching given key.
811 * @param __x Key of (key, value) pair to be located.
812 * @return Read-only (constant) iterator pointing to first element
813 * equal to or greater than key, or end().
815 * This function returns the first element of a subsequence of
816 * elements that matches the given key. If unsuccessful the
817 * iterator will point to the next greatest element or, if no
818 * such greater element exists, to end().
821 lower_bound(const key_type
& __x
) const
822 { return _M_t
.lower_bound(__x
); }
825 * @brief Finds the end of a subsequence matching given key.
826 * @param __x Key of (key, value) pair to be located.
827 * @return Iterator pointing to the first element
828 * greater than key, or end().
831 upper_bound(const key_type
& __x
)
832 { return _M_t
.upper_bound(__x
); }
835 * @brief Finds the end of a subsequence matching given key.
836 * @param __x Key of (key, value) pair to be located.
837 * @return Read-only (constant) iterator pointing to first iterator
838 * greater than key, or end().
841 upper_bound(const key_type
& __x
) const
842 { return _M_t
.upper_bound(__x
); }
845 * @brief Finds a subsequence matching given key.
846 * @param __x Key of (key, value) pairs to be located.
847 * @return Pair of iterators that possibly points to the subsequence
848 * matching given key.
850 * This function is equivalent to
852 * std::make_pair(c.lower_bound(val),
853 * c.upper_bound(val))
855 * (but is faster than making the calls separately).
857 std::pair
<iterator
, iterator
>
858 equal_range(const key_type
& __x
)
859 { return _M_t
.equal_range(__x
); }
862 * @brief Finds a subsequence matching given key.
863 * @param __x Key of (key, value) pairs to be located.
864 * @return Pair of read-only (constant) iterators that possibly points
865 * to the subsequence matching given key.
867 * This function is equivalent to
869 * std::make_pair(c.lower_bound(val),
870 * c.upper_bound(val))
872 * (but is faster than making the calls separately).
874 std::pair
<const_iterator
, const_iterator
>
875 equal_range(const key_type
& __x
) const
876 { return _M_t
.equal_range(__x
); }
878 template<typename _K1
, typename _T1
, typename _C1
, typename _A1
>
880 operator==(const multimap
<_K1
, _T1
, _C1
, _A1
>&,
881 const multimap
<_K1
, _T1
, _C1
, _A1
>&);
883 template<typename _K1
, typename _T1
, typename _C1
, typename _A1
>
885 operator<(const multimap
<_K1
, _T1
, _C1
, _A1
>&,
886 const multimap
<_K1
, _T1
, _C1
, _A1
>&);
890 * @brief Multimap equality comparison.
891 * @param __x A %multimap.
892 * @param __y A %multimap of the same type as @a __x.
893 * @return True iff the size and elements of the maps are equal.
895 * This is an equivalence relation. It is linear in the size of the
896 * multimaps. Multimaps are considered equivalent if their sizes are equal,
897 * and if corresponding elements compare equal.
899 template<typename _Key
, typename _Tp
, typename _Compare
, typename _Alloc
>
901 operator==(const multimap
<_Key
, _Tp
, _Compare
, _Alloc
>& __x
,
902 const multimap
<_Key
, _Tp
, _Compare
, _Alloc
>& __y
)
903 { return __x
._M_t
== __y
._M_t
; }
906 * @brief Multimap ordering relation.
907 * @param __x A %multimap.
908 * @param __y A %multimap of the same type as @a __x.
909 * @return True iff @a x is lexicographically less than @a y.
911 * This is a total ordering relation. It is linear in the size of the
912 * multimaps. The elements must be comparable with @c <.
914 * See std::lexicographical_compare() for how the determination is made.
916 template<typename _Key
, typename _Tp
, typename _Compare
, typename _Alloc
>
918 operator<(const multimap
<_Key
, _Tp
, _Compare
, _Alloc
>& __x
,
919 const multimap
<_Key
, _Tp
, _Compare
, _Alloc
>& __y
)
920 { return __x
._M_t
< __y
._M_t
; }
922 /// Based on operator==
923 template<typename _Key
, typename _Tp
, typename _Compare
, typename _Alloc
>
925 operator!=(const multimap
<_Key
, _Tp
, _Compare
, _Alloc
>& __x
,
926 const multimap
<_Key
, _Tp
, _Compare
, _Alloc
>& __y
)
927 { return !(__x
== __y
); }
929 /// Based on operator<
930 template<typename _Key
, typename _Tp
, typename _Compare
, typename _Alloc
>
932 operator>(const multimap
<_Key
, _Tp
, _Compare
, _Alloc
>& __x
,
933 const multimap
<_Key
, _Tp
, _Compare
, _Alloc
>& __y
)
934 { return __y
< __x
; }
936 /// Based on operator<
937 template<typename _Key
, typename _Tp
, typename _Compare
, typename _Alloc
>
939 operator<=(const multimap
<_Key
, _Tp
, _Compare
, _Alloc
>& __x
,
940 const multimap
<_Key
, _Tp
, _Compare
, _Alloc
>& __y
)
941 { return !(__y
< __x
); }
943 /// Based on operator<
944 template<typename _Key
, typename _Tp
, typename _Compare
, typename _Alloc
>
946 operator>=(const multimap
<_Key
, _Tp
, _Compare
, _Alloc
>& __x
,
947 const multimap
<_Key
, _Tp
, _Compare
, _Alloc
>& __y
)
948 { return !(__x
< __y
); }
950 /// See std::multimap::swap().
951 template<typename _Key
, typename _Tp
, typename _Compare
, typename _Alloc
>
953 swap(multimap
<_Key
, _Tp
, _Compare
, _Alloc
>& __x
,
954 multimap
<_Key
, _Tp
, _Compare
, _Alloc
>& __y
)
957 _GLIBCXX_END_NAMESPACE_CONTAINER
960 #endif /* _STL_MULTIMAP_H */