File indexing completed on 2026-05-03 08:13:48
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef _LIBCPP___FLAT_MAP_UTILS_H
0011 #define _LIBCPP___FLAT_MAP_UTILS_H
0012
0013 #include <__config>
0014 #include <__type_traits/container_traits.h>
0015 #include <__utility/exception_guard.h>
0016 #include <__utility/forward.h>
0017 #include <__utility/move.h>
0018
0019 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0020 # pragma GCC system_header
0021 #endif
0022
0023 _LIBCPP_PUSH_MACROS
0024 #include <__undef_macros>
0025
0026 #if _LIBCPP_STD_VER >= 23
0027
0028 _LIBCPP_BEGIN_NAMESPACE_STD
0029
0030
0031 struct __flat_map_utils {
0032
0033
0034
0035
0036
0037 template <class _Map, class _IterK, class _IterM, class _KeyArg, class... _MArgs>
0038 _LIBCPP_HIDE_FROM_ABI static typename _Map::iterator __emplace_exact_pos(
0039 _Map& __map, _IterK&& __it_key, _IterM&& __it_mapped, _KeyArg&& __key, _MArgs&&... __mapped_args) {
0040 auto __on_key_failed = std::__make_exception_guard([&]() noexcept {
0041 using _KeyContainer = typename _Map::key_container_type;
0042 if constexpr (__container_traits<_KeyContainer>::__emplacement_has_strong_exception_safety_guarantee) {
0043
0044 } else {
0045
0046 __map.clear() ;
0047 }
0048 });
0049 auto __key_it = __map.__containers_.keys.emplace(__it_key, std::forward<_KeyArg>(__key));
0050 __on_key_failed.__complete();
0051
0052 auto __on_value_failed = std::__make_exception_guard([&]() noexcept {
0053 using _MappedContainer = typename _Map::mapped_container_type;
0054 if constexpr (!__container_traits<_MappedContainer>::__emplacement_has_strong_exception_safety_guarantee) {
0055
0056 __map.clear() ;
0057 } else {
0058
0059
0060 # if _LIBCPP_HAS_EXCEPTIONS
0061 try {
0062 # endif
0063 __map.__containers_.keys.erase(__key_it);
0064 # if _LIBCPP_HAS_EXCEPTIONS
0065 } catch (...) {
0066
0067
0068
0069
0070
0071 __map.clear() ;
0072 }
0073 # endif
0074 }
0075 });
0076 auto __mapped_it = __map.__containers_.values.emplace(__it_mapped, std::forward<_MArgs>(__mapped_args)...);
0077 __on_value_failed.__complete();
0078
0079 return typename _Map::iterator(std::move(__key_it), std::move(__mapped_it));
0080 }
0081
0082
0083
0084 template <class _Map, class _InputIterator, class _Sentinel>
0085 _LIBCPP_HIDE_FROM_ABI static typename _Map::size_type
0086 __append(_Map& __map, _InputIterator __first, _Sentinel __last) {
0087 typename _Map::size_type __num_appended = 0;
0088 for (; __first != __last; ++__first) {
0089 typename _Map::value_type __kv = *__first;
0090 __map.__containers_.keys.insert(__map.__containers_.keys.end(), std::move(__kv.first));
0091 __map.__containers_.values.insert(__map.__containers_.values.end(), std::move(__kv.second));
0092 ++__num_appended;
0093 }
0094 return __num_appended;
0095 }
0096 };
0097 _LIBCPP_END_NAMESPACE_STD
0098
0099 #endif
0100
0101 _LIBCPP_POP_MACROS
0102
0103 #endif