61 #if __cplusplus >= 201103L 66 namespace std _GLIBCXX_VISIBILITY(default)
68 _GLIBCXX_BEGIN_NAMESPACE_VERSION
69 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
71 template <
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
98 template <
typename _Key,
typename _Tp,
typename _Compare = std::less<_Key>,
99 typename _Alloc = std::allocator<std::pair<const _Key, _Tp> > >
103 typedef _Key key_type;
104 typedef _Tp mapped_type;
106 typedef _Compare key_compare;
107 typedef _Alloc allocator_type;
110 #ifdef _GLIBCXX_CONCEPT_CHECKS 112 typedef typename _Alloc::value_type _Alloc_value_type;
113 # if __cplusplus < 201103L 114 __glibcxx_class_requires(_Tp, _SGIAssignableConcept)
116 __glibcxx_class_requires4(_Compare,
bool, _Key, _Key,
117 _BinaryFunctionConcept)
118 __glibcxx_class_requires2(
value_type, _Alloc_value_type, _SameTypeConcept)
121 #if __cplusplus >= 201103L && defined(__STRICT_ANSI__) 123 "std::map must have the same value_type as its allocator");
130 friend class map<_Key, _Tp, _Compare, _Alloc>;
134 value_compare(_Compare __c)
145 rebind<value_type>::other _Pair_alloc_type;
147 typedef _Rb_tree<key_type, value_type, _Select1st<value_type>,
148 key_compare, _Pair_alloc_type> _Rep_type;
158 typedef typename _Alloc_traits::pointer pointer;
159 typedef typename _Alloc_traits::const_pointer const_pointer;
160 typedef typename _Alloc_traits::reference reference;
161 typedef typename _Alloc_traits::const_reference const_reference;
162 typedef typename _Rep_type::iterator iterator;
163 typedef typename _Rep_type::const_iterator const_iterator;
164 typedef typename _Rep_type::size_type size_type;
165 typedef typename _Rep_type::difference_type difference_type;
169 #if __cplusplus > 201402L 170 using node_type =
typename _Rep_type::node_type;
171 using insert_return_type =
typename _Rep_type::insert_return_type;
180 #if __cplusplus < 201103L 192 map(
const _Compare& __comp,
193 const allocator_type& __a = allocator_type())
194 : _M_t(__comp, _Pair_alloc_type(__a)) { }
201 #if __cplusplus < 201103L 205 map(
const map&) =
default;
227 const _Compare& __comp = _Compare(),
228 const allocator_type& __a = allocator_type())
229 : _M_t(__comp, _Pair_alloc_type(__a))
230 { _M_t._M_insert_unique(__l.begin(), __l.end()); }
234 map(
const allocator_type& __a)
235 : _M_t(_Compare(), _Pair_alloc_type(__a)) { }
238 map(
const map& __m,
const allocator_type& __a)
239 : _M_t(__m._M_t, _Pair_alloc_type(__a)) { }
242 map(
map&& __m,
const allocator_type& __a)
244 && _Alloc_traits::_S_always_equal())
245 : _M_t(
std::move(__m._M_t), _Pair_alloc_type(__a)) { }
249 : _M_t(_Compare(), _Pair_alloc_type(__a))
250 { _M_t._M_insert_unique(__l.begin(), __l.end()); }
253 template<
typename _InputIterator>
254 map(_InputIterator __first, _InputIterator __last,
255 const allocator_type& __a)
256 : _M_t(_Compare(), _Pair_alloc_type(__a))
257 { _M_t._M_insert_unique(__first, __last); }
270 template<
typename _InputIterator>
271 map(_InputIterator __first, _InputIterator __last)
273 { _M_t._M_insert_unique(__first, __last); }
287 template<
typename _InputIterator>
288 map(_InputIterator __first, _InputIterator __last,
289 const _Compare& __comp,
290 const allocator_type& __a = allocator_type())
291 : _M_t(__comp, _Pair_alloc_type(__a))
292 { _M_t._M_insert_unique(__first, __last); }
294 #if __cplusplus >= 201103L 308 #if __cplusplus < 201103L 337 _M_t._M_assign_unique(__l.begin(), __l.end());
345 {
return allocator_type(_M_t.get_allocator()); }
355 {
return _M_t.begin(); }
364 {
return _M_t.begin(); }
373 {
return _M_t.end(); }
381 end() const _GLIBCXX_NOEXCEPT
382 {
return _M_t.end(); }
391 {
return _M_t.rbegin(); }
398 const_reverse_iterator
400 {
return _M_t.rbegin(); }
409 {
return _M_t.rend(); }
416 const_reverse_iterator
418 {
return _M_t.rend(); }
420 #if __cplusplus >= 201103L 428 {
return _M_t.begin(); }
437 {
return _M_t.end(); }
444 const_reverse_iterator
446 {
return _M_t.rbegin(); }
453 const_reverse_iterator
455 {
return _M_t.rend(); }
464 {
return _M_t.empty(); }
469 {
return _M_t.size(); }
474 {
return _M_t.max_size(); }
493 __glibcxx_function_requires(_DefaultConstructibleConcept<mapped_type>)
498 #if __cplusplus >= 201103L 505 return (*__i).second;
508 #if __cplusplus >= 201103L 513 __glibcxx_function_requires(_DefaultConstructibleConcept<mapped_type>)
519 std::forward_as_tuple(std::move(__k)),
521 return (*__i).second;
535 at(
const key_type& __k)
539 __throw_out_of_range(__N(
"map::at"));
540 return (*__i).second;
544 at(
const key_type& __k)
const 548 __throw_out_of_range(__N(
"map::at"));
549 return (*__i).second;
553 #if __cplusplus >= 201103L 572 template<
typename... _Args>
575 {
return _M_t._M_emplace_unique(std::forward<_Args>(__args)...); }
602 template<
typename... _Args>
606 return _M_t._M_emplace_hint_unique(__pos,
607 std::forward<_Args>(__args)...);
611 #if __cplusplus > 201402L 614 extract(const_iterator __pos)
616 __glibcxx_assert(__pos !=
end());
617 return _M_t.extract(__pos);
622 extract(
const key_type& __x)
623 {
return _M_t.extract(__x); }
628 {
return _M_t._M_reinsert_node_unique(std::move(__nh)); }
632 insert(const_iterator __hint, node_type&& __nh)
633 {
return _M_t._M_reinsert_node_hint_unique(__hint, std::move(__nh)); }
635 template<
typename,
typename>
636 friend class std::_Rb_tree_merge_helper;
638 template<
typename _C2>
640 merge(map<_Key, _Tp, _C2, _Alloc>& __source)
642 using _Merge_helper = _Rb_tree_merge_helper<map, _C2>;
643 _M_t._M_merge_unique(_Merge_helper::_S_get_tree(__source));
646 template<
typename _C2>
648 merge(map<_Key, _Tp, _C2, _Alloc>&& __source)
651 template<
typename _C2>
653 merge(multimap<_Key, _Tp, _C2, _Alloc>& __source)
655 using _Merge_helper = _Rb_tree_merge_helper<map, _C2>;
656 _M_t._M_merge_unique(_Merge_helper::_S_get_tree(__source));
659 template<
typename _C2>
661 merge(multimap<_Key, _Tp, _C2, _Alloc>&& __source)
665 #if __cplusplus > 201402L 666 #define __cpp_lib_map_try_emplace 201411 687 template <
typename... _Args>
689 try_emplace(
const key_type& __k, _Args&&... __args)
695 std::forward_as_tuple(__k),
696 std::forward_as_tuple(
697 std::forward<_Args>(__args)...));
704 template <
typename... _Args>
706 try_emplace(key_type&& __k, _Args&&... __args)
712 std::forward_as_tuple(std::move(__k)),
713 std::forward_as_tuple(
714 std::forward<_Args>(__args)...));
747 template <
typename... _Args>
749 try_emplace(const_iterator __hint,
const key_type& __k,
753 auto __true_hint = _M_t._M_get_insert_hint_unique_pos(__hint, __k);
754 if (__true_hint.second)
757 std::forward_as_tuple(__k),
758 std::forward_as_tuple(
759 std::forward<_Args>(__args)...));
761 __i = iterator(__true_hint.first);
766 template <
typename... _Args>
768 try_emplace(const_iterator __hint, key_type&& __k, _Args&&... __args)
771 auto __true_hint = _M_t._M_get_insert_hint_unique_pos(__hint, __k);
772 if (__true_hint.second)
775 std::forward_as_tuple(std::move(__k)),
776 std::forward_as_tuple(
777 std::forward<_Args>(__args)...));
779 __i = iterator(__true_hint.first);
802 {
return _M_t._M_insert_unique(__x); }
804 #if __cplusplus >= 201103L 809 {
return _M_t._M_insert_unique(std::move(__x)); }
811 template<
typename _Pair>
812 __enable_if_t<is_constructible<value_type, _Pair>::value,
815 {
return _M_t._M_emplace_unique(std::forward<_Pair>(__x)); }
819 #if __cplusplus >= 201103L 829 {
insert(__list.begin(), __list.end()); }
857 #if __cplusplus >= 201103L 862 {
return _M_t._M_insert_unique_(__position, __x); }
864 #if __cplusplus >= 201103L 869 {
return _M_t._M_insert_unique_(__position, std::move(__x)); }
871 template<
typename _Pair>
872 __enable_if_t<is_constructible<value_type, _Pair>::value,
iterator>
873 insert(const_iterator __position, _Pair&& __x)
875 return _M_t._M_emplace_hint_unique(__position,
876 std::forward<_Pair>(__x));
889 template<
typename _InputIterator>
891 insert(_InputIterator __first, _InputIterator __last)
892 { _M_t._M_insert_unique(__first, __last); }
894 #if __cplusplus > 201402L 895 #define __cpp_lib_map_insertion 201411 915 template <
typename _Obj>
917 insert_or_assign(
const key_type& __k, _Obj&& __obj)
923 std::forward_as_tuple(__k),
924 std::forward_as_tuple(
925 std::forward<_Obj>(__obj)));
928 (*__i).second = std::forward<_Obj>(__obj);
933 template <
typename _Obj>
935 insert_or_assign(key_type&& __k, _Obj&& __obj)
941 std::forward_as_tuple(std::move(__k)),
942 std::forward_as_tuple(
943 std::forward<_Obj>(__obj)));
946 (*__i).second = std::forward<_Obj>(__obj);
970 template <
typename _Obj>
972 insert_or_assign(const_iterator __hint,
973 const key_type& __k, _Obj&& __obj)
976 auto __true_hint = _M_t._M_get_insert_hint_unique_pos(__hint, __k);
977 if (__true_hint.second)
981 std::forward_as_tuple(__k),
982 std::forward_as_tuple(
983 std::forward<_Obj>(__obj)));
985 __i = iterator(__true_hint.first);
986 (*__i).second = std::forward<_Obj>(__obj);
991 template <
typename _Obj>
993 insert_or_assign(const_iterator __hint, key_type&& __k, _Obj&& __obj)
996 auto __true_hint = _M_t._M_get_insert_hint_unique_pos(__hint, __k);
997 if (__true_hint.second)
1001 std::forward_as_tuple(std::move(__k)),
1002 std::forward_as_tuple(
1003 std::forward<_Obj>(__obj)));
1005 __i = iterator(__true_hint.first);
1006 (*__i).second = std::forward<_Obj>(__obj);
1011 #if __cplusplus >= 201103L 1031 {
return _M_t.erase(__position); }
1034 _GLIBCXX_ABI_TAG_CXX11
1037 {
return _M_t.erase(__position); }
1052 { _M_t.erase(__position); }
1068 {
return _M_t.erase(__x); }
1070 #if __cplusplus >= 201103L 1087 erase(const_iterator __first, const_iterator __last)
1088 {
return _M_t.erase(__first, __last); }
1104 { _M_t.erase(__first, __last); }
1122 _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value)
1123 { _M_t.swap(__x._M_t); }
1142 {
return _M_t.key_comp(); }
1150 {
return value_compare(_M_t.key_comp()); }
1169 {
return _M_t.find(__x); }
1171 #if __cplusplus > 201103L 1172 template<
typename _Kt>
1174 find(
const _Kt& __x) -> decltype(_M_t._M_find_tr(__x))
1175 {
return _M_t._M_find_tr(__x); }
1194 {
return _M_t.find(__x); }
1196 #if __cplusplus > 201103L 1197 template<
typename _Kt>
1199 find(
const _Kt& __x)
const -> decltype(_M_t._M_find_tr(__x))
1200 {
return _M_t._M_find_tr(__x); }
1215 {
return _M_t.find(__x) == _M_t.end() ? 0 : 1; }
1217 #if __cplusplus > 201103L 1218 template<
typename _Kt>
1220 count(
const _Kt& __x)
const -> decltype(_M_t._M_count_tr(__x))
1221 {
return _M_t._M_count_tr(__x); }
1239 {
return _M_t.lower_bound(__x); }
1241 #if __cplusplus > 201103L 1242 template<
typename _Kt>
1245 -> decltype(iterator(_M_t._M_lower_bound_tr(__x)))
1246 {
return iterator(_M_t._M_lower_bound_tr(__x)); }
1264 {
return _M_t.lower_bound(__x); }
1266 #if __cplusplus > 201103L 1267 template<
typename _Kt>
1270 -> decltype(const_iterator(_M_t._M_lower_bound_tr(__x)))
1271 {
return const_iterator(_M_t._M_lower_bound_tr(__x)); }
1284 {
return _M_t.upper_bound(__x); }
1286 #if __cplusplus > 201103L 1287 template<
typename _Kt>
1290 -> decltype(iterator(_M_t._M_upper_bound_tr(__x)))
1291 {
return iterator(_M_t._M_upper_bound_tr(__x)); }
1304 {
return _M_t.upper_bound(__x); }
1306 #if __cplusplus > 201103L 1307 template<
typename _Kt>
1310 -> decltype(const_iterator(_M_t._M_upper_bound_tr(__x)))
1311 {
return const_iterator(_M_t._M_upper_bound_tr(__x)); }
1333 {
return _M_t.equal_range(__x); }
1335 #if __cplusplus > 201103L 1336 template<
typename _Kt>
1362 {
return _M_t.equal_range(__x); }
1364 #if __cplusplus > 201103L 1365 template<
typename _Kt>
1369 _M_t._M_equal_range_tr(__x)))
1372 _M_t._M_equal_range_tr(__x));
1377 template<
typename _K1,
typename _T1,
typename _C1,
typename _A1>
1382 template<
typename _K1,
typename _T1,
typename _C1,
typename _A1>
1389 #if __cpp_deduction_guides >= 201606 1391 template<
typename _InputIterator,
1392 typename _Compare = less<__iter_key_t<_InputIterator>>,
1393 typename _Allocator = allocator<__iter_to_alloc_t<_InputIterator>>,
1394 typename = _RequireInputIter<_InputIterator>,
1395 typename = _RequireAllocator<_Allocator>>
1396 map(_InputIterator, _InputIterator,
1397 _Compare = _Compare(), _Allocator = _Allocator())
1398 -> map<__iter_key_t<_InputIterator>, __iter_val_t<_InputIterator>,
1399 _Compare, _Allocator>;
1401 template<
typename _Key,
typename _Tp,
typename _Compare = less<_Key>,
1402 typename _Allocator = allocator<pair<const _Key, _Tp>>,
1403 typename = _RequireAllocator<_Allocator>>
1404 map(initializer_list<pair<_Key, _Tp>>,
1405 _Compare = _Compare(), _Allocator = _Allocator())
1406 -> map<_Key, _Tp, _Compare, _Allocator>;
1408 template <
typename _InputIterator,
typename _Allocator,
1409 typename = _RequireInputIter<_InputIterator>,
1410 typename = _RequireAllocator<_Allocator>>
1411 map(_InputIterator, _InputIterator, _Allocator)
1412 -> map<__iter_key_t<_InputIterator>, __iter_val_t<_InputIterator>,
1413 less<__iter_key_t<_InputIterator>>, _Allocator>;
1415 template<
typename _Key,
typename _Tp,
typename _Allocator,
1416 typename = _RequireAllocator<_Allocator>>
1417 map(initializer_list<pair<_Key, _Tp>>, _Allocator)
1418 -> map<_Key, _Tp, less<_Key>, _Allocator>;
1432 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1436 {
return __x._M_t == __y._M_t; }
1449 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1453 {
return __x._M_t < __y._M_t; }
1456 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1460 {
return !(__x == __y); }
1463 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1467 {
return __y < __x; }
1470 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1474 {
return !(__y < __x); }
1477 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1481 {
return !(__x < __y); }
1484 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1488 _GLIBCXX_NOEXCEPT_IF(noexcept(__x.swap(__y)))
1491 _GLIBCXX_END_NAMESPACE_CONTAINER
1493 #if __cplusplus > 201402L 1495 template<
typename _Key,
typename _Val,
typename _Cmp1,
typename _Alloc,
1498 _Rb_tree_merge_helper<_GLIBCXX_STD_C::map<_Key, _Val, _Cmp1, _Alloc>,
1502 friend class _GLIBCXX_STD_C::map<_Key, _Val, _Cmp1, _Alloc>;
1505 _S_get_tree(_GLIBCXX_STD_C::map<_Key, _Val, _Cmp2, _Alloc>& __map)
1506 {
return __map._M_t; }
1509 _S_get_tree(_GLIBCXX_STD_C::multimap<_Key, _Val, _Cmp2, _Alloc>& __map)
1510 {
return __map._M_t; }
1514 _GLIBCXX_END_NAMESPACE_VERSION
auto lower_bound(const _Kt &__x) const -> decltype(const_iterator(_M_t._M_lower_bound_tr(__x)))
Finds the beginning of a subsequence matching given key.
A standard container made up of (key,value) pairs, which can be retrieved based on a key,...
map(_InputIterator __first, _InputIterator __last, const _Compare &__comp, const allocator_type &__a=allocator_type())
Builds a map from a range.
auto lower_bound(const _Kt &__x) -> decltype(iterator(_M_t._M_lower_bound_tr(__x)))
Finds the beginning of a subsequence matching given key.
map()=default
Default constructor creates no elements.
map(const _Compare &__comp, const allocator_type &__a=allocator_type())
Creates a map with no elements.
auto upper_bound(const _Kt &__x) -> decltype(iterator(_M_t._M_upper_bound_tr(__x)))
Finds the end of a subsequence matching given key.
const_iterator lower_bound(const key_type &__x) const
Finds the beginning of a subsequence matching given key.
Struct holding two objects of arbitrary type.
reverse_iterator rend() noexcept
reverse_iterator rbegin() noexcept
map(_InputIterator __first, _InputIterator __last, const allocator_type &__a)
Allocator-extended range constructor.
map(map &&__m, const allocator_type &__a) noexcept(is_nothrow_copy_constructible< _Compare >::value &&_Alloc_traits::_S_always_equal())
Allocator-extended move constructor.
iterator insert(const_iterator __position, const value_type &__x)
Attempts to insert a std::pair into the map.
map & operator=(initializer_list< value_type > __l)
Map list assignment operator.
const_iterator upper_bound(const key_type &__x) const
Finds the end of a subsequence matching given key.
iterator erase(const_iterator __first, const_iterator __last)
Erases a [first,last) range of elements from a map.
auto find(const _Kt &__x) -> decltype(_M_t._M_find_tr(__x))
Tries to locate an element in a map.
iterator lower_bound(const key_type &__x)
Finds the beginning of a subsequence matching given key.
const_iterator find(const key_type &__x) const
Tries to locate an element in a map.
map(initializer_list< value_type > __l, const allocator_type &__a)
Allocator-extended initialier-list constructor.
size_type size() const noexcept
map(_InputIterator __first, _InputIterator __last)
Builds a map from a range.
const_iterator end() const noexcept
map(const map &__m, const allocator_type &__a)
Allocator-extended copy constructor.
const_iterator cend() const noexcept
const_reverse_iterator rbegin() const noexcept
void insert(_InputIterator __first, _InputIterator __last)
Template function that attempts to insert a range of elements.
iterator insert(const_iterator __position, value_type &&__x)
Attempts to insert a std::pair into the map.
auto equal_range(const _Kt &__x) const -> decltype(pair< const_iterator, const_iterator >(_M_t._M_equal_range_tr(__x)))
Finds a subsequence matching given key.
std::pair< const_iterator, const_iterator > equal_range(const key_type &__x) const
Finds a subsequence matching given key.
const_reverse_iterator rend() const noexcept
ISO C++ entities toplevel namespace is std.
auto equal_range(const _Kt &__x) -> decltype(pair< iterator, iterator >(_M_t._M_equal_range_tr(__x)))
Finds a subsequence matching given key.
is_nothrow_copy_constructible
size_type max_size() const noexcept
mapped_type & at(const key_type &__k)
Access to map data.
auto upper_bound(const _Kt &__x) const -> decltype(const_iterator(_M_t._M_upper_bound_tr(__x)))
Finds the end of a subsequence matching given key.
iterator emplace_hint(const_iterator __pos, _Args &&... __args)
Attempts to build and insert a std::pair into the map.
__enable_if_t< is_constructible< value_type, _Pair >::value, iterator > insert(const_iterator __position, _Pair &&__x)
Attempts to insert a std::pair into the map.
void insert(std::initializer_list< value_type > __list)
Attempts to insert a list of std::pairs into the map.
key_compare key_comp() const
void swap(map &__x) noexcept(/*conditional */)
Swaps data with another map.
bool empty() const noexcept
iterator begin() noexcept
mapped_type & operator[](const key_type &__k)
Subscript ( [] ) access to map data.
auto count(const _Kt &__x) const -> decltype(_M_t._M_count_tr(__x))
Finds the number of elements with given key.
iterator erase(const_iterator __position)
Erases an element from a map.
Primary class template, tuple.
allocator_type get_allocator() const noexcept
Get a copy of the memory allocation object.
auto find(const _Kt &__x) const -> decltype(_M_t._M_find_tr(__x))
Tries to locate an element in a map.
std::pair< iterator, iterator > equal_range(const key_type &__x)
Finds a subsequence matching given key.
const_reverse_iterator crend() const noexcept
__enable_if_t< is_constructible< value_type, _Pair >::value, pair< iterator, bool > > insert(_Pair &&__x)
Attempts to insert a std::pair into the map.
iterator find(const key_type &__x)
Tries to locate an element in a map.
Uniform interface to C++98 and C++11 allocators.
iterator upper_bound(const key_type &__x)
Finds the end of a subsequence matching given key.
map & operator=(const map &)=default
Map assignment operator.
map(initializer_list< value_type > __l, const _Compare &__comp=_Compare(), const allocator_type &__a=allocator_type())
Builds a map from an initializer_list.
size_type count(const key_type &__x) const
Finds the number of elements with given key.
_T1 first
second_type is the second bound type
_GLIBCXX_ABI_TAG_CXX11 iterator erase(iterator __position)
Erases an element from a map.
map(const allocator_type &__a)
Allocator-extended default constructor.
std::pair< iterator, bool > insert(const value_type &__x)
Attempts to insert a std::pair into the map.
_GLIBCXX17_INLINE constexpr piecewise_construct_t piecewise_construct
piecewise_construct
A standard container made up of (key,value) pairs, which can be retrieved based on a key,...
value_compare value_comp() const
size_type erase(const key_type &__x)
Erases elements according to the provided key.
std::pair< iterator, bool > emplace(_Args &&... __args)
Attempts to build and insert a std::pair into the map.
const_iterator cbegin() const noexcept
std::pair< iterator, bool > insert(value_type &&__x)
Attempts to insert a std::pair into the map.
const_reverse_iterator crbegin() const noexcept
const_iterator begin() const noexcept