1 // Map implementation -*- C++ -*-
3 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 // 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 _GLIBCXX_BEGIN_NESTED_NAMESPACE(std
, _GLIBCXX_STD_D
)
67 * @brief A standard container made up of (key,value) pairs, which can be
68 * retrieved based on a key, in logarithmic time.
70 * @ingroup associative_containers
72 * Meets the requirements of a <a href="tables.html#65">container</a>, a
73 * <a href="tables.html#66">reversible container</a>, and an
74 * <a href="tables.html#69">associative container</a> (using unique keys).
75 * For a @c map<Key,T> the key_type is Key, the mapped_type is T, and the
76 * value_type is std::pair<const Key,T>.
78 * Maps support bidirectional iterators.
80 * The private tree data is declared exactly the same way for map and
81 * multimap; the distinction is made entirely in how the tree functions are
82 * called (*_unique versus *_equal, same as the standard).
84 template <typename _Key
, typename _Tp
, typename _Compare
= std::less
<_Key
>,
85 typename _Alloc
= std::allocator
<std::pair
<const _Key
, _Tp
> > >
89 typedef _Key key_type
;
90 typedef _Tp mapped_type
;
91 typedef std::pair
<const _Key
, _Tp
> value_type
;
92 typedef _Compare key_compare
;
93 typedef _Alloc allocator_type
;
96 // concept requirements
97 typedef typename
_Alloc::value_type _Alloc_value_type
;
98 __glibcxx_class_requires(_Tp
, _SGIAssignableConcept
)
99 __glibcxx_class_requires4(_Compare
, bool, _Key
, _Key
,
100 _BinaryFunctionConcept
)
101 __glibcxx_class_requires2(value_type
, _Alloc_value_type
, _SameTypeConcept
)
105 : public std::binary_function
<value_type
, value_type
, bool>
107 friend class map
<_Key
, _Tp
, _Compare
, _Alloc
>;
111 value_compare(_Compare __c
)
115 bool operator()(const value_type
& __x
, const value_type
& __y
) const
116 { return comp(__x
.first
, __y
.first
); }
120 /// This turns a red-black tree into a [multi]map.
121 typedef typename
_Alloc::template rebind
<value_type
>::other
124 typedef _Rb_tree
<key_type
, value_type
, _Select1st
<value_type
>,
125 key_compare
, _Pair_alloc_type
> _Rep_type
;
127 /// The actual tree structure.
131 // many of these are specified differently in ISO, but the following are
132 // "functionally equivalent"
133 typedef typename
_Pair_alloc_type::pointer pointer
;
134 typedef typename
_Pair_alloc_type::const_pointer const_pointer
;
135 typedef typename
_Pair_alloc_type::reference reference
;
136 typedef typename
_Pair_alloc_type::const_reference const_reference
;
137 typedef typename
_Rep_type::iterator iterator
;
138 typedef typename
_Rep_type::const_iterator const_iterator
;
139 typedef typename
_Rep_type::size_type size_type
;
140 typedef typename
_Rep_type::difference_type difference_type
;
141 typedef typename
_Rep_type::reverse_iterator reverse_iterator
;
142 typedef typename
_Rep_type::const_reverse_iterator const_reverse_iterator
;
144 // [23.3.1.1] construct/copy/destroy
145 // (get_allocator() is normally listed in this section, but seems to have
146 // been accidentally omitted in the printed standard)
148 * @brief Default constructor creates no elements.
154 * @brief Creates a %map with no elements.
155 * @param comp A comparison object.
156 * @param a An allocator object.
159 map(const _Compare
& __comp
,
160 const allocator_type
& __a
= allocator_type())
161 : _M_t(__comp
, __a
) { }
164 * @brief %Map copy constructor.
165 * @param x A %map of identical element and allocator types.
167 * The newly-created %map uses a copy of the allocation object
173 #ifdef __GXX_EXPERIMENTAL_CXX0X__
175 * @brief %Map move constructor.
176 * @param x A %map of identical element and allocator types.
178 * The newly-created %map contains the exact contents of @a x.
179 * The contents of @a x are a valid, but unspecified %map.
182 : _M_t(std::move(__x
._M_t
)) { }
185 * @brief Builds a %map from an initializer_list.
186 * @param l An initializer_list.
187 * @param comp A comparison object.
188 * @param a An allocator object.
190 * Create a %map consisting of copies of the elements in the
191 * initializer_list @a l.
192 * This is linear in N if the range is already sorted, and NlogN
193 * otherwise (where N is @a l.size()).
195 map(initializer_list
<value_type
> __l
,
196 const _Compare
& __c
= _Compare(),
197 const allocator_type
& __a
= allocator_type())
199 { _M_t
._M_insert_unique(__l
.begin(), __l
.end()); }
203 * @brief Builds a %map from a range.
204 * @param first An input iterator.
205 * @param last An input iterator.
207 * Create a %map consisting of copies of the elements from [first,last).
208 * This is linear in N if the range is already sorted, and NlogN
209 * otherwise (where N is distance(first,last)).
211 template<typename _InputIterator
>
212 map(_InputIterator __first
, _InputIterator __last
)
214 { _M_t
._M_insert_unique(__first
, __last
); }
217 * @brief Builds a %map from a range.
218 * @param first An input iterator.
219 * @param last An input iterator.
220 * @param comp A comparison functor.
221 * @param a An allocator object.
223 * Create a %map consisting of copies of the elements from [first,last).
224 * This is linear in N if the range is already sorted, and NlogN
225 * otherwise (where N is distance(first,last)).
227 template<typename _InputIterator
>
228 map(_InputIterator __first
, _InputIterator __last
,
229 const _Compare
& __comp
,
230 const allocator_type
& __a
= allocator_type())
232 { _M_t
._M_insert_unique(__first
, __last
); }
234 // FIXME There is no dtor declared, but we should have something
235 // generated by Doxygen. I don't know what tags to add to this
236 // paragraph to make that happen:
238 * The dtor only erases the elements, and note that if the elements
239 * themselves are pointers, the pointed-to memory is not touched in any
240 * way. Managing the pointer is the user's responsibility.
244 * @brief %Map assignment operator.
245 * @param x A %map of identical element and allocator types.
247 * All the elements of @a x are copied, but unlike the copy constructor,
248 * the allocator object is not copied.
251 operator=(const map
& __x
)
257 #ifdef __GXX_EXPERIMENTAL_CXX0X__
259 * @brief %Map move assignment operator.
260 * @param x A %map of identical element and allocator types.
262 * The contents of @a x are moved into this map (without copying).
263 * @a x is a valid, but unspecified %map.
276 * @brief %Map list assignment operator.
277 * @param l An initializer_list.
279 * This function fills a %map with copies of the elements in the
280 * initializer list @a l.
282 * Note that the assignment completely changes the %map and
283 * that the resulting %map's size is the same as the number
284 * of elements assigned. Old data may be lost.
287 operator=(initializer_list
<value_type
> __l
)
290 this->insert(__l
.begin(), __l
.end());
295 /// Get a copy of the memory allocation object.
297 get_allocator() const
298 { return _M_t
.get_allocator(); }
302 * Returns a read/write iterator that points to the first pair in the
304 * Iteration is done in ascending order according to the keys.
308 { return _M_t
.begin(); }
311 * Returns a read-only (constant) iterator that points to the first pair
312 * in the %map. Iteration is done in ascending order according to the
317 { return _M_t
.begin(); }
320 * Returns a read/write iterator that points one past the last
321 * pair in the %map. Iteration is done in ascending order
322 * according to the keys.
326 { return _M_t
.end(); }
329 * Returns a read-only (constant) iterator that points one past the last
330 * pair in the %map. Iteration is done in ascending order according to
335 { return _M_t
.end(); }
338 * Returns a read/write reverse iterator that points to the last pair in
339 * the %map. Iteration is done in descending order according to the
344 { return _M_t
.rbegin(); }
347 * Returns a read-only (constant) reverse iterator that points to the
348 * last pair in the %map. Iteration is done in descending order
349 * according to the keys.
351 const_reverse_iterator
353 { return _M_t
.rbegin(); }
356 * Returns a read/write reverse iterator that points to one before the
357 * first pair in the %map. Iteration is done in descending order
358 * according to the keys.
362 { return _M_t
.rend(); }
365 * Returns a read-only (constant) reverse iterator that points to one
366 * before the first pair in the %map. Iteration is done in descending
367 * order according to the keys.
369 const_reverse_iterator
371 { return _M_t
.rend(); }
373 #ifdef __GXX_EXPERIMENTAL_CXX0X__
375 * Returns a read-only (constant) iterator that points to the first pair
376 * in the %map. Iteration is done in ascending order according to the
381 { return _M_t
.begin(); }
384 * Returns a read-only (constant) iterator that points one past the last
385 * pair in the %map. Iteration is done in ascending order according to
390 { return _M_t
.end(); }
393 * Returns a read-only (constant) reverse iterator that points to the
394 * last pair in the %map. Iteration is done in descending order
395 * according to the keys.
397 const_reverse_iterator
399 { return _M_t
.rbegin(); }
402 * Returns a read-only (constant) reverse iterator that points to one
403 * before the first pair in the %map. Iteration is done in descending
404 * order according to the keys.
406 const_reverse_iterator
408 { return _M_t
.rend(); }
412 /** Returns true if the %map is empty. (Thus begin() would equal
417 { return _M_t
.empty(); }
419 /** Returns the size of the %map. */
422 { return _M_t
.size(); }
424 /** Returns the maximum size of the %map. */
427 { return _M_t
.max_size(); }
429 // [23.3.1.2] element access
431 * @brief Subscript ( @c [] ) access to %map data.
432 * @param k The key for which data should be retrieved.
433 * @return A reference to the data of the (key,data) %pair.
435 * Allows for easy lookup with the subscript ( @c [] )
436 * operator. Returns data associated with the key specified in
437 * subscript. If the key does not exist, a pair with that key
438 * is created using default values, which is then returned.
440 * Lookup requires logarithmic time.
443 operator[](const key_type
& __k
)
445 // concept requirements
446 __glibcxx_function_requires(_DefaultConstructibleConcept
<mapped_type
>)
448 iterator __i
= lower_bound(__k
);
449 // __i->first is greater than or equivalent to __k.
450 if (__i
== end() || key_comp()(__k
, (*__i
).first
))
451 __i
= insert(__i
, value_type(__k
, mapped_type()));
452 return (*__i
).second
;
455 #ifdef __GXX_EXPERIMENTAL_CXX0X__
457 operator[](key_type
&& __k
)
459 // concept requirements
460 __glibcxx_function_requires(_DefaultConstructibleConcept
<mapped_type
>)
462 iterator __i
= lower_bound(__k
);
463 // __i->first is greater than or equivalent to __k.
464 if (__i
== end() || key_comp()(__k
, (*__i
).first
))
465 __i
= insert(__i
, std::make_pair(std::move(__k
), mapped_type()));
466 return (*__i
).second
;
470 // _GLIBCXX_RESOLVE_LIB_DEFECTS
471 // DR 464. Suggestion for new member functions in standard containers.
473 * @brief Access to %map data.
474 * @param k The key for which data should be retrieved.
475 * @return A reference to the data whose key is equivalent to @a k, if
476 * such a data is present in the %map.
477 * @throw std::out_of_range If no such data is present.
480 at(const key_type
& __k
)
482 iterator __i
= lower_bound(__k
);
483 if (__i
== end() || key_comp()(__k
, (*__i
).first
))
484 __throw_out_of_range(__N("map::at"));
485 return (*__i
).second
;
489 at(const key_type
& __k
) const
491 const_iterator __i
= lower_bound(__k
);
492 if (__i
== end() || key_comp()(__k
, (*__i
).first
))
493 __throw_out_of_range(__N("map::at"));
494 return (*__i
).second
;
499 * @brief Attempts to insert a std::pair into the %map.
501 * @param x Pair to be inserted (see std::make_pair for easy creation
504 * @return A pair, of which the first element is an iterator that
505 * points to the possibly inserted pair, and the second is
506 * a bool that is true if the pair was actually inserted.
508 * This function attempts to insert a (key, value) %pair into the %map.
509 * A %map relies on unique keys and thus a %pair is only inserted if its
510 * first element (the key) is not already present in the %map.
512 * Insertion requires logarithmic time.
514 std::pair
<iterator
, bool>
515 insert(const value_type
& __x
)
516 { return _M_t
._M_insert_unique(__x
); }
518 #ifdef __GXX_EXPERIMENTAL_CXX0X__
519 template<typename _Pair
, typename
= typename
520 std::enable_if
<std::is_convertible
<_Pair
,
521 value_type
>::value
>::type
>
522 std::pair
<iterator
, bool>
524 { return _M_t
._M_insert_unique(std::forward
<_Pair
>(__x
)); }
527 #ifdef __GXX_EXPERIMENTAL_CXX0X__
529 * @brief Attempts to insert a list of std::pairs into the %map.
530 * @param list A std::initializer_list<value_type> of pairs to be
533 * Complexity similar to that of the range constructor.
536 insert(std::initializer_list
<value_type
> __list
)
537 { insert(__list
.begin(), __list
.end()); }
541 * @brief Attempts to insert a std::pair into the %map.
542 * @param position An iterator that serves as a hint as to where the
543 * pair should be inserted.
544 * @param x Pair to be inserted (see std::make_pair for easy creation
546 * @return An iterator that points to the element with key of @a x (may
547 * or may not be the %pair passed in).
550 * This function is not concerned about whether the insertion
551 * took place, and thus does not return a boolean like the
552 * single-argument insert() does. Note that the first
553 * parameter is only a hint and can potentially improve the
554 * performance of the insertion process. A bad hint would
555 * cause no gains in efficiency.
558 * http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt07ch17.html
559 * for more on @a hinting.
561 * Insertion requires logarithmic time (if the hint is not taken).
564 #ifdef __GXX_EXPERIMENTAL_CXX0X__
565 insert(const_iterator __position
, const value_type
& __x
)
567 insert(iterator __position
, const value_type
& __x
)
569 { return _M_t
._M_insert_unique_(__position
, __x
); }
571 #ifdef __GXX_EXPERIMENTAL_CXX0X__
572 template<typename _Pair
, typename
= typename
573 std::enable_if
<std::is_convertible
<_Pair
,
574 value_type
>::value
>::type
>
576 insert(const_iterator __position
, _Pair
&& __x
)
577 { return _M_t
._M_insert_unique_(__position
,
578 std::forward
<_Pair
>(__x
)); }
582 * @brief Template function that attempts to insert a range of elements.
583 * @param first Iterator pointing to the start of the range to be
585 * @param last Iterator pointing to the end of the range.
587 * Complexity similar to that of the range constructor.
589 template<typename _InputIterator
>
591 insert(_InputIterator __first
, _InputIterator __last
)
592 { _M_t
._M_insert_unique(__first
, __last
); }
594 #ifdef __GXX_EXPERIMENTAL_CXX0X__
595 // _GLIBCXX_RESOLVE_LIB_DEFECTS
596 // DR 130. Associative erase should return an iterator.
598 * @brief Erases an element from a %map.
599 * @param position An iterator pointing to the element to be erased.
600 * @return An iterator pointing to the element immediately following
601 * @a position prior to the element being erased. If no such
602 * element exists, end() is returned.
604 * This function erases an element, pointed to by the given
605 * iterator, from a %map. Note that this function only erases
606 * the element, and that if the element is itself a pointer,
607 * the pointed-to memory is not touched in any way. Managing
608 * the pointer is the user's responsibility.
611 erase(const_iterator __position
)
612 { return _M_t
.erase(__position
); }
615 * @brief Erases an element from a %map.
616 * @param position An iterator pointing to the element to be erased.
618 * This function erases an element, pointed to by the given
619 * iterator, from a %map. Note that this function only erases
620 * the element, and that if the element is itself a pointer,
621 * the pointed-to memory is not touched in any way. Managing
622 * the pointer is the user's responsibility.
625 erase(iterator __position
)
626 { _M_t
.erase(__position
); }
630 * @brief Erases elements according to the provided key.
631 * @param x Key of element to be erased.
632 * @return The number of elements erased.
634 * This function erases all the elements located by the given key from
636 * Note that this function only erases the element, and that if
637 * the element is itself a pointer, the pointed-to memory is not touched
638 * in any way. Managing the pointer is the user's responsibility.
641 erase(const key_type
& __x
)
642 { return _M_t
.erase(__x
); }
644 #ifdef __GXX_EXPERIMENTAL_CXX0X__
645 // _GLIBCXX_RESOLVE_LIB_DEFECTS
646 // DR 130. Associative erase should return an iterator.
648 * @brief Erases a [first,last) range of elements from a %map.
649 * @param first Iterator pointing to the start of the range to be
651 * @param last Iterator pointing to the end of the range to be erased.
652 * @return The iterator @a last.
654 * This function erases a sequence of elements from a %map.
655 * Note that this function only erases the element, and that if
656 * the element is itself a pointer, the pointed-to memory is not touched
657 * in any way. Managing the pointer is the user's responsibility.
660 erase(const_iterator __first
, const_iterator __last
)
661 { return _M_t
.erase(__first
, __last
); }
664 * @brief Erases a [first,last) range of elements from a %map.
665 * @param first Iterator pointing to the start of the range to be
667 * @param last Iterator pointing to the end of the range to be erased.
669 * This function erases a sequence of elements from a %map.
670 * Note that this function only erases the element, and that if
671 * the element is itself a pointer, the pointed-to memory is not touched
672 * in any way. Managing the pointer is the user's responsibility.
675 erase(iterator __first
, iterator __last
)
676 { _M_t
.erase(__first
, __last
); }
680 * @brief Swaps data with another %map.
681 * @param x A %map of the same element and allocator types.
683 * This exchanges the elements between two maps in constant
684 * time. (It is only swapping a pointer, an integer, and an
685 * instance of the @c Compare type (which itself is often
686 * stateless and empty), so it should be quite fast.) Note
687 * that the global std::swap() function is specialized such
688 * that std::swap(m1,m2) will feed to this function.
692 { _M_t
.swap(__x
._M_t
); }
695 * Erases all elements in a %map. Note that this function only
696 * erases the elements, and that if the elements themselves are
697 * pointers, the pointed-to memory is not touched in any way.
698 * Managing the pointer is the user's responsibility.
706 * Returns the key comparison object out of which the %map was
711 { return _M_t
.key_comp(); }
714 * Returns a value comparison object, built from the key comparison
715 * object out of which the %map was constructed.
719 { return value_compare(_M_t
.key_comp()); }
721 // [23.3.1.3] map operations
723 * @brief Tries to locate an element in a %map.
724 * @param x Key of (key, value) %pair to be located.
725 * @return Iterator pointing to sought-after element, or end() if not
728 * This function takes a key and tries to locate the element with which
729 * the key matches. If successful the function returns an iterator
730 * pointing to the sought after %pair. If unsuccessful it returns the
731 * past-the-end ( @c end() ) iterator.
734 find(const key_type
& __x
)
735 { return _M_t
.find(__x
); }
738 * @brief Tries to locate an element in a %map.
739 * @param x Key of (key, value) %pair to be located.
740 * @return Read-only (constant) iterator pointing to sought-after
741 * element, or end() if not found.
743 * This function takes a key and tries to locate the element with which
744 * the key matches. If successful the function returns a constant
745 * iterator pointing to the sought after %pair. If unsuccessful it
746 * returns the past-the-end ( @c end() ) iterator.
749 find(const key_type
& __x
) const
750 { return _M_t
.find(__x
); }
753 * @brief Finds the number of elements with given key.
754 * @param x Key of (key, value) pairs to be located.
755 * @return Number of elements with specified key.
757 * This function only makes sense for multimaps; for map the result will
758 * either be 0 (not present) or 1 (present).
761 count(const key_type
& __x
) const
762 { return _M_t
.find(__x
) == _M_t
.end() ? 0 : 1; }
765 * @brief Finds the beginning of a subsequence matching given key.
766 * @param x Key of (key, value) pair to be located.
767 * @return Iterator pointing to first element equal to or greater
768 * than key, or end().
770 * This function returns the first element of a subsequence of elements
771 * that matches the given key. If unsuccessful it returns an iterator
772 * pointing to the first element that has a greater value than given key
773 * or end() if no such element exists.
776 lower_bound(const key_type
& __x
)
777 { return _M_t
.lower_bound(__x
); }
780 * @brief Finds the beginning of a subsequence matching given key.
781 * @param x Key of (key, value) pair to be located.
782 * @return Read-only (constant) iterator pointing to first element
783 * equal to or greater than key, or end().
785 * This function returns the first element of a subsequence of elements
786 * that matches the given key. If unsuccessful it returns an iterator
787 * pointing to the first element that has a greater value than given key
788 * or end() if no such element exists.
791 lower_bound(const key_type
& __x
) const
792 { return _M_t
.lower_bound(__x
); }
795 * @brief Finds the end of a subsequence matching given key.
796 * @param x Key of (key, value) pair to be located.
797 * @return Iterator pointing to the first element
798 * greater than key, or end().
801 upper_bound(const key_type
& __x
)
802 { return _M_t
.upper_bound(__x
); }
805 * @brief Finds the end of a subsequence matching given key.
806 * @param x Key of (key, value) pair to be located.
807 * @return Read-only (constant) iterator pointing to first iterator
808 * greater than key, or end().
811 upper_bound(const key_type
& __x
) const
812 { return _M_t
.upper_bound(__x
); }
815 * @brief Finds a subsequence matching given key.
816 * @param x Key of (key, value) pairs to be located.
817 * @return Pair of iterators that possibly points to the subsequence
818 * matching given key.
820 * This function is equivalent to
822 * std::make_pair(c.lower_bound(val),
823 * c.upper_bound(val))
825 * (but is faster than making the calls separately).
827 * This function probably only makes sense for multimaps.
829 std::pair
<iterator
, iterator
>
830 equal_range(const key_type
& __x
)
831 { return _M_t
.equal_range(__x
); }
834 * @brief Finds a subsequence matching given key.
835 * @param x Key of (key, value) pairs to be located.
836 * @return Pair of read-only (constant) iterators that possibly points
837 * to the subsequence matching given key.
839 * This function is equivalent to
841 * std::make_pair(c.lower_bound(val),
842 * c.upper_bound(val))
844 * (but is faster than making the calls separately).
846 * This function probably only makes sense for multimaps.
848 std::pair
<const_iterator
, const_iterator
>
849 equal_range(const key_type
& __x
) const
850 { return _M_t
.equal_range(__x
); }
852 template<typename _K1
, typename _T1
, typename _C1
, typename _A1
>
854 operator==(const map
<_K1
, _T1
, _C1
, _A1
>&,
855 const map
<_K1
, _T1
, _C1
, _A1
>&);
857 template<typename _K1
, typename _T1
, typename _C1
, typename _A1
>
859 operator<(const map
<_K1
, _T1
, _C1
, _A1
>&,
860 const map
<_K1
, _T1
, _C1
, _A1
>&);
864 * @brief Map equality comparison.
866 * @param y A %map of the same type as @a x.
867 * @return True iff the size and elements of the maps are equal.
869 * This is an equivalence relation. It is linear in the size of the
870 * maps. Maps are considered equivalent if their sizes are equal,
871 * and if corresponding elements compare equal.
873 template<typename _Key
, typename _Tp
, typename _Compare
, typename _Alloc
>
875 operator==(const map
<_Key
, _Tp
, _Compare
, _Alloc
>& __x
,
876 const map
<_Key
, _Tp
, _Compare
, _Alloc
>& __y
)
877 { return __x
._M_t
== __y
._M_t
; }
880 * @brief Map ordering relation.
882 * @param y A %map of the same type as @a x.
883 * @return True iff @a x is lexicographically less than @a y.
885 * This is a total ordering relation. It is linear in the size of the
886 * maps. The elements must be comparable with @c <.
888 * See std::lexicographical_compare() for how the determination is made.
890 template<typename _Key
, typename _Tp
, typename _Compare
, typename _Alloc
>
892 operator<(const map
<_Key
, _Tp
, _Compare
, _Alloc
>& __x
,
893 const map
<_Key
, _Tp
, _Compare
, _Alloc
>& __y
)
894 { return __x
._M_t
< __y
._M_t
; }
896 /// Based on operator==
897 template<typename _Key
, typename _Tp
, typename _Compare
, typename _Alloc
>
899 operator!=(const map
<_Key
, _Tp
, _Compare
, _Alloc
>& __x
,
900 const map
<_Key
, _Tp
, _Compare
, _Alloc
>& __y
)
901 { return !(__x
== __y
); }
903 /// Based on operator<
904 template<typename _Key
, typename _Tp
, typename _Compare
, typename _Alloc
>
906 operator>(const map
<_Key
, _Tp
, _Compare
, _Alloc
>& __x
,
907 const map
<_Key
, _Tp
, _Compare
, _Alloc
>& __y
)
908 { return __y
< __x
; }
910 /// Based on operator<
911 template<typename _Key
, typename _Tp
, typename _Compare
, typename _Alloc
>
913 operator<=(const map
<_Key
, _Tp
, _Compare
, _Alloc
>& __x
,
914 const map
<_Key
, _Tp
, _Compare
, _Alloc
>& __y
)
915 { return !(__y
< __x
); }
917 /// Based on operator<
918 template<typename _Key
, typename _Tp
, typename _Compare
, typename _Alloc
>
920 operator>=(const map
<_Key
, _Tp
, _Compare
, _Alloc
>& __x
,
921 const map
<_Key
, _Tp
, _Compare
, _Alloc
>& __y
)
922 { return !(__x
< __y
); }
924 /// See std::map::swap().
925 template<typename _Key
, typename _Tp
, typename _Compare
, typename _Alloc
>
927 swap(map
<_Key
, _Tp
, _Compare
, _Alloc
>& __x
,
928 map
<_Key
, _Tp
, _Compare
, _Alloc
>& __y
)
931 _GLIBCXX_END_NESTED_NAMESPACE
933 #endif /* _STL_MAP_H */