1 // Map implementation -*- C++ -*-
3 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
4 // 2011 Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // Under Section 7 of GPL version 3, you are granted additional
18 // permissions described in the GCC Runtime Library Exception, version
19 // 3.1, as published by the Free Software Foundation.
21 // You should have received a copy of the GNU General Public License and
22 // a copy of the GCC Runtime Library Exception along with this program;
23 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 // <http://www.gnu.org/licenses/>.
29 * Hewlett-Packard Company
31 * Permission to use, copy, modify, distribute and sell this software
32 * and its documentation for any purpose is hereby granted without fee,
33 * provided that the above copyright notice appear in all copies and
34 * that both that copyright notice and this permission notice appear
35 * in supporting documentation. Hewlett-Packard Company makes no
36 * representations about the suitability of this software for any
37 * purpose. It is provided "as is" without express or implied warranty.
40 * Copyright (c) 1996,1997
41 * Silicon Graphics Computer Systems, Inc.
43 * Permission to use, copy, modify, distribute and sell this software
44 * and its documentation for any purpose is hereby granted without fee,
45 * provided that the above copyright notice appear in all copies and
46 * that both that copyright notice and this permission notice appear
47 * in supporting documentation. Silicon Graphics makes no
48 * representations about the suitability of this software for any
49 * purpose. It is provided "as is" without express or implied warranty.
52 /** @file bits/stl_map.h
53 * This is an internal header file, included by other library headers.
54 * Do not attempt to use it directly. @headername{map}
60 #include <bits/functexcept.h>
61 #include <bits/concept_check.h>
62 #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 * Meets the requirements of a <a href="tables.html#65">container</a>, a
75 * <a href="tables.html#66">reversible container</a>, and an
76 * <a href="tables.html#69">associative container</a> (using unique keys).
77 * For a @c map<Key,T> the key_type is Key, the mapped_type is T, and the
78 * value_type is std::pair<const Key,T>.
80 * Maps support bidirectional iterators.
82 * The private tree data is declared exactly the same way for map and
83 * multimap; the distinction is made entirely in how the tree functions are
84 * called (*_unique versus *_equal, same as the standard).
86 template <typename _Key
, typename _Tp
, typename _Compare
= std::less
<_Key
>,
87 typename _Alloc
= std::allocator
<std::pair
<const _Key
, _Tp
> > >
91 typedef _Key key_type
;
92 typedef _Tp mapped_type
;
93 typedef std::pair
<const _Key
, _Tp
> value_type
;
94 typedef _Compare key_compare
;
95 typedef _Alloc allocator_type
;
98 // concept requirements
99 typedef typename
_Alloc::value_type _Alloc_value_type
;
100 __glibcxx_class_requires(_Tp
, _SGIAssignableConcept
)
101 __glibcxx_class_requires4(_Compare
, bool, _Key
, _Key
,
102 _BinaryFunctionConcept
)
103 __glibcxx_class_requires2(value_type
, _Alloc_value_type
, _SameTypeConcept
)
107 : public std::binary_function
<value_type
, value_type
, bool>
109 friend class map
<_Key
, _Tp
, _Compare
, _Alloc
>;
113 value_compare(_Compare __c
)
117 bool operator()(const value_type
& __x
, const value_type
& __y
) const
118 { return comp(__x
.first
, __y
.first
); }
122 /// This turns a red-black tree into a [multi]map.
123 typedef typename
_Alloc::template rebind
<value_type
>::other
126 typedef _Rb_tree
<key_type
, value_type
, _Select1st
<value_type
>,
127 key_compare
, _Pair_alloc_type
> _Rep_type
;
129 /// The actual tree structure.
133 // many of these are specified differently in ISO, but the following are
134 // "functionally equivalent"
135 typedef typename
_Pair_alloc_type::pointer pointer
;
136 typedef typename
_Pair_alloc_type::const_pointer const_pointer
;
137 typedef typename
_Pair_alloc_type::reference reference
;
138 typedef typename
_Pair_alloc_type::const_reference const_reference
;
139 typedef typename
_Rep_type::iterator iterator
;
140 typedef typename
_Rep_type::const_iterator const_iterator
;
141 typedef typename
_Rep_type::size_type size_type
;
142 typedef typename
_Rep_type::difference_type difference_type
;
143 typedef typename
_Rep_type::reverse_iterator reverse_iterator
;
144 typedef typename
_Rep_type::const_reverse_iterator const_reverse_iterator
;
146 // [23.3.1.1] construct/copy/destroy
147 // (get_allocator() is normally listed in this section, but seems to have
148 // been accidentally omitted in the printed standard)
150 * @brief Default constructor creates no elements.
156 * @brief Creates a %map with no elements.
157 * @param comp A comparison object.
158 * @param a An allocator object.
161 map(const _Compare
& __comp
,
162 const allocator_type
& __a
= allocator_type())
163 : _M_t(__comp
, __a
) { }
166 * @brief %Map copy constructor.
167 * @param x A %map of identical element and allocator types.
169 * The newly-created %map uses a copy of the allocation object
175 #ifdef __GXX_EXPERIMENTAL_CXX0X__
177 * @brief %Map move constructor.
178 * @param x A %map of identical element and allocator types.
180 * The newly-created %map contains the exact contents of @a x.
181 * The contents of @a x are a valid, but unspecified %map.
184 : _M_t(std::move(__x
._M_t
)) { }
187 * @brief Builds a %map from an initializer_list.
188 * @param l An initializer_list.
189 * @param comp A comparison object.
190 * @param a An allocator object.
192 * Create a %map consisting of copies of the elements in the
193 * initializer_list @a l.
194 * This is linear in N if the range is already sorted, and NlogN
195 * otherwise (where N is @a l.size()).
197 map(initializer_list
<value_type
> __l
,
198 const _Compare
& __c
= _Compare(),
199 const allocator_type
& __a
= allocator_type())
201 { _M_t
._M_insert_unique(__l
.begin(), __l
.end()); }
205 * @brief Builds a %map from a range.
206 * @param first An input iterator.
207 * @param last An input iterator.
209 * Create a %map consisting of copies of the elements from [first,last).
210 * This is linear in N if the range is already sorted, and NlogN
211 * otherwise (where N is distance(first,last)).
213 template<typename _InputIterator
>
214 map(_InputIterator __first
, _InputIterator __last
)
216 { _M_t
._M_insert_unique(__first
, __last
); }
219 * @brief Builds a %map from a range.
220 * @param first An input iterator.
221 * @param last An input iterator.
222 * @param comp A comparison functor.
223 * @param a An allocator object.
225 * Create a %map consisting of copies of the elements from [first,last).
226 * This is linear in N if the range is already sorted, and NlogN
227 * otherwise (where N is distance(first,last)).
229 template<typename _InputIterator
>
230 map(_InputIterator __first
, _InputIterator __last
,
231 const _Compare
& __comp
,
232 const allocator_type
& __a
= allocator_type())
234 { _M_t
._M_insert_unique(__first
, __last
); }
236 // FIXME There is no dtor declared, but we should have something
237 // generated by Doxygen. I don't know what tags to add to this
238 // paragraph to make that happen:
240 * The dtor only erases the elements, and note that if the elements
241 * themselves are pointers, the pointed-to memory is not touched in any
242 * way. Managing the pointer is the user's responsibility.
246 * @brief %Map assignment operator.
247 * @param x A %map of identical element and allocator types.
249 * All the elements of @a x are copied, but unlike the copy constructor,
250 * the allocator object is not copied.
253 operator=(const map
& __x
)
259 #ifdef __GXX_EXPERIMENTAL_CXX0X__
261 * @brief %Map move assignment operator.
262 * @param x A %map of identical element and allocator types.
264 * The contents of @a x are moved into this map (without copying).
265 * @a x is a valid, but unspecified %map.
278 * @brief %Map list assignment operator.
279 * @param l An initializer_list.
281 * This function fills a %map with copies of the elements in the
282 * initializer list @a l.
284 * Note that the assignment completely changes the %map and
285 * that the resulting %map's size is the same as the number
286 * of elements assigned. Old data may be lost.
289 operator=(initializer_list
<value_type
> __l
)
292 this->insert(__l
.begin(), __l
.end());
297 /// Get a copy of the memory allocation object.
299 get_allocator() const _GLIBCXX_NOEXCEPT
300 { return _M_t
.get_allocator(); }
304 * Returns a read/write iterator that points to the first pair in the
306 * Iteration is done in ascending order according to the keys.
309 begin() _GLIBCXX_NOEXCEPT
310 { return _M_t
.begin(); }
313 * Returns a read-only (constant) iterator that points to the first pair
314 * in the %map. Iteration is done in ascending order according to the
318 begin() const _GLIBCXX_NOEXCEPT
319 { return _M_t
.begin(); }
322 * Returns a read/write iterator that points one past the last
323 * pair in the %map. Iteration is done in ascending order
324 * according to the keys.
327 end() _GLIBCXX_NOEXCEPT
328 { return _M_t
.end(); }
331 * Returns a read-only (constant) iterator that points one past the last
332 * pair in the %map. Iteration is done in ascending order according to
336 end() const _GLIBCXX_NOEXCEPT
337 { return _M_t
.end(); }
340 * Returns a read/write reverse iterator that points to the last pair in
341 * the %map. Iteration is done in descending order according to the
345 rbegin() _GLIBCXX_NOEXCEPT
346 { return _M_t
.rbegin(); }
349 * Returns a read-only (constant) reverse iterator that points to the
350 * last pair in the %map. Iteration is done in descending order
351 * according to the keys.
353 const_reverse_iterator
354 rbegin() const _GLIBCXX_NOEXCEPT
355 { return _M_t
.rbegin(); }
358 * Returns a read/write reverse iterator that points to one before the
359 * first pair in the %map. Iteration is done in descending order
360 * according to the keys.
363 rend() _GLIBCXX_NOEXCEPT
364 { return _M_t
.rend(); }
367 * Returns a read-only (constant) reverse iterator that points to one
368 * before the first pair in the %map. Iteration is done in descending
369 * order according to the keys.
371 const_reverse_iterator
372 rend() const _GLIBCXX_NOEXCEPT
373 { return _M_t
.rend(); }
375 #ifdef __GXX_EXPERIMENTAL_CXX0X__
377 * Returns a read-only (constant) iterator that points to the first pair
378 * in the %map. Iteration is done in ascending order according to the
382 cbegin() const noexcept
383 { return _M_t
.begin(); }
386 * Returns a read-only (constant) iterator that points one past the last
387 * pair in the %map. Iteration is done in ascending order according to
391 cend() const noexcept
392 { return _M_t
.end(); }
395 * Returns a read-only (constant) reverse iterator that points to the
396 * last pair in the %map. Iteration is done in descending order
397 * according to the keys.
399 const_reverse_iterator
400 crbegin() const noexcept
401 { return _M_t
.rbegin(); }
404 * Returns a read-only (constant) reverse iterator that points to one
405 * before the first pair in the %map. Iteration is done in descending
406 * order according to the keys.
408 const_reverse_iterator
409 crend() const noexcept
410 { return _M_t
.rend(); }
414 /** Returns true if the %map is empty. (Thus begin() would equal
418 empty() const _GLIBCXX_NOEXCEPT
419 { return _M_t
.empty(); }
421 /** Returns the size of the %map. */
423 size() const _GLIBCXX_NOEXCEPT
424 { return _M_t
.size(); }
426 /** Returns the maximum size of the %map. */
428 max_size() const _GLIBCXX_NOEXCEPT
429 { return _M_t
.max_size(); }
431 // [23.3.1.2] element access
433 * @brief Subscript ( @c [] ) access to %map data.
434 * @param k The key for which data should be retrieved.
435 * @return A reference to the data of the (key,data) %pair.
437 * Allows for easy lookup with the subscript ( @c [] )
438 * operator. Returns data associated with the key specified in
439 * subscript. If the key does not exist, a pair with that key
440 * is created using default values, which is then returned.
442 * Lookup requires logarithmic time.
445 operator[](const key_type
& __k
)
447 // concept requirements
448 __glibcxx_function_requires(_DefaultConstructibleConcept
<mapped_type
>)
450 iterator __i
= lower_bound(__k
);
451 // __i->first is greater than or equivalent to __k.
452 if (__i
== end() || key_comp()(__k
, (*__i
).first
))
453 __i
= insert(__i
, value_type(__k
, mapped_type()));
454 return (*__i
).second
;
457 #ifdef __GXX_EXPERIMENTAL_CXX0X__
459 operator[](key_type
&& __k
)
461 // concept requirements
462 __glibcxx_function_requires(_DefaultConstructibleConcept
<mapped_type
>)
464 iterator __i
= lower_bound(__k
);
465 // __i->first is greater than or equivalent to __k.
466 if (__i
== end() || key_comp()(__k
, (*__i
).first
))
467 __i
= insert(__i
, std::make_pair(std::move(__k
), mapped_type()));
468 return (*__i
).second
;
472 // _GLIBCXX_RESOLVE_LIB_DEFECTS
473 // DR 464. Suggestion for new member functions in standard containers.
475 * @brief Access to %map data.
476 * @param k The key for which data should be retrieved.
477 * @return A reference to the data whose key is equivalent to @a k, if
478 * such a data is present in the %map.
479 * @throw std::out_of_range If no such data is present.
482 at(const key_type
& __k
)
484 iterator __i
= lower_bound(__k
);
485 if (__i
== end() || key_comp()(__k
, (*__i
).first
))
486 __throw_out_of_range(__N("map::at"));
487 return (*__i
).second
;
491 at(const key_type
& __k
) const
493 const_iterator __i
= lower_bound(__k
);
494 if (__i
== end() || key_comp()(__k
, (*__i
).first
))
495 __throw_out_of_range(__N("map::at"));
496 return (*__i
).second
;
501 * @brief Attempts to insert a std::pair into the %map.
503 * @param x Pair to be inserted (see std::make_pair for easy creation
506 * @return A pair, of which the first element is an iterator that
507 * points to the possibly inserted pair, and the second is
508 * a bool that is true if the pair was actually inserted.
510 * This function attempts to insert a (key, value) %pair into the %map.
511 * A %map relies on unique keys and thus a %pair is only inserted if its
512 * first element (the key) is not already present in the %map.
514 * Insertion requires logarithmic time.
516 std::pair
<iterator
, bool>
517 insert(const value_type
& __x
)
518 { return _M_t
._M_insert_unique(__x
); }
520 #ifdef __GXX_EXPERIMENTAL_CXX0X__
521 template<typename _Pair
, typename
= typename
522 std::enable_if
<std::is_convertible
<_Pair
,
523 value_type
>::value
>::type
>
524 std::pair
<iterator
, bool>
526 { return _M_t
._M_insert_unique(std::forward
<_Pair
>(__x
)); }
529 #ifdef __GXX_EXPERIMENTAL_CXX0X__
531 * @brief Attempts to insert a list of std::pairs into the %map.
532 * @param list A std::initializer_list<value_type> of pairs to be
535 * Complexity similar to that of the range constructor.
538 insert(std::initializer_list
<value_type
> __list
)
539 { insert(__list
.begin(), __list
.end()); }
543 * @brief Attempts to insert a std::pair into the %map.
544 * @param position An iterator that serves as a hint as to where the
545 * pair should be inserted.
546 * @param x Pair to be inserted (see std::make_pair for easy creation
548 * @return An iterator that points to the element with key of @a x (may
549 * or may not be the %pair passed in).
552 * This function is not concerned about whether the insertion
553 * took place, and thus does not return a boolean like the
554 * single-argument insert() does. Note that the first
555 * parameter is only a hint and can potentially improve the
556 * performance of the insertion process. A bad hint would
557 * cause no gains in efficiency.
560 * http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt07ch17.html
561 * for more on @a hinting.
563 * Insertion requires logarithmic time (if the hint is not taken).
566 #ifdef __GXX_EXPERIMENTAL_CXX0X__
567 insert(const_iterator __position
, const value_type
& __x
)
569 insert(iterator __position
, const value_type
& __x
)
571 { return _M_t
._M_insert_unique_(__position
, __x
); }
573 #ifdef __GXX_EXPERIMENTAL_CXX0X__
574 template<typename _Pair
, typename
= typename
575 std::enable_if
<std::is_convertible
<_Pair
,
576 value_type
>::value
>::type
>
578 insert(const_iterator __position
, _Pair
&& __x
)
579 { return _M_t
._M_insert_unique_(__position
,
580 std::forward
<_Pair
>(__x
)); }
584 * @brief Template function that attempts to insert a range of elements.
585 * @param first Iterator pointing to the start of the range to be
587 * @param last Iterator pointing to the end of the range.
589 * Complexity similar to that of the range constructor.
591 template<typename _InputIterator
>
593 insert(_InputIterator __first
, _InputIterator __last
)
594 { _M_t
._M_insert_unique(__first
, __last
); }
596 #ifdef __GXX_EXPERIMENTAL_CXX0X__
597 // _GLIBCXX_RESOLVE_LIB_DEFECTS
598 // DR 130. Associative erase should return an iterator.
600 * @brief Erases an element from a %map.
601 * @param position An iterator pointing to the element to be erased.
602 * @return An iterator pointing to the element immediately following
603 * @a position prior to the element being erased. If no such
604 * element exists, end() is returned.
606 * This function erases an element, pointed to by the given
607 * iterator, from a %map. Note that this function only erases
608 * the element, and that if the element is itself a pointer,
609 * the pointed-to memory is not touched in any way. Managing
610 * the pointer is the user's responsibility.
613 erase(const_iterator __position
)
614 { return _M_t
.erase(__position
); }
617 * @brief Erases an element from a %map.
618 * @param position An iterator pointing to the element to be erased.
620 * This function erases an element, pointed to by the given
621 * iterator, from a %map. Note that this function only erases
622 * the element, and that if the element is itself a pointer,
623 * the pointed-to memory is not touched in any way. Managing
624 * the pointer is the user's responsibility.
627 erase(iterator __position
)
628 { _M_t
.erase(__position
); }
632 * @brief Erases elements according to the provided key.
633 * @param x Key of element to be erased.
634 * @return The number of elements erased.
636 * This function erases all the elements located by the given key from
638 * Note that this function only erases the element, and that if
639 * the element is itself a pointer, the pointed-to memory is not touched
640 * in any way. Managing the pointer is the user's responsibility.
643 erase(const key_type
& __x
)
644 { return _M_t
.erase(__x
); }
646 #ifdef __GXX_EXPERIMENTAL_CXX0X__
647 // _GLIBCXX_RESOLVE_LIB_DEFECTS
648 // DR 130. Associative erase should return an iterator.
650 * @brief Erases a [first,last) range of elements from a %map.
651 * @param first Iterator pointing to the start of the range to be
653 * @param last Iterator pointing to the end of the range to be erased.
654 * @return The iterator @a last.
656 * This function erases a sequence of elements from a %map.
657 * Note that this function only erases the element, and that if
658 * the element is itself a pointer, the pointed-to memory is not touched
659 * in any way. Managing the pointer is the user's responsibility.
662 erase(const_iterator __first
, const_iterator __last
)
663 { return _M_t
.erase(__first
, __last
); }
666 * @brief Erases a [first,last) range of elements from a %map.
667 * @param first Iterator pointing to the start of the range to be
669 * @param last Iterator pointing to the end of the range to be erased.
671 * This function erases a sequence of elements from a %map.
672 * Note that this function only erases the element, and that if
673 * the element is itself a pointer, the pointed-to memory is not touched
674 * in any way. Managing the pointer is the user's responsibility.
677 erase(iterator __first
, iterator __last
)
678 { _M_t
.erase(__first
, __last
); }
682 * @brief Swaps data with another %map.
683 * @param x A %map of the same element and allocator types.
685 * This exchanges the elements between two maps in constant
686 * time. (It is only swapping a pointer, an integer, and an
687 * instance of the @c Compare type (which itself is often
688 * stateless and empty), so it should be quite fast.) Note
689 * that the global std::swap() function is specialized such
690 * that std::swap(m1,m2) will feed to this function.
694 { _M_t
.swap(__x
._M_t
); }
697 * Erases all elements in a %map. Note that this function only
698 * erases the elements, and that if the elements themselves are
699 * pointers, the pointed-to memory is not touched in any way.
700 * Managing the pointer is the user's responsibility.
703 clear() _GLIBCXX_NOEXCEPT
708 * Returns the key comparison object out of which the %map was
713 { return _M_t
.key_comp(); }
716 * Returns a value comparison object, built from the key comparison
717 * object out of which the %map was constructed.
721 { return value_compare(_M_t
.key_comp()); }
723 // [23.3.1.3] map operations
725 * @brief Tries to locate an element in a %map.
726 * @param x Key of (key, value) %pair to be located.
727 * @return Iterator pointing to sought-after element, or end() if not
730 * This function takes a key and tries to locate the element with which
731 * the key matches. If successful the function returns an iterator
732 * pointing to the sought after %pair. If unsuccessful it returns the
733 * past-the-end ( @c end() ) iterator.
736 find(const key_type
& __x
)
737 { return _M_t
.find(__x
); }
740 * @brief Tries to locate an element in a %map.
741 * @param x Key of (key, value) %pair to be located.
742 * @return Read-only (constant) iterator pointing to sought-after
743 * element, or end() if not found.
745 * This function takes a key and tries to locate the element with which
746 * the key matches. If successful the function returns a constant
747 * iterator pointing to the sought after %pair. If unsuccessful it
748 * returns the past-the-end ( @c end() ) iterator.
751 find(const key_type
& __x
) const
752 { return _M_t
.find(__x
); }
755 * @brief Finds the number of elements with given key.
756 * @param x Key of (key, value) pairs to be located.
757 * @return Number of elements with specified key.
759 * This function only makes sense for multimaps; for map the result will
760 * either be 0 (not present) or 1 (present).
763 count(const key_type
& __x
) const
764 { return _M_t
.find(__x
) == _M_t
.end() ? 0 : 1; }
767 * @brief Finds the beginning of a subsequence matching given key.
768 * @param x Key of (key, value) pair to be located.
769 * @return Iterator pointing to first element equal to or greater
770 * than key, or end().
772 * This function returns the first element of a subsequence of elements
773 * that matches the given key. If unsuccessful it returns an iterator
774 * pointing to the first element that has a greater value than given key
775 * or end() if no such element exists.
778 lower_bound(const key_type
& __x
)
779 { return _M_t
.lower_bound(__x
); }
782 * @brief Finds the beginning of a subsequence matching given key.
783 * @param x Key of (key, value) pair to be located.
784 * @return Read-only (constant) iterator pointing to first element
785 * equal to or greater than key, or end().
787 * This function returns the first element of a subsequence of elements
788 * that matches the given key. If unsuccessful it returns an iterator
789 * pointing to the first element that has a greater value than given key
790 * or end() if no such element exists.
793 lower_bound(const key_type
& __x
) const
794 { return _M_t
.lower_bound(__x
); }
797 * @brief Finds the end of a subsequence matching given key.
798 * @param x Key of (key, value) pair to be located.
799 * @return Iterator pointing to the first element
800 * greater than key, or end().
803 upper_bound(const key_type
& __x
)
804 { return _M_t
.upper_bound(__x
); }
807 * @brief Finds the end of a subsequence matching given key.
808 * @param x Key of (key, value) pair to be located.
809 * @return Read-only (constant) iterator pointing to first iterator
810 * greater than key, or end().
813 upper_bound(const key_type
& __x
) const
814 { return _M_t
.upper_bound(__x
); }
817 * @brief Finds a subsequence matching given key.
818 * @param x Key of (key, value) pairs to be located.
819 * @return Pair of iterators that possibly points to the subsequence
820 * matching given key.
822 * This function is equivalent to
824 * std::make_pair(c.lower_bound(val),
825 * c.upper_bound(val))
827 * (but is faster than making the calls separately).
829 * This function probably only makes sense for multimaps.
831 std::pair
<iterator
, iterator
>
832 equal_range(const key_type
& __x
)
833 { return _M_t
.equal_range(__x
); }
836 * @brief Finds a subsequence matching given key.
837 * @param x Key of (key, value) pairs to be located.
838 * @return Pair of read-only (constant) iterators that possibly points
839 * to the subsequence matching given key.
841 * This function is equivalent to
843 * std::make_pair(c.lower_bound(val),
844 * c.upper_bound(val))
846 * (but is faster than making the calls separately).
848 * This function probably only makes sense for multimaps.
850 std::pair
<const_iterator
, const_iterator
>
851 equal_range(const key_type
& __x
) const
852 { return _M_t
.equal_range(__x
); }
854 template<typename _K1
, typename _T1
, typename _C1
, typename _A1
>
856 operator==(const map
<_K1
, _T1
, _C1
, _A1
>&,
857 const map
<_K1
, _T1
, _C1
, _A1
>&);
859 template<typename _K1
, typename _T1
, typename _C1
, typename _A1
>
861 operator<(const map
<_K1
, _T1
, _C1
, _A1
>&,
862 const map
<_K1
, _T1
, _C1
, _A1
>&);
866 * @brief Map equality comparison.
868 * @param y A %map of the same type as @a x.
869 * @return True iff the size and elements of the maps are equal.
871 * This is an equivalence relation. It is linear in the size of the
872 * maps. Maps are considered equivalent if their sizes are equal,
873 * and if corresponding elements compare equal.
875 template<typename _Key
, typename _Tp
, typename _Compare
, typename _Alloc
>
877 operator==(const map
<_Key
, _Tp
, _Compare
, _Alloc
>& __x
,
878 const map
<_Key
, _Tp
, _Compare
, _Alloc
>& __y
)
879 { return __x
._M_t
== __y
._M_t
; }
882 * @brief Map ordering relation.
884 * @param y A %map of the same type as @a x.
885 * @return True iff @a x is lexicographically less than @a y.
887 * This is a total ordering relation. It is linear in the size of the
888 * maps. The elements must be comparable with @c <.
890 * See std::lexicographical_compare() for how the determination is made.
892 template<typename _Key
, typename _Tp
, typename _Compare
, typename _Alloc
>
894 operator<(const map
<_Key
, _Tp
, _Compare
, _Alloc
>& __x
,
895 const map
<_Key
, _Tp
, _Compare
, _Alloc
>& __y
)
896 { return __x
._M_t
< __y
._M_t
; }
898 /// Based on operator==
899 template<typename _Key
, typename _Tp
, typename _Compare
, typename _Alloc
>
901 operator!=(const map
<_Key
, _Tp
, _Compare
, _Alloc
>& __x
,
902 const map
<_Key
, _Tp
, _Compare
, _Alloc
>& __y
)
903 { return !(__x
== __y
); }
905 /// Based on operator<
906 template<typename _Key
, typename _Tp
, typename _Compare
, typename _Alloc
>
908 operator>(const map
<_Key
, _Tp
, _Compare
, _Alloc
>& __x
,
909 const map
<_Key
, _Tp
, _Compare
, _Alloc
>& __y
)
910 { return __y
< __x
; }
912 /// Based on operator<
913 template<typename _Key
, typename _Tp
, typename _Compare
, typename _Alloc
>
915 operator<=(const map
<_Key
, _Tp
, _Compare
, _Alloc
>& __x
,
916 const map
<_Key
, _Tp
, _Compare
, _Alloc
>& __y
)
917 { return !(__y
< __x
); }
919 /// Based on operator<
920 template<typename _Key
, typename _Tp
, typename _Compare
, typename _Alloc
>
922 operator>=(const map
<_Key
, _Tp
, _Compare
, _Alloc
>& __x
,
923 const map
<_Key
, _Tp
, _Compare
, _Alloc
>& __y
)
924 { return !(__x
< __y
); }
926 /// See std::map::swap().
927 template<typename _Key
, typename _Tp
, typename _Compare
, typename _Alloc
>
929 swap(map
<_Key
, _Tp
, _Compare
, _Alloc
>& __x
,
930 map
<_Key
, _Tp
, _Compare
, _Alloc
>& __y
)
933 _GLIBCXX_END_NAMESPACE_CONTAINER
936 #endif /* _STL_MAP_H */