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 #if __cplusplus > 201402L
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 #if __cplusplus > 201402L
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 #if __cplusplus > 201402L
700 #define __cpp_lib_map_try_emplace 201411L
721 template <
typename... _Args>
731 std::forward<_Args>(__args)...));
738 template <
typename... _Args>
748 std::forward<_Args>(__args)...));
781 template <
typename... _Args>
787 auto __true_hint = _M_t._M_get_insert_hint_unique_pos(__hint, __k);
788 if (__true_hint.second)
793 std::forward<_Args>(__args)...));
795 __i = iterator(__true_hint.first);
800 template <
typename... _Args>
802 try_emplace(const_iterator __hint, key_type&& __k, _Args&&... __args)
805 auto __true_hint = _M_t._M_get_insert_hint_unique_pos(__hint, __k);
806 if (__true_hint.second)
811 std::forward<_Args>(__args)...));
836 {
return _M_t._M_insert_unique(__x); }
838 #if __cplusplus >= 201103L
843 {
return _M_t._M_insert_unique(
std::move(__x)); }
845 template<
typename _Pair>
846 __enable_if_t<is_constructible<value_type, _Pair>::value,
850 #if __cplusplus >= 201703L
854 if constexpr (__usable_key<typename _P2::first_type>)
856 const key_type& __k = __x.first;
866 return _M_t._M_emplace_unique(std::forward<_Pair>(__x));
871 #if __cplusplus >= 201103L
881 {
insert(__list.begin(), __list.end()); }
909 #if __cplusplus >= 201103L
914 {
return _M_t._M_insert_unique_(__position, __x); }
916 #if __cplusplus >= 201103L
921 {
return _M_t._M_insert_unique_(__position,
std::move(__x)); }
923 template<
typename _Pair>
924 __enable_if_t<is_constructible<value_type, _Pair>::value,
iterator>
925 insert(const_iterator __position, _Pair&& __x)
927 return _M_t._M_emplace_hint_unique(__position,
928 std::forward<_Pair>(__x));
941 template<
typename _InputIterator>
943 insert(_InputIterator __first, _InputIterator __last)
944 { _M_t._M_insert_range_unique(__first, __last); }
946 #if __cplusplus > 201402L
966 template <
typename _Obj>
976 std::forward<_Obj>(__obj)));
979 (*__i).second = std::forward<_Obj>(__obj);
984 template <
typename _Obj>
994 std::forward<_Obj>(__obj)));
997 (*__i).second = std::forward<_Obj>(__obj);
1021 template <
typename _Obj>
1024 const key_type& __k, _Obj&& __obj)
1027 auto __true_hint = _M_t._M_get_insert_hint_unique_pos(__hint, __k);
1028 if (__true_hint.second)
1034 std::forward<_Obj>(__obj)));
1036 __i = iterator(__true_hint.first);
1037 (*__i).second = std::forward<_Obj>(__obj);
1042 template <
typename _Obj>
1047 auto __true_hint = _M_t._M_get_insert_hint_unique_pos(__hint, __k);
1048 if (__true_hint.second)
1054 std::forward<_Obj>(__obj)));
1056 __i = iterator(__true_hint.first);
1057 (*__i).second = std::forward<_Obj>(__obj);
1062 #if __cplusplus >= 201103L
1082 {
return _M_t.erase(__position); }
1085 _GLIBCXX_ABI_TAG_CXX11
1088 {
return _M_t.erase(__position); }
1103 { _M_t.erase(__position); }
1119 {
return _M_t.erase(__x); }
1121 #if __cplusplus >= 201103L
1138 erase(const_iterator __first, const_iterator __last)
1139 {
return _M_t.erase(__first, __last); }
1155 { _M_t.erase(__first, __last); }
1173 _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Compare>::value)
1174 { _M_t.swap(__x._M_t); }
1193 {
return _M_t.key_comp(); }
1201 {
return value_compare(_M_t.key_comp()); }
1220 {
return _M_t.find(__x); }
1222 #if __cplusplus > 201103L
1223 template<
typename _Kt>
1225 find(
const _Kt& __x) -> decltype(_M_t._M_find_tr(__x))
1226 {
return _M_t._M_find_tr(__x); }
1245 {
return _M_t.find(__x); }
1247 #if __cplusplus > 201103L
1248 template<
typename _Kt>
1250 find(
const _Kt& __x)
const -> decltype(_M_t._M_find_tr(__x))
1251 {
return _M_t._M_find_tr(__x); }
1266 {
return _M_t.find(__x) == _M_t.end() ? 0 : 1; }
1268 #if __cplusplus > 201103L
1269 template<
typename _Kt>
1271 count(
const _Kt& __x)
const -> decltype(_M_t._M_count_tr(__x))
1272 {
return _M_t._M_count_tr(__x); }
1276 #if __cplusplus > 201703L
1285 {
return _M_t.find(__x) != _M_t.end(); }
1287 template<
typename _Kt>
1290 -> decltype(_M_t._M_find_tr(__x),
void(),
true)
1291 {
return _M_t._M_find_tr(__x) != _M_t.end(); }
1309 {
return _M_t.lower_bound(__x); }
1311 #if __cplusplus > 201103L
1312 template<
typename _Kt>
1315 -> decltype(iterator(_M_t._M_lower_bound_tr(__x)))
1316 {
return iterator(_M_t._M_lower_bound_tr(__x)); }
1334 {
return _M_t.lower_bound(__x); }
1336 #if __cplusplus > 201103L
1337 template<
typename _Kt>
1340 -> decltype(const_iterator(_M_t._M_lower_bound_tr(__x)))
1341 {
return const_iterator(_M_t._M_lower_bound_tr(__x)); }
1354 {
return _M_t.upper_bound(__x); }
1356 #if __cplusplus > 201103L
1357 template<
typename _Kt>
1360 -> decltype(iterator(_M_t._M_upper_bound_tr(__x)))
1361 {
return iterator(_M_t._M_upper_bound_tr(__x)); }
1374 {
return _M_t.upper_bound(__x); }
1376 #if __cplusplus > 201103L
1377 template<
typename _Kt>
1380 -> decltype(const_iterator(_M_t._M_upper_bound_tr(__x)))
1381 {
return const_iterator(_M_t._M_upper_bound_tr(__x)); }
1403 {
return _M_t.equal_range(__x); }
1405 #if __cplusplus > 201103L
1406 template<
typename _Kt>
1432 {
return _M_t.equal_range(__x); }
1434 #if __cplusplus > 201103L
1435 template<
typename _Kt>
1439 _M_t._M_equal_range_tr(__x)))
1442 _M_t._M_equal_range_tr(__x));
1447 template<
typename _K1,
typename _T1,
typename _C1,
typename _A1>
1452 #if __cpp_lib_three_way_comparison
1453 template<
typename _K1,
typename _T1,
typename _C1,
typename _A1>
1454 friend __detail::__synth3way_t<pair<const _K1, _T1>>
1458 template<
typename _K1,
typename _T1,
typename _C1,
typename _A1>
1466 #if __cpp_deduction_guides >= 201606
1468 template<
typename _InputIterator,
1469 typename _Compare = less<__iter_key_t<_InputIterator>>,
1470 typename _Allocator = allocator<__iter_to_alloc_t<_InputIterator>>,
1471 typename = _RequireInputIter<_InputIterator>,
1472 typename = _RequireNotAllocator<_Compare>,
1473 typename = _RequireAllocator<_Allocator>>
1474 map(_InputIterator, _InputIterator,
1475 _Compare = _Compare(), _Allocator = _Allocator())
1476 -> map<__iter_key_t<_InputIterator>, __iter_val_t<_InputIterator>,
1477 _Compare, _Allocator>;
1479 template<
typename _Key,
typename _Tp,
typename _Compare = less<_Key>,
1480 typename _Allocator = allocator<pair<const _Key, _Tp>>,
1481 typename = _RequireNotAllocator<_Compare>,
1482 typename = _RequireAllocator<_Allocator>>
1483 map(initializer_list<pair<_Key, _Tp>>,
1484 _Compare = _Compare(), _Allocator = _Allocator())
1485 -> map<_Key, _Tp, _Compare, _Allocator>;
1487 template <
typename _InputIterator,
typename _Allocator,
1488 typename = _RequireInputIter<_InputIterator>,
1489 typename = _RequireAllocator<_Allocator>>
1490 map(_InputIterator, _InputIterator, _Allocator)
1491 -> map<__iter_key_t<_InputIterator>, __iter_val_t<_InputIterator>,
1492 less<__iter_key_t<_InputIterator>>, _Allocator>;
1494 template<
typename _Key,
typename _Tp,
typename _Allocator,
1495 typename = _RequireAllocator<_Allocator>>
1496 map(initializer_list<pair<_Key, _Tp>>, _Allocator)
1497 -> map<_Key, _Tp, less<_Key>, _Allocator>;
1499 #endif // deduction guides
1511 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1515 {
return __x._M_t == __y._M_t; }
1517 #if __cpp_lib_three_way_comparison
1532 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1533 inline __detail::__synth3way_t<pair<const _Key, _Tp>>
1534 operator<=>(
const map<_Key, _Tp, _Compare, _Alloc>& __x,
1535 const map<_Key, _Tp, _Compare, _Alloc>& __y)
1536 {
return __x._M_t <=> __y._M_t; }
1549 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1553 {
return __x._M_t < __y._M_t; }
1556 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1560 {
return !(__x == __y); }
1563 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1567 {
return __y < __x; }
1570 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1574 {
return !(__y < __x); }
1577 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1581 {
return !(__x < __y); }
1582 #endif // three-way comparison
1585 template<
typename _Key,
typename _Tp,
typename _Compare,
typename _Alloc>
1589 _GLIBCXX_NOEXCEPT_IF(noexcept(__x.
swap(__y)))
1592 _GLIBCXX_END_NAMESPACE_CONTAINER
1594 #if __cplusplus > 201402L
1596 template<
typename _Key,
typename _Val,
typename _Cmp1,
typename _Alloc,
1599 _Rb_tree_merge_helper<_GLIBCXX_STD_C::map<_Key, _Val, _Cmp1, _Alloc>,
1603 friend class _GLIBCXX_STD_C::map<_Key, _Val, _Cmp1, _Alloc>;
1606 _S_get_tree(_GLIBCXX_STD_C::map<_Key, _Val, _Cmp2, _Alloc>& __map)
1607 {
return __map._M_t; }
1610 _S_get_tree(_GLIBCXX_STD_C::multimap<_Key, _Val, _Cmp2, _Alloc>& __map)
1611 {
return __map._M_t; }
1615 _GLIBCXX_END_NAMESPACE_VERSION