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
122 #if __cplusplus > 201703L || defined __STRICT_ANSI__
124 "std::map must have the same value_type as its allocator");
132 friend class map<_Key, _Tp, _Compare, _Alloc>;
136 value_compare(_Compare __c)
147 rebind<value_type>::other _Pair_alloc_type;
149 typedef _Rb_tree<key_type, value_type, _Select1st<value_type>,
150 key_compare, _Pair_alloc_type> _Rep_type;
160 typedef typename _Alloc_traits::pointer pointer;
161 typedef typename _Alloc_traits::const_pointer const_pointer;
162 typedef typename _Alloc_traits::reference reference;
163 typedef typename _Alloc_traits::const_reference const_reference;
164 typedef typename _Rep_type::iterator iterator;
165 typedef typename _Rep_type::const_iterator const_iterator;
166 typedef typename _Rep_type::size_type size_type;
167 typedef typename _Rep_type::difference_type difference_type;
171 #if __cplusplus > 201402L
172 using node_type =
typename _Rep_type::node_type;
173 using insert_return_type =
typename _Rep_type::insert_return_type;
182 #if __cplusplus < 201103L
194 map(
const _Compare& __comp,
195 const allocator_type& __a = allocator_type())
196 : _M_t(__comp, _Pair_alloc_type(__a)) { }
203 #if __cplusplus < 201103L
207 map(
const map&) =
default;
229 const _Compare& __comp = _Compare(),
230 const allocator_type& __a = allocator_type())
231 : _M_t(__comp, _Pair_alloc_type(__a))
232 { _M_t._M_insert_range_unique(__l.begin(), __l.end()); }
236 map(
const allocator_type& __a)
237 : _M_t(_Pair_alloc_type(__a)) { }
240 map(
const map& __m,
const allocator_type& __a)
241 : _M_t(__m._M_t, _Pair_alloc_type(__a)) { }
244 map(
map&& __m,
const allocator_type& __a)
246 && _Alloc_traits::_S_always_equal())
247 : _M_t(
std::
move(__m._M_t), _Pair_alloc_type(__a)) { }
251 : _M_t(_Pair_alloc_type(__a))
252 { _M_t._M_insert_range_unique(__l.begin(), __l.end()); }
255 template<
typename _InputIterator>
256 map(_InputIterator __first, _InputIterator __last,
257 const allocator_type& __a)
258 : _M_t(_Pair_alloc_type(__a))
259 { _M_t._M_insert_range_unique(__first, __last); }
272 template<
typename _InputIterator>
273 map(_InputIterator __first, _InputIterator __last)
275 { _M_t._M_insert_range_unique(__first, __last); }
289 template<
typename _InputIterator>
290 map(_InputIterator __first, _InputIterator __last,
291 const _Compare& __comp,
292 const allocator_type& __a = allocator_type())
293 : _M_t(__comp, _Pair_alloc_type(__a))
294 { _M_t._M_insert_range_unique(__first, __last); }
296 #if __cplusplus >= 201103L
310 #if __cplusplus < 201103L
339 _M_t._M_assign_unique(__l.begin(), __l.end());
347 {
return allocator_type(_M_t.get_allocator()); }
357 {
return _M_t.begin(); }
366 {
return _M_t.begin(); }
375 {
return _M_t.end(); }
383 end() const _GLIBCXX_NOEXCEPT
384 {
return _M_t.end(); }
393 {
return _M_t.rbegin(); }
400 const_reverse_iterator
402 {
return _M_t.rbegin(); }
411 {
return _M_t.rend(); }
418 const_reverse_iterator
420 {
return _M_t.rend(); }
422 #if __cplusplus >= 201103L
430 {
return _M_t.begin(); }
439 {
return _M_t.end(); }
446 const_reverse_iterator
448 {
return _M_t.rbegin(); }
455 const_reverse_iterator
457 {
return _M_t.rend(); }
464 _GLIBCXX_NODISCARD
bool
466 {
return _M_t.empty(); }
471 {
return _M_t.size(); }
476 {
return _M_t.max_size(); }
495 __glibcxx_function_requires(_DefaultConstructibleConcept<mapped_type>)
500 #if __cplusplus >= 201103L
507 return (*__i).second;
510 #if __cplusplus >= 201103L
515 __glibcxx_function_requires(_DefaultConstructibleConcept<mapped_type>)
523 return (*__i).second;
537 at(
const key_type& __k)
541 __throw_out_of_range(__N(
"map::at"));
542 return (*__i).second;
546 at(
const key_type& __k)
const
550 __throw_out_of_range(__N(
"map::at"));
551 return (*__i).second;
555 #if __cplusplus >= 201103L
574 template<
typename... _Args>
577 {
return _M_t._M_emplace_unique(std::forward<_Args>(__args)...); }
604 template<
typename... _Args>
608 return _M_t._M_emplace_hint_unique(__pos,
609 std::forward<_Args>(__args)...);
613 #if __cplusplus > 201402L
616 extract(const_iterator __pos)
618 __glibcxx_assert(__pos !=
end());
619 return _M_t.extract(__pos);
624 extract(
const key_type& __x)
625 {
return _M_t.extract(__x); }
630 {
return _M_t._M_reinsert_node_unique(
std::move(__nh)); }
634 insert(const_iterator __hint, node_type&& __nh)
635 {
return _M_t._M_reinsert_node_hint_unique(__hint,
std::move(__nh)); }
637 template<
typename,
typename>
638 friend class std::_Rb_tree_merge_helper;
640 template<
typename _Cmp2>
642 merge(map<_Key, _Tp, _Cmp2, _Alloc>& __source)
644 using _Merge_helper = _Rb_tree_merge_helper<map, _Cmp2>;
645 _M_t._M_merge_unique(_Merge_helper::_S_get_tree(__source));
648 template<
typename _Cmp2>
650 merge(map<_Key, _Tp, _Cmp2, _Alloc>&& __source)
653 template<
typename _Cmp2>
655 merge(multimap<_Key, _Tp, _Cmp2, _Alloc>& __source)
657 using _Merge_helper = _Rb_tree_merge_helper<map, _Cmp2>;
658 _M_t._M_merge_unique(_Merge_helper::_S_get_tree(__source));
661 template<
typename _Cmp2>
663 merge(multimap<_Key, _Tp, _Cmp2, _Alloc>&& __source)
667 #if __cplusplus > 201402L
668 #define __cpp_lib_map_try_emplace 201411
689 template <
typename... _Args>
691 try_emplace(
const key_type& __k, _Args&&... __args)
699 std::forward<_Args>(__args)...));
706 template <
typename... _Args>
708 try_emplace(key_type&& __k, _Args&&... __args)
716 std::forward<_Args>(__args)...));
749 template <
typename... _Args>
751 try_emplace(const_iterator __hint,
const key_type& __k,
755 auto __true_hint = _M_t._M_get_insert_hint_unique_pos(__hint, __k);
756 if (__true_hint.second)
761 std::forward<_Args>(__args)...));
763 __i = iterator(__true_hint.first);
768 template <
typename... _Args>
770 try_emplace(const_iterator __hint, key_type&& __k, _Args&&... __args)
773 auto __true_hint = _M_t._M_get_insert_hint_unique_pos(__hint, __k);
774 if (__true_hint.second)
779 std::forward<_Args>(__args)...));
781 __i = iterator(__true_hint.first);
804 {
return _M_t._M_insert_unique(__x); }
806 #if __cplusplus >= 201103L
811 {
return _M_t._M_insert_unique(
std::move(__x)); }
813 template<
typename _Pair>
814 __enable_if_t<is_constructible<value_type, _Pair>::value,
817 {
return _M_t._M_emplace_unique(std::forward<_Pair>(__x)); }
821 #if __cplusplus >= 201103L
831 {
insert(__list.begin(), __list.end()); }
859 #if __cplusplus >= 201103L
864 {
return _M_t._M_insert_unique_(__position, __x); }
866 #if __cplusplus >= 201103L
871 {
return _M_t._M_insert_unique_(__position,
std::move(__x)); }
873 template<
typename _Pair>
874 __enable_if_t<is_constructible<value_type, _Pair>::value,
iterator>
875 insert(const_iterator __position, _Pair&& __x)
877 return _M_t._M_emplace_hint_unique(__position,
878 std::forward<_Pair>(__x));
891 template<
typename _InputIterator>
893 insert(_InputIterator __first, _InputIterator __last)
894 { _M_t._M_insert_range_unique(__first, __last); }
896 #if __cplusplus > 201402L
897 #define __cpp_lib_map_insertion 201411
917 template <
typename _Obj>
919 insert_or_assign(
const key_type& __k, _Obj&& __obj)
927 std::forward<_Obj>(__obj)));
930 (*__i).second = std::forward<_Obj>(__obj);
935 template <
typename _Obj>
937 insert_or_assign(key_type&& __k, _Obj&& __obj)
945 std::forward<_Obj>(__obj)));
948 (*__i).second = std::forward<_Obj>(__obj);
972 template <
typename _Obj>
974 insert_or_assign(const_iterator __hint,
975 const key_type& __k, _Obj&& __obj)
978 auto __true_hint = _M_t._M_get_insert_hint_unique_pos(__hint, __k);
979 if (__true_hint.second)
985 std::forward<_Obj>(__obj)));
987 __i = iterator(__true_hint.first);
988 (*__i).second = std::forward<_Obj>(__obj);
993 template <
typename _Obj>
995 insert_or_assign(const_iterator __hint, key_type&& __k, _Obj&& __obj)
998 auto __true_hint = _M_t._M_get_insert_hint_unique_pos(__hint, __k);
999 if (__true_hint.second)
1005 std::forward<_Obj>(__obj)));
1007 __i = iterator(__true_hint.first);
1008 (*__i).second = std::forward<_Obj>(__obj);
1013 #if __cplusplus >= 201103L
1033 {
return _M_t.erase(__position); }
1036 _GLIBCXX_ABI_TAG_CXX11
1039 {
return _M_t.erase(__position); }
1054 { _M_t.erase(__position); }
1070 {
return _M_t.erase(__x); }
1072 #if __cplusplus >= 201103L
1089 erase(const_iterator __first, const_iterator __last)
1090 {
return _M_t.erase(__first, __last); }
1106 { _M_t.erase(__first, __last); }
1124 _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value)
1125 { _M_t.swap(__x._M_t); }
1144 {
return _M_t.key_comp(); }
1152 {
return value_compare(_M_t.key_comp()); }
1171 {
return _M_t.find(__x); }
1173 #if __cplusplus > 201103L
1174 template<
typename _Kt>
1176 find(
const _Kt& __x) -> decltype(_M_t._M_find_tr(__x))
1177 {
return _M_t._M_find_tr(__x); }
1196 {
return _M_t.find(__x); }
1198 #if __cplusplus > 201103L
1199 template<
typename _Kt>
1201 find(
const _Kt& __x)
const -> decltype(_M_t._M_find_tr(__x))
1202 {
return _M_t._M_find_tr(__x); }
1217 {
return _M_t.find(__x) == _M_t.end() ? 0 : 1; }
1219 #if __cplusplus > 201103L
1220 template<
typename _Kt>
1222 count(
const _Kt& __x)
const -> decltype(_M_t._M_count_tr(__x))
1223 {
return _M_t._M_count_tr(__x); }
1227 #if __cplusplus > 201703L
1235 contains(
const key_type& __x)
const
1236 {
return _M_t.find(__x) != _M_t.end(); }
1238 template<
typename _Kt>
1240 contains(
const _Kt& __x)
const
1241 -> decltype(_M_t._M_find_tr(__x),
void(),
true)
1242 {
return _M_t._M_find_tr(__x) != _M_t.end(); }
1260 {
return _M_t.lower_bound(__x); }
1262 #if __cplusplus > 201103L
1263 template<
typename _Kt>
1266 -> decltype(iterator(_M_t._M_lower_bound_tr(__x)))
1267 {
return iterator(_M_t._M_lower_bound_tr(__x)); }
1285 {
return _M_t.lower_bound(__x); }
1287 #if __cplusplus > 201103L
1288 template<
typename _Kt>
1291 -> decltype(const_iterator(_M_t._M_lower_bound_tr(__x)))
1292 {
return const_iterator(_M_t._M_lower_bound_tr(__x)); }
1305 {
return _M_t.upper_bound(__x); }
1307 #if __cplusplus > 201103L
1308 template<
typename _Kt>
1311 -> decltype(iterator(_M_t._M_upper_bound_tr(__x)))
1312 {
return iterator(_M_t._M_upper_bound_tr(__x)); }
1325 {
return _M_t.upper_bound(__x); }
1327 #if __cplusplus > 201103L
1328 template<
typename _Kt>
1331 -> decltype(const_iterator(_M_t._M_upper_bound_tr(__x)))
1332 {
return const_iterator(_M_t._M_upper_bound_tr(__x)); }
1354 {
return _M_t.equal_range(__x); }
1356 #if __cplusplus > 201103L
1357 template<
typename _Kt>
1383 {
return _M_t.equal_range(__x); }
1385 #if __cplusplus > 201103L
1386 template<
typename _Kt>
1390 _M_t._M_equal_range_tr(__x)))
1393 _M_t._M_equal_range_tr(__x));
1398 template<
typename _K1,
typename _T1,
typename _C1,
typename _A1>
1403 template<
typename _K1,
typename _T1,
typename _C1,
typename _A1>
1410 #if __cpp_deduction_guides >= 201606
1412 template<
typename _InputIterator,
1413 typename _Compare = less<__iter_key_t<_InputIterator>>,
1414 typename _Allocator = allocator<__iter_to_alloc_t<_InputIterator>>,
1415 typename = _RequireInputIter<_InputIterator>,
1416 typename = _RequireNotAllocator<_Compare>,
1417 typename = _RequireAllocator<_Allocator>>
1418 map(_InputIterator, _InputIterator,
1419 _Compare = _Compare(), _Allocator = _Allocator())
1420 -> map<__iter_key_t<_InputIterator>, __iter_val_t<_InputIterator>,
1421 _Compare, _Allocator>;
1423 template<
typename _Key,
typename _Tp,
typename _Compare = less<_Key>,
1424 typename _Allocator = allocator<pair<const _Key, _Tp>>,
1425 typename = _RequireNotAllocator<_Compare>,
1426 typename = _RequireAllocator<_Allocator>>
1427 map(initializer_list<pair<_Key, _Tp>>,
1428 _Compare = _Compare(), _Allocator = _Allocator())
1429 -> map<_Key, _Tp, _Compare, _Allocator>;
1431 template <
typename _InputIterator,
typename _Allocator,
1432 typename = _RequireInputIter<_InputIterator>,
1433 typename = _RequireAllocator<_Allocator>>
1434 map(_InputIterator, _InputIterator, _Allocator)
1435 -> map<__iter_key_t<_InputIterator>, __iter_val_t<_InputIterator>,
1436 less<__iter_key_t<_InputIterator>>, _Allocator>;
1438 template<
typename _Key,
typename _Tp,
typename _Allocator,
1439 typename = _RequireAllocator<_Allocator>>
1440 map(initializer_list<pair<_Key, _Tp>>, _Allocator)
1441 -> map<_Key, _Tp, less<_Key>, _Allocator>;
1455 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1459 {
return __x._M_t == __y._M_t; }
1472 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1476 {
return __x._M_t < __y._M_t; }
1479 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1483 {
return !(__x == __y); }
1486 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1490 {
return __y < __x; }
1493 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1497 {
return !(__y < __x); }
1500 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1504 {
return !(__x < __y); }
1507 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1511 _GLIBCXX_NOEXCEPT_IF(noexcept(__x.swap(__y)))
1514 _GLIBCXX_END_NAMESPACE_CONTAINER
1516 #if __cplusplus > 201402L
1518 template<
typename _Key,
typename _Val,
typename _Cmp1,
typename _Alloc,
1521 _Rb_tree_merge_helper<_GLIBCXX_STD_C::map<_Key, _Val, _Cmp1, _Alloc>,
1525 friend class _GLIBCXX_STD_C::map<_Key, _Val, _Cmp1, _Alloc>;
1528 _S_get_tree(_GLIBCXX_STD_C::map<_Key, _Val, _Cmp2, _Alloc>& __map)
1529 {
return __map._M_t; }
1532 _S_get_tree(_GLIBCXX_STD_C::multimap<_Key, _Val, _Cmp2, _Alloc>& __map)
1533 {
return __map._M_t; }
1537 _GLIBCXX_END_NAMESPACE_VERSION