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>
100 template <
typename _Key,
typename _Tp,
typename _Compare = std::less<_Key>,
101 typename _Alloc = std::allocator<std::pair<const _Key, _Tp> > >
105 typedef _Key key_type;
106 typedef _Tp mapped_type;
108 typedef _Compare key_compare;
109 typedef _Alloc allocator_type;
112 #ifdef _GLIBCXX_CONCEPT_CHECKS
114 typedef typename _Alloc::value_type _Alloc_value_type;
115 # if __cplusplus < 201103L
116 __glibcxx_class_requires(_Tp, _SGIAssignableConcept)
118 __glibcxx_class_requires4(_Compare,
bool, _Key, _Key,
119 _BinaryFunctionConcept)
120 __glibcxx_class_requires2(
value_type, _Alloc_value_type, _SameTypeConcept)
123 #if __cplusplus >= 201103L
124 #if __cplusplus > 201703L || defined __STRICT_ANSI__
126 "std::map must have the same value_type as its allocator");
131 #pragma GCC diagnostic push
132 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
136 friend class map<_Key, _Tp, _Compare, _Alloc>;
140 value_compare(_Compare __c)
147 #pragma GCC diagnostic pop
152 rebind<value_type>::other _Pair_alloc_type;
154 typedef _Rb_tree<key_type, value_type, _Select1st<value_type>,
155 key_compare, _Pair_alloc_type> _Rep_type;
162 #if __cplusplus >= 201703L
163 template<
typename _Up,
typename _Vp = remove_reference_t<_Up>>
164 static constexpr
bool __usable_key
165 = __or_v<is_same<const _Vp, const _Key>,
172 typedef typename _Alloc_traits::pointer pointer;
173 typedef typename _Alloc_traits::const_pointer const_pointer;
174 typedef typename _Alloc_traits::reference reference;
175 typedef typename _Alloc_traits::const_reference const_reference;
176 typedef typename _Rep_type::iterator iterator;
177 typedef typename _Rep_type::const_iterator const_iterator;
178 typedef typename _Rep_type::size_type size_type;
179 typedef typename _Rep_type::difference_type difference_type;
183 #ifdef __glibcxx_node_extract // >= C++17
194 #if __cplusplus < 201103L
206 map(
const _Compare& __comp,
207 const allocator_type& __a = allocator_type())
208 : _M_t(__comp, _Pair_alloc_type(__a)) { }
215 #if __cplusplus < 201103L
219 map(
const map&) =
default;
241 const _Compare& __comp = _Compare(),
242 const allocator_type& __a = allocator_type())
243 : _M_t(__comp, _Pair_alloc_type(__a))
244 { _M_t._M_insert_range_unique(__l.begin(), __l.end()); }
248 map(
const allocator_type& __a)
249 : _M_t(_Pair_alloc_type(__a)) { }
252 map(
const map& __m,
const __type_identity_t<allocator_type>& __a)
253 : _M_t(__m._M_t, _Pair_alloc_type(__a)) { }
256 map(
map&& __m,
const __type_identity_t<allocator_type>& __a)
258 && _Alloc_traits::_S_always_equal())
259 : _M_t(
std::
move(__m._M_t), _Pair_alloc_type(__a)) { }
263 : _M_t(_Pair_alloc_type(__a))
264 { _M_t._M_insert_range_unique(__l.begin(), __l.end()); }
267 template<
typename _InputIterator>
268 map(_InputIterator __first, _InputIterator __last,
269 const allocator_type& __a)
270 : _M_t(_Pair_alloc_type(__a))
271 { _M_t._M_insert_range_unique(__first, __last); }
284 template<
typename _InputIterator>
285 map(_InputIterator __first, _InputIterator __last)
287 { _M_t._M_insert_range_unique(__first, __last); }
301 template<
typename _InputIterator>
302 map(_InputIterator __first, _InputIterator __last,
303 const _Compare& __comp,
304 const allocator_type& __a = allocator_type())
305 : _M_t(__comp, _Pair_alloc_type(__a))
306 { _M_t._M_insert_range_unique(__first, __last); }
308 #if __cplusplus >= 201103L
322 #if __cplusplus < 201103L
351 _M_t._M_assign_unique(__l.begin(), __l.end());
359 {
return allocator_type(_M_t.get_allocator()); }
369 {
return _M_t.begin(); }
378 {
return _M_t.begin(); }
387 {
return _M_t.end(); }
395 end() const _GLIBCXX_NOEXCEPT
396 {
return _M_t.end(); }
405 {
return _M_t.rbegin(); }
412 const_reverse_iterator
414 {
return _M_t.rbegin(); }
423 {
return _M_t.rend(); }
430 const_reverse_iterator
432 {
return _M_t.rend(); }
434 #if __cplusplus >= 201103L
442 {
return _M_t.begin(); }
451 {
return _M_t.end(); }
458 const_reverse_iterator
460 {
return _M_t.rbegin(); }
467 const_reverse_iterator
469 {
return _M_t.rend(); }
476 _GLIBCXX_NODISCARD
bool
478 {
return _M_t.empty(); }
483 {
return _M_t.size(); }
488 {
return _M_t.max_size(); }
507 __glibcxx_function_requires(_DefaultConstructibleConcept<mapped_type>)
512 #if __cplusplus >= 201103L
519 return (*__i).second;
522 #if __cplusplus >= 201103L
527 __glibcxx_function_requires(_DefaultConstructibleConcept<mapped_type>)
535 return (*__i).second;
549 at(
const key_type& __k)
553 __throw_out_of_range(__N(
"map::at"));
554 return (*__i).second;
558 at(
const key_type& __k)
const
562 __throw_out_of_range(__N(
"map::at"));
563 return (*__i).second;
567 #if __cplusplus >= 201103L
586 template<
typename... _Args>
590 #if __cplusplus >= 201703L
591 if constexpr (
sizeof...(_Args) == 2)
594 auto&& [__a, __v] =
pair<_Args&...>(__args...);
595 if constexpr (__usable_key<decltype(__a)>)
597 const key_type& __k = __a;
601 __i =
emplace_hint(__i, std::forward<_Args>(__args)...);
608 return _M_t._M_emplace_unique(std::forward<_Args>(__args)...);
636 template<
typename... _Args>
640 return _M_t._M_emplace_hint_unique(__pos,
641 std::forward<_Args>(__args)...);
645 #ifdef __glibcxx_node_extract // >= C++17
650 __glibcxx_assert(__pos !=
end());
651 return _M_t.extract(__pos);
657 {
return _M_t.extract(__x); }
662 {
return _M_t._M_reinsert_node_unique(
std::move(__nh)); }
666 insert(const_iterator __hint, node_type&& __nh)
667 {
return _M_t._M_reinsert_node_hint_unique(__hint,
std::move(__nh)); }
669 template<
typename,
typename>
670 friend struct std::_Rb_tree_merge_helper;
672 template<
typename _Cmp2>
676 using _Merge_helper = _Rb_tree_merge_helper<map, _Cmp2>;
677 _M_t._M_merge_unique(_Merge_helper::_S_get_tree(__source));
680 template<
typename _Cmp2>
682 merge(map<_Key, _Tp, _Cmp2, _Alloc>&& __source)
685 template<
typename _Cmp2>
687 merge(multimap<_Key, _Tp, _Cmp2, _Alloc>& __source)
689 using _Merge_helper = _Rb_tree_merge_helper<map, _Cmp2>;
690 _M_t._M_merge_unique(_Merge_helper::_S_get_tree(__source));
693 template<
typename _Cmp2>
695 merge(multimap<_Key, _Tp, _Cmp2, _Alloc>&& __source)
699 #ifdef __glibcxx_map_try_emplace // C++ >= 17 && HOSTED
720 template <
typename... _Args>
730 std::forward<_Args>(__args)...));
737 template <
typename... _Args>
747 std::forward<_Args>(__args)...));
780 template <
typename... _Args>
786 auto __true_hint = _M_t._M_get_insert_hint_unique_pos(__hint, __k);
787 if (__true_hint.second)
792 std::forward<_Args>(__args)...));
794 __i = iterator(__true_hint.first);
799 template <
typename... _Args>
801 try_emplace(const_iterator __hint, key_type&& __k, _Args&&... __args)
804 auto __true_hint = _M_t._M_get_insert_hint_unique_pos(__hint, __k);
805 if (__true_hint.second)
810 std::forward<_Args>(__args)...));
835 {
return _M_t._M_insert_unique(__x); }
837 #if __cplusplus >= 201103L
842 {
return _M_t._M_insert_unique(
std::move(__x)); }
844 template<
typename _Pair>
845 __enable_if_t<is_constructible<value_type, _Pair>::value,
849 #if __cplusplus >= 201703L
851 if constexpr (__is_pair<remove_const_t<_P2>>)
853 if constexpr (__usable_key<typename _P2::first_type>)
855 const key_type& __k = __x.first;
865 return _M_t._M_emplace_unique(std::forward<_Pair>(__x));
870 #if __cplusplus >= 201103L
880 {
insert(__list.begin(), __list.end()); }
908 #if __cplusplus >= 201103L
913 {
return _M_t._M_insert_unique_(__position, __x); }
915 #if __cplusplus >= 201103L
920 {
return _M_t._M_insert_unique_(__position,
std::move(__x)); }
922 template<
typename _Pair>
923 __enable_if_t<is_constructible<value_type, _Pair>::value,
iterator>
924 insert(const_iterator __position, _Pair&& __x)
926 return _M_t._M_emplace_hint_unique(__position,
927 std::forward<_Pair>(__x));
940 template<
typename _InputIterator>
942 insert(_InputIterator __first, _InputIterator __last)
943 { _M_t._M_insert_range_unique(__first, __last); }
945 #if __cplusplus > 201402L
965 template <
typename _Obj>
975 std::forward<_Obj>(__obj)));
978 (*__i).second = std::forward<_Obj>(__obj);
983 template <
typename _Obj>
993 std::forward<_Obj>(__obj)));
996 (*__i).second = std::forward<_Obj>(__obj);
1020 template <
typename _Obj>
1023 const key_type& __k, _Obj&& __obj)
1026 auto __true_hint = _M_t._M_get_insert_hint_unique_pos(__hint, __k);
1027 if (__true_hint.second)
1033 std::forward<_Obj>(__obj)));
1035 __i = iterator(__true_hint.first);
1036 (*__i).second = std::forward<_Obj>(__obj);
1041 template <
typename _Obj>
1046 auto __true_hint = _M_t._M_get_insert_hint_unique_pos(__hint, __k);
1047 if (__true_hint.second)
1053 std::forward<_Obj>(__obj)));
1055 __i = iterator(__true_hint.first);
1056 (*__i).second = std::forward<_Obj>(__obj);
1061 #if __cplusplus >= 201103L
1081 {
return _M_t.erase(__position); }
1084 _GLIBCXX_ABI_TAG_CXX11
1087 {
return _M_t.erase(__position); }
1102 { _M_t.erase(__position); }
1118 {
return _M_t.erase(__x); }
1120 #if __cplusplus >= 201103L
1137 erase(const_iterator __first, const_iterator __last)
1138 {
return _M_t.erase(__first, __last); }
1154 { _M_t.erase(__first, __last); }
1172 _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value)
1173 { _M_t.swap(__x._M_t); }
1192 {
return _M_t.key_comp(); }
1200 {
return value_compare(_M_t.key_comp()); }
1219 {
return _M_t.find(__x); }
1221 #if __cplusplus > 201103L
1222 template<
typename _Kt>
1224 find(
const _Kt& __x) -> decltype(_M_t._M_find_tr(__x))
1225 {
return _M_t._M_find_tr(__x); }
1244 {
return _M_t.find(__x); }
1246 #if __cplusplus > 201103L
1247 template<
typename _Kt>
1249 find(
const _Kt& __x)
const -> decltype(_M_t._M_find_tr(__x))
1250 {
return _M_t._M_find_tr(__x); }
1265 {
return _M_t.find(__x) == _M_t.end() ? 0 : 1; }
1267 #if __cplusplus > 201103L
1268 template<
typename _Kt>
1270 count(
const _Kt& __x)
const -> decltype(_M_t._M_count_tr(__x))
1271 {
return _M_t._M_count_tr(__x); }
1275 #if __cplusplus > 201703L
1284 {
return _M_t.find(__x) != _M_t.end(); }
1286 template<
typename _Kt>
1289 -> decltype(_M_t._M_find_tr(__x),
void(),
true)
1290 {
return _M_t._M_find_tr(__x) != _M_t.end(); }
1308 {
return _M_t.lower_bound(__x); }
1310 #if __cplusplus > 201103L
1311 template<
typename _Kt>
1314 -> decltype(iterator(_M_t._M_lower_bound_tr(__x)))
1315 {
return iterator(_M_t._M_lower_bound_tr(__x)); }
1333 {
return _M_t.lower_bound(__x); }
1335 #if __cplusplus > 201103L
1336 template<
typename _Kt>
1339 -> decltype(const_iterator(_M_t._M_lower_bound_tr(__x)))
1340 {
return const_iterator(_M_t._M_lower_bound_tr(__x)); }
1353 {
return _M_t.upper_bound(__x); }
1355 #if __cplusplus > 201103L
1356 template<
typename _Kt>
1359 -> decltype(iterator(_M_t._M_upper_bound_tr(__x)))
1360 {
return iterator(_M_t._M_upper_bound_tr(__x)); }
1373 {
return _M_t.upper_bound(__x); }
1375 #if __cplusplus > 201103L
1376 template<
typename _Kt>
1379 -> decltype(const_iterator(_M_t._M_upper_bound_tr(__x)))
1380 {
return const_iterator(_M_t._M_upper_bound_tr(__x)); }
1402 {
return _M_t.equal_range(__x); }
1404 #if __cplusplus > 201103L
1405 template<
typename _Kt>
1431 {
return _M_t.equal_range(__x); }
1433 #if __cplusplus > 201103L
1434 template<
typename _Kt>
1438 _M_t._M_equal_range_tr(__x)))
1441 _M_t._M_equal_range_tr(__x));
1446 template<
typename _K1,
typename _T1,
typename _C1,
typename _A1>
1451 #if __cpp_lib_three_way_comparison
1452 template<
typename _K1,
typename _T1,
typename _C1,
typename _A1>
1453 friend __detail::__synth3way_t<pair<const _K1, _T1>>
1457 template<
typename _K1,
typename _T1,
typename _C1,
typename _A1>
1465 #if __cpp_deduction_guides >= 201606
1467 template<
typename _InputIterator,
1468 typename _Compare = less<__iter_key_t<_InputIterator>>,
1469 typename _Allocator = allocator<__iter_to_alloc_t<_InputIterator>>,
1470 typename = _RequireInputIter<_InputIterator>,
1471 typename = _RequireNotAllocator<_Compare>,
1472 typename = _RequireAllocator<_Allocator>>
1473 map(_InputIterator, _InputIterator,
1474 _Compare = _Compare(), _Allocator = _Allocator())
1475 -> map<__iter_key_t<_InputIterator>, __iter_val_t<_InputIterator>,
1476 _Compare, _Allocator>;
1478 template<
typename _Key,
typename _Tp,
typename _Compare = less<_Key>,
1479 typename _Allocator = allocator<pair<const _Key, _Tp>>,
1480 typename = _RequireNotAllocator<_Compare>,
1481 typename = _RequireAllocator<_Allocator>>
1482 map(initializer_list<pair<_Key, _Tp>>,
1483 _Compare = _Compare(), _Allocator = _Allocator())
1484 -> map<_Key, _Tp, _Compare, _Allocator>;
1486 template <
typename _InputIterator,
typename _Allocator,
1487 typename = _RequireInputIter<_InputIterator>,
1488 typename = _RequireAllocator<_Allocator>>
1489 map(_InputIterator, _InputIterator, _Allocator)
1490 -> map<__iter_key_t<_InputIterator>, __iter_val_t<_InputIterator>,
1491 less<__iter_key_t<_InputIterator>>, _Allocator>;
1493 template<
typename _Key,
typename _Tp,
typename _Allocator,
1494 typename = _RequireAllocator<_Allocator>>
1495 map(initializer_list<pair<_Key, _Tp>>, _Allocator)
1496 -> map<_Key, _Tp, less<_Key>, _Allocator>;
1498 #endif // deduction guides
1510 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1514 {
return __x._M_t == __y._M_t; }
1516 #if __cpp_lib_three_way_comparison
1531 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1532 inline __detail::__synth3way_t<pair<const _Key, _Tp>>
1533 operator<=>(
const map<_Key, _Tp, _Compare, _Alloc>& __x,
1534 const map<_Key, _Tp, _Compare, _Alloc>& __y)
1535 {
return __x._M_t <=> __y._M_t; }
1548 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1552 {
return __x._M_t < __y._M_t; }
1555 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1559 {
return !(__x == __y); }
1562 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1566 {
return __y < __x; }
1569 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1573 {
return !(__y < __x); }
1576 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1580 {
return !(__x < __y); }
1581 #endif // three-way comparison
1584 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1588 _GLIBCXX_NOEXCEPT_IF(noexcept(__x.
swap(__y)))
1591 _GLIBCXX_END_NAMESPACE_CONTAINER
1593 #if __cplusplus > 201402L
1595 template<
typename _Key,
typename _Val,
typename _Cmp1,
typename _Alloc,
1598 _Rb_tree_merge_helper<_GLIBCXX_STD_C::map<_Key, _Val, _Cmp1, _Alloc>,
1602 friend class _GLIBCXX_STD_C::map<_Key, _Val, _Cmp1, _Alloc>;
1605 _S_get_tree(_GLIBCXX_STD_C::map<_Key, _Val, _Cmp2, _Alloc>& __map)
1606 {
return __map._M_t; }
1609 _S_get_tree(_GLIBCXX_STD_C::multimap<_Key, _Val, _Cmp2, _Alloc>& __map)
1610 {
return __map._M_t; }
1614 _GLIBCXX_END_NAMESPACE_VERSION