diff --git a/ChangeLog.md b/ChangeLog.md index 79c8d937a6148..ac956d4185a63 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -20,6 +20,7 @@ See docs/process.md for more on how version tagging works. 4.0.10 (in development) ---------------------- +- libcxx and libcxxabi were updated to LLVM 20.1.4. (#24346) - The `-sASYNCIFY_LAZY_LOAD_CODE` setting was deprecated. This setting was added as an experiment a long time ago and as far we know has no active users. In addition, it cannot work with JSPI (the future of ASYNCIFY). (#24383) diff --git a/system/lib/libcxx/include/__algorithm/adjacent_find.h b/system/lib/libcxx/include/__algorithm/adjacent_find.h index 6f15456e3a4d0..2508250d8796c 100644 --- a/system/lib/libcxx/include/__algorithm/adjacent_find.h +++ b/system/lib/libcxx/include/__algorithm/adjacent_find.h @@ -11,9 +11,9 @@ #define _LIBCPP___ALGORITHM_ADJACENT_FIND_H #include <__algorithm/comp.h> -#include <__algorithm/iterator_operations.h> #include <__config> -#include <__iterator/iterator_traits.h> +#include <__functional/identity.h> +#include <__type_traits/invoke.h> #include <__utility/move.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -25,14 +25,15 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD -template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Iter -__adjacent_find(_Iter __first, _Sent __last, _BinaryPredicate&& __pred) { +template +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Iter +__adjacent_find(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) { if (__first == __last) return __first; + _Iter __i = __first; while (++__i != __last) { - if (__pred(*__first, *__i)) + if (std::__invoke(__pred, std::__invoke(__proj, *__first), std::__invoke(__proj, *__i))) return __first; __first = __i; } @@ -40,13 +41,14 @@ __adjacent_find(_Iter __first, _Sent __last, _BinaryPredicate&& __pred) { } template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator adjacent_find(_ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred) { - return std::__adjacent_find(std::move(__first), std::move(__last), __pred); + __identity __proj; + return std::__adjacent_find(std::move(__first), std::move(__last), __pred, __proj); } template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator adjacent_find(_ForwardIterator __first, _ForwardIterator __last) { return std::adjacent_find(std::move(__first), std::move(__last), __equal_to()); } diff --git a/system/lib/libcxx/include/__algorithm/all_of.h b/system/lib/libcxx/include/__algorithm/all_of.h index ec84eea759296..6acc117fc47bc 100644 --- a/system/lib/libcxx/include/__algorithm/all_of.h +++ b/system/lib/libcxx/include/__algorithm/all_of.h @@ -11,6 +11,8 @@ #define _LIBCPP___ALGORITHM_ALL_OF_H #include <__config> +#include <__functional/identity.h> +#include <__type_traits/invoke.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -18,15 +20,23 @@ _LIBCPP_BEGIN_NAMESPACE_STD -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool -all_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) { - for (; __first != __last; ++__first) - if (!__pred(*__first)) +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool +__all_of(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) { + for (; __first != __last; ++__first) { + if (!std::__invoke(__pred, std::__invoke(__proj, *__first))) return false; + } return true; } +template +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool +all_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) { + __identity __proj; + return std::__all_of(__first, __last, __pred, __proj); +} + _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP___ALGORITHM_ALL_OF_H diff --git a/system/lib/libcxx/include/__algorithm/any_of.h b/system/lib/libcxx/include/__algorithm/any_of.h index b5ff778c4171d..4b6eb94517286 100644 --- a/system/lib/libcxx/include/__algorithm/any_of.h +++ b/system/lib/libcxx/include/__algorithm/any_of.h @@ -11,6 +11,8 @@ #define _LIBCPP___ALGORITHM_ANY_OF_H #include <__config> +#include <__functional/identity.h> +#include <__type_traits/invoke.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -18,15 +20,23 @@ _LIBCPP_BEGIN_NAMESPACE_STD -template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool -any_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) { - for (; __first != __last; ++__first) - if (__pred(*__first)) +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool +__any_of(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) { + for (; __first != __last; ++__first) { + if (std::__invoke(__pred, std::__invoke(__proj, *__first))) return true; + } return false; } +template +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool +any_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) { + __identity __proj; + return std::__any_of(__first, __last, __pred, __proj); +} + _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP___ALGORITHM_ANY_OF_H diff --git a/system/lib/libcxx/include/__algorithm/binary_search.h b/system/lib/libcxx/include/__algorithm/binary_search.h index 6065fc37274dc..4940059f285cd 100644 --- a/system/lib/libcxx/include/__algorithm/binary_search.h +++ b/system/lib/libcxx/include/__algorithm/binary_search.h @@ -13,7 +13,6 @@ #include <__algorithm/comp_ref_type.h> #include <__algorithm/lower_bound.h> #include <__config> -#include <__iterator/iterator_traits.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -22,14 +21,14 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp) { __first = std::lower_bound<_ForwardIterator, _Tp, __comp_ref_type<_Compare> >(__first, __last, __value, __comp); return __first != __last && !__comp(__value, *__first); } template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) { return std::binary_search(__first, __last, __value, __less<>()); } diff --git a/system/lib/libcxx/include/__algorithm/comp.h b/system/lib/libcxx/include/__algorithm/comp.h index a0fa88d6d2acd..ab3c598418828 100644 --- a/system/lib/libcxx/include/__algorithm/comp.h +++ b/system/lib/libcxx/include/__algorithm/comp.h @@ -11,6 +11,7 @@ #include <__config> #include <__type_traits/desugars_to.h> +#include <__type_traits/is_integral.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -44,6 +45,9 @@ struct __less { template inline const bool __desugars_to_v<__less_tag, __less<>, _Tp, _Tp> = true; +template +inline const bool __desugars_to_v<__totally_ordered_less_tag, __less<>, _Tp, _Tp> = is_integral<_Tp>::value; + _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP___ALGORITHM_COMP_H diff --git a/system/lib/libcxx/include/__algorithm/comp_ref_type.h b/system/lib/libcxx/include/__algorithm/comp_ref_type.h index c367fbb91ac28..6a9d5cef26719 100644 --- a/system/lib/libcxx/include/__algorithm/comp_ref_type.h +++ b/system/lib/libcxx/include/__algorithm/comp_ref_type.h @@ -56,10 +56,10 @@ struct __debug_less { // Pass the comparator by lvalue reference. Or in the debug mode, using a debugging wrapper that stores a reference. #if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG template -using __comp_ref_type = __debug_less<_Comp>; +using __comp_ref_type _LIBCPP_NODEBUG = __debug_less<_Comp>; #else template -using __comp_ref_type = _Comp&; +using __comp_ref_type _LIBCPP_NODEBUG = _Comp&; #endif _LIBCPP_END_NAMESPACE_STD diff --git a/system/lib/libcxx/include/__algorithm/copy.h b/system/lib/libcxx/include/__algorithm/copy.h index 0890b895f5409..962aa90059d57 100644 --- a/system/lib/libcxx/include/__algorithm/copy.h +++ b/system/lib/libcxx/include/__algorithm/copy.h @@ -11,11 +11,12 @@ #include <__algorithm/copy_move_common.h> #include <__algorithm/for_each_segment.h> -#include <__algorithm/iterator_operations.h> #include <__algorithm/min.h> #include <__config> +#include <__iterator/iterator_traits.h> #include <__iterator/segmented_iterator.h> #include <__type_traits/common_type.h> +#include <__type_traits/enable_if.h> #include <__utility/move.h> #include <__utility/pair.h> @@ -28,10 +29,9 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD -template +template inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> __copy(_InIter, _Sent, _OutIter); -template struct __copy_impl { template _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> @@ -47,7 +47,7 @@ struct __copy_impl { template struct _CopySegment { - using _Traits = __segmented_iterator_traits<_InIter>; + using _Traits _LIBCPP_NODEBUG = __segmented_iterator_traits<_InIter>; _OutIter& __result_; @@ -56,7 +56,7 @@ struct __copy_impl { _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void operator()(typename _Traits::__local_iterator __lfirst, typename _Traits::__local_iterator __llast) { - __result_ = std::__copy<_AlgPolicy>(__lfirst, __llast, std::move(__result_)).second; + __result_ = std::__copy(__lfirst, __llast, std::move(__result_)).second; } }; @@ -85,7 +85,7 @@ struct __copy_impl { while (true) { auto __local_last = _Traits::__end(__segment_iterator); auto __size = std::min<_DiffT>(__local_last - __local_first, __last - __first); - auto __iters = std::__copy<_AlgPolicy>(__first, __first + __size, __local_first); + auto __iters = std::__copy(__first, __first + __size, __local_first); __first = std::move(__iters.first); if (__first == __last) @@ -103,17 +103,16 @@ struct __copy_impl { } }; -template +template pair<_InIter, _OutIter> inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __copy(_InIter __first, _Sent __last, _OutIter __result) { - return std::__copy_move_unwrap_iters<__copy_impl<_AlgPolicy> >( - std::move(__first), std::move(__last), std::move(__result)); + return std::__copy_move_unwrap_iters<__copy_impl>(std::move(__first), std::move(__last), std::move(__result)); } template inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result) { - return std::__copy<_ClassicAlgPolicy>(__first, __last, __result).second; + return std::__copy(__first, __last, __result).second; } _LIBCPP_END_NAMESPACE_STD diff --git a/system/lib/libcxx/include/__algorithm/copy_backward.h b/system/lib/libcxx/include/__algorithm/copy_backward.h index 73dc846a975a4..48a768f577f55 100644 --- a/system/lib/libcxx/include/__algorithm/copy_backward.h +++ b/system/lib/libcxx/include/__algorithm/copy_backward.h @@ -13,8 +13,10 @@ #include <__algorithm/iterator_operations.h> #include <__algorithm/min.h> #include <__config> +#include <__iterator/iterator_traits.h> #include <__iterator/segmented_iterator.h> #include <__type_traits/common_type.h> +#include <__type_traits/enable_if.h> #include <__type_traits/is_constructible.h> #include <__utility/move.h> #include <__utility/pair.h> diff --git a/system/lib/libcxx/include/__algorithm/copy_if.h b/system/lib/libcxx/include/__algorithm/copy_if.h index 228e4d22323e3..ffea621fc0618 100644 --- a/system/lib/libcxx/include/__algorithm/copy_if.h +++ b/system/lib/libcxx/include/__algorithm/copy_if.h @@ -10,25 +10,41 @@ #define _LIBCPP___ALGORITHM_COPY_IF_H #include <__config> +#include <__functional/identity.h> +#include <__type_traits/invoke.h> +#include <__utility/move.h> +#include <__utility/pair.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header #endif +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + _LIBCPP_BEGIN_NAMESPACE_STD -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator -copy_if(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Predicate __pred) { +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter> +__copy_if(_InIter __first, _Sent __last, _OutIter __result, _Pred& __pred, _Proj& __proj) { for (; __first != __last; ++__first) { - if (__pred(*__first)) { + if (std::__invoke(__pred, std::__invoke(__proj, *__first))) { *__result = *__first; ++__result; } } - return __result; + return std::make_pair(std::move(__first), std::move(__result)); +} + +template +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator +copy_if(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Predicate __pred) { + __identity __proj; + return std::__copy_if(__first, __last, __result, __pred, __proj).second; } _LIBCPP_END_NAMESPACE_STD +_LIBCPP_POP_MACROS + #endif // _LIBCPP___ALGORITHM_COPY_IF_H diff --git a/system/lib/libcxx/include/__algorithm/copy_move_common.h b/system/lib/libcxx/include/__algorithm/copy_move_common.h index 8a98451a8f965..7471012c01d96 100644 --- a/system/lib/libcxx/include/__algorithm/copy_move_common.h +++ b/system/lib/libcxx/include/__algorithm/copy_move_common.h @@ -9,10 +9,10 @@ #ifndef _LIBCPP___ALGORITHM_COPY_MOVE_COMMON_H #define _LIBCPP___ALGORITHM_COPY_MOVE_COMMON_H -#include <__algorithm/iterator_operations.h> #include <__algorithm/unwrap_iter.h> #include <__algorithm/unwrap_range.h> #include <__config> +#include <__cstddef/size_t.h> #include <__iterator/iterator_traits.h> #include <__memory/pointer_traits.h> #include <__string/constexpr_c_functions.h> @@ -24,7 +24,6 @@ #include <__type_traits/is_volatile.h> #include <__utility/move.h> #include <__utility/pair.h> -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/system/lib/libcxx/include/__algorithm/count.h b/system/lib/libcxx/include/__algorithm/count.h index 1cfe7f631ac1b..cd9125779ec64 100644 --- a/system/lib/libcxx/include/__algorithm/count.h +++ b/system/lib/libcxx/include/__algorithm/count.h @@ -16,9 +16,10 @@ #include <__bit/popcount.h> #include <__config> #include <__functional/identity.h> -#include <__functional/invoke.h> #include <__fwd/bit_reference.h> #include <__iterator/iterator_traits.h> +#include <__type_traits/enable_if.h> +#include <__type_traits/invoke.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -43,7 +44,7 @@ __count(_Iter __first, _Sent __last, const _Tp& __value, _Proj& __proj) { // __bit_iterator implementation template _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 typename __bit_iterator<_Cp, _IsConst>::difference_type -__count_bool(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n) { +__count_bool(__bit_iterator<_Cp, _IsConst> __first, typename __size_difference_type_traits<_Cp>::size_type __n) { using _It = __bit_iterator<_Cp, _IsConst>; using __storage_type = typename _It::__storage_type; using difference_type = typename _It::difference_type; @@ -74,12 +75,14 @@ template > __count(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, const _Tp& __value, _Proj&) { if (__value) - return std::__count_bool(__first, static_cast(__last - __first)); - return std::__count_bool(__first, static_cast(__last - __first)); + return std::__count_bool( + __first, static_cast::size_type>(__last - __first)); + return std::__count_bool( + __first, static_cast::size_type>(__last - __first)); } template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __iter_diff_t<_InputIterator> +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __iter_diff_t<_InputIterator> count(_InputIterator __first, _InputIterator __last, const _Tp& __value) { __identity __proj; return std::__count<_ClassicAlgPolicy>(__first, __last, __value, __proj); diff --git a/system/lib/libcxx/include/__algorithm/count_if.h b/system/lib/libcxx/include/__algorithm/count_if.h index 25782069d0327..26f945e6bd98c 100644 --- a/system/lib/libcxx/include/__algorithm/count_if.h +++ b/system/lib/libcxx/include/__algorithm/count_if.h @@ -10,8 +10,11 @@ #ifndef _LIBCPP___ALGORITHM_COUNT_IF_H #define _LIBCPP___ALGORITHM_COUNT_IF_H +#include <__algorithm/iterator_operations.h> #include <__config> +#include <__functional/identity.h> #include <__iterator/iterator_traits.h> +#include <__type_traits/invoke.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -19,15 +22,23 @@ _LIBCPP_BEGIN_NAMESPACE_STD +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __policy_iter_diff_t<_AlgPolicy, _Iter> +__count_if(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) { + __policy_iter_diff_t<_AlgPolicy, _Iter> __counter(0); + for (; __first != __last; ++__first) { + if (std::__invoke(__pred, std::__invoke(__proj, *__first))) + ++__counter; + } + return __counter; +} + template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 typename iterator_traits<_InputIterator>::difference_type count_if(_InputIterator __first, _InputIterator __last, _Predicate __pred) { - typename iterator_traits<_InputIterator>::difference_type __r(0); - for (; __first != __last; ++__first) - if (__pred(*__first)) - ++__r; - return __r; + __identity __proj; + return std::__count_if<_ClassicAlgPolicy>(__first, __last, __pred, __proj); } _LIBCPP_END_NAMESPACE_STD diff --git a/system/lib/libcxx/include/__algorithm/equal.h b/system/lib/libcxx/include/__algorithm/equal.h index bfc8f72f6eb19..a276bb9954c9b 100644 --- a/system/lib/libcxx/include/__algorithm/equal.h +++ b/system/lib/libcxx/include/__algorithm/equal.h @@ -14,13 +14,12 @@ #include <__algorithm/unwrap_iter.h> #include <__config> #include <__functional/identity.h> -#include <__functional/invoke.h> #include <__iterator/distance.h> #include <__iterator/iterator_traits.h> #include <__string/constexpr_c_functions.h> #include <__type_traits/desugars_to.h> #include <__type_traits/enable_if.h> -#include <__type_traits/is_constant_evaluated.h> +#include <__type_traits/invoke.h> #include <__type_traits/is_equality_comparable.h> #include <__type_traits/is_volatile.h> #include <__utility/move.h> @@ -35,7 +34,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __equal_iter_impl( +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __equal_iter_impl( _InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _BinaryPredicate& __pred) { for (; __first1 != __last1; ++__first1, (void)++__first2) if (!__pred(*__first1, *__first2)) @@ -49,20 +48,20 @@ template && !is_volatile<_Tp>::value && !is_volatile<_Up>::value && __libcpp_is_trivially_equality_comparable<_Tp, _Up>::value, int> = 0> -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __equal_iter_impl(_Tp* __first1, _Tp* __last1, _Up* __first2, _BinaryPredicate&) { return std::__constexpr_memcmp_equal(__first1, __first2, __element_count(__last1 - __first1)); } template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _BinaryPredicate __pred) { return std::__equal_iter_impl( std::__unwrap_iter(__first1), std::__unwrap_iter(__last1), std::__unwrap_iter(__first2), __pred); } template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2) { return std::equal(__first1, __last1, __first2, __equal_to()); } @@ -70,7 +69,7 @@ equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first #if _LIBCPP_STD_VER >= 14 template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __equal_impl( +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __equal_impl( _Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2, _Pred& __comp, _Proj1& __proj1, _Proj2& __proj2) { while (__first1 != __last1 && __first2 != __last2) { if (!std::__invoke(__comp, std::__invoke(__proj1, *__first1), std::__invoke(__proj2, *__first2))) @@ -90,13 +89,13 @@ template ::value && !is_volatile<_Tp>::value && !is_volatile<_Up>::value && __libcpp_is_trivially_equality_comparable<_Tp, _Up>::value, int> = 0> -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __equal_impl(_Tp* __first1, _Tp* __last1, _Up* __first2, _Up*, _Pred&, _Proj1&, _Proj2&) { return std::__constexpr_memcmp_equal(__first1, __first2, __element_count(__last1 - __first1)); } template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, @@ -119,7 +118,7 @@ equal(_InputIterator1 __first1, } template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) { return std::equal(__first1, __last1, __first2, __last2, __equal_to()); } diff --git a/system/lib/libcxx/include/__algorithm/equal_range.h b/system/lib/libcxx/include/__algorithm/equal_range.h index 09bbf8f006021..ff6f4f2225c7a 100644 --- a/system/lib/libcxx/include/__algorithm/equal_range.h +++ b/system/lib/libcxx/include/__algorithm/equal_range.h @@ -17,11 +17,7 @@ #include <__algorithm/upper_bound.h> #include <__config> #include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__iterator/advance.h> -#include <__iterator/distance.h> -#include <__iterator/iterator_traits.h> -#include <__iterator/next.h> +#include <__type_traits/invoke.h> #include <__type_traits/is_callable.h> #include <__type_traits/is_constructible.h> #include <__utility/move.h> @@ -60,9 +56,9 @@ __equal_range(_Iter __first, _Sent __last, const _Tp& __value, _Compare&& __comp } template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_ForwardIterator, _ForwardIterator> +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_ForwardIterator, _ForwardIterator> equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp) { - static_assert(__is_callable<_Compare, decltype(*__first), const _Tp&>::value, "The comparator has to be callable"); + static_assert(__is_callable<_Compare&, decltype(*__first), const _Tp&>::value, "The comparator has to be callable"); static_assert(is_copy_constructible<_ForwardIterator>::value, "Iterator has to be copy constructible"); return std::__equal_range<_ClassicAlgPolicy>( std::move(__first), @@ -73,7 +69,7 @@ equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __valu } template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_ForwardIterator, _ForwardIterator> +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_ForwardIterator, _ForwardIterator> equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) { return std::equal_range(std::move(__first), std::move(__last), __value, __less<>()); } diff --git a/system/lib/libcxx/include/__algorithm/fill_n.h b/system/lib/libcxx/include/__algorithm/fill_n.h index f29633f88087f..a7e01c45b9222 100644 --- a/system/lib/libcxx/include/__algorithm/fill_n.h +++ b/system/lib/libcxx/include/__algorithm/fill_n.h @@ -12,7 +12,6 @@ #include <__algorithm/min.h> #include <__config> #include <__fwd/bit_reference.h> -#include <__iterator/iterator_traits.h> #include <__memory/pointer_traits.h> #include <__utility/convert_to_integral.h> @@ -33,7 +32,7 @@ __fill_n(_OutputIterator __first, _Size __n, const _Tp& __value); template _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void -__fill_n_bool(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n) { +__fill_n_bool(__bit_iterator<_Cp, false> __first, typename __size_difference_type_traits<_Cp>::size_type __n) { using _It = __bit_iterator<_Cp, false>; using __storage_type = typename _It::__storage_type; diff --git a/system/lib/libcxx/include/__algorithm/find.h b/system/lib/libcxx/include/__algorithm/find.h index 7f58dbb13a577..24b8b2f96443c 100644 --- a/system/lib/libcxx/include/__algorithm/find.h +++ b/system/lib/libcxx/include/__algorithm/find.h @@ -17,17 +17,18 @@ #include <__bit/invert_if.h> #include <__config> #include <__functional/identity.h> -#include <__functional/invoke.h> #include <__fwd/bit_reference.h> #include <__iterator/segmented_iterator.h> #include <__string/constexpr_c_functions.h> +#include <__type_traits/enable_if.h> +#include <__type_traits/invoke.h> +#include <__type_traits/is_equality_comparable.h> #include <__type_traits/is_integral.h> -#include <__type_traits/is_same.h> #include <__type_traits/is_signed.h> #include <__utility/move.h> #include -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +#if _LIBCPP_HAS_WIDE_CHARACTERS # include #endif @@ -63,7 +64,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp* __find(_Tp* __first, _T return __last; } -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +#if _LIBCPP_HAS_WIDE_CHARACTERS template _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cp, _IsConst> -__find_bool(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n) { +__find_bool(__bit_iterator<_Cp, _IsConst> __first, typename __size_difference_type_traits<_Cp>::size_type __n) { using _It = __bit_iterator<_Cp, _IsConst>; using __storage_type = typename _It::__storage_type; @@ -134,8 +135,10 @@ template __find(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, const _Tp& __value, _Proj&) { if (static_cast(__value)) - return std::__find_bool(__first, static_cast(__last - __first)); - return std::__find_bool(__first, static_cast(__last - __first)); + return std::__find_bool( + __first, static_cast::size_type>(__last - __first)); + return std::__find_bool( + __first, static_cast::size_type>(__last - __first)); } // segmented iterator implementation @@ -167,7 +170,7 @@ struct __find_segment { // public API template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator find(_InputIterator __first, _InputIterator __last, const _Tp& __value) { __identity __proj; return std::__rewrap_iter( diff --git a/system/lib/libcxx/include/__algorithm/find_end.h b/system/lib/libcxx/include/__algorithm/find_end.h index 7e08e7953534e..86b4a3e2e3689 100644 --- a/system/lib/libcxx/include/__algorithm/find_end.h +++ b/system/lib/libcxx/include/__algorithm/find_end.h @@ -12,14 +12,10 @@ #include <__algorithm/comp.h> #include <__algorithm/iterator_operations.h> -#include <__algorithm/search.h> #include <__config> #include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__iterator/advance.h> #include <__iterator/iterator_traits.h> -#include <__iterator/next.h> -#include <__iterator/reverse_iterator.h> +#include <__type_traits/invoke.h> #include <__utility/pair.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -80,111 +76,8 @@ _LIBCPP_HIDE_FROM_ABI inline _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter1, _Iter1> } } -template < class _IterOps, - class _Pred, - class _Iter1, - class _Sent1, - class _Iter2, - class _Sent2, - class _Proj1, - class _Proj2> -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Iter1 __find_end( - _Iter1 __first1, - _Sent1 __sent1, - _Iter2 __first2, - _Sent2 __sent2, - _Pred& __pred, - _Proj1& __proj1, - _Proj2& __proj2, - bidirectional_iterator_tag, - bidirectional_iterator_tag) { - auto __last1 = _IterOps::next(__first1, __sent1); - auto __last2 = _IterOps::next(__first2, __sent2); - // modeled after search algorithm (in reverse) - if (__first2 == __last2) - return __last1; // Everything matches an empty sequence - _Iter1 __l1 = __last1; - _Iter2 __l2 = __last2; - --__l2; - while (true) { - // Find last element in sequence 1 that matchs *(__last2-1), with a mininum of loop checks - while (true) { - if (__first1 == __l1) // return __last1 if no element matches *__first2 - return __last1; - if (std::__invoke(__pred, std::__invoke(__proj1, *--__l1), std::__invoke(__proj2, *__l2))) - break; - } - // *__l1 matches *__l2, now match elements before here - _Iter1 __m1 = __l1; - _Iter2 __m2 = __l2; - while (true) { - if (__m2 == __first2) // If pattern exhausted, __m1 is the answer (works for 1 element pattern) - return __m1; - if (__m1 == __first1) // Otherwise if source exhaused, pattern not found - return __last1; - - // if there is a mismatch, restart with a new __l1 - if (!std::__invoke(__pred, std::__invoke(__proj1, *--__m1), std::__invoke(__proj2, *--__m2))) { - break; - } // else there is a match, check next elements - } - } -} - -template < class _AlgPolicy, - class _Pred, - class _Iter1, - class _Sent1, - class _Iter2, - class _Sent2, - class _Proj1, - class _Proj2> -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iter1 __find_end( - _Iter1 __first1, - _Sent1 __sent1, - _Iter2 __first2, - _Sent2 __sent2, - _Pred& __pred, - _Proj1& __proj1, - _Proj2& __proj2, - random_access_iterator_tag, - random_access_iterator_tag) { - typedef typename iterator_traits<_Iter1>::difference_type _D1; - auto __last1 = _IterOps<_AlgPolicy>::next(__first1, __sent1); - auto __last2 = _IterOps<_AlgPolicy>::next(__first2, __sent2); - // Take advantage of knowing source and pattern lengths. Stop short when source is smaller than pattern - auto __len2 = __last2 - __first2; - if (__len2 == 0) - return __last1; - auto __len1 = __last1 - __first1; - if (__len1 < __len2) - return __last1; - const _Iter1 __s = __first1 + _D1(__len2 - 1); // End of pattern match can't go before here - _Iter1 __l1 = __last1; - _Iter2 __l2 = __last2; - --__l2; - while (true) { - while (true) { - if (__s == __l1) - return __last1; - if (std::__invoke(__pred, std::__invoke(__proj1, *--__l1), std::__invoke(__proj2, *__l2))) - break; - } - _Iter1 __m1 = __l1; - _Iter2 __m2 = __l2; - while (true) { - if (__m2 == __first2) - return __m1; - // no need to check range on __m1 because __s guarantees we have enough source - if (!std::__invoke(__pred, std::__invoke(__proj1, *--__m1), std::__invoke(*--__m2))) { - break; - } - } - } -} - template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator1 __find_end_classic( +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator1 __find_end_classic( _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, @@ -205,7 +98,7 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Fo } template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1 find_end( +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1 find_end( _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, @@ -215,7 +108,7 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Fo } template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1 +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1 find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2) { return std::find_end(__first1, __last1, __first2, __last2, __equal_to()); } diff --git a/system/lib/libcxx/include/__algorithm/find_first_of.h b/system/lib/libcxx/include/__algorithm/find_first_of.h index 6b99f562f8804..45ec133154371 100644 --- a/system/lib/libcxx/include/__algorithm/find_first_of.h +++ b/system/lib/libcxx/include/__algorithm/find_first_of.h @@ -12,7 +12,6 @@ #include <__algorithm/comp.h> #include <__config> -#include <__iterator/iterator_traits.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -35,7 +34,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator1 __find_fir } template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1 find_first_of( +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1 find_first_of( _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, @@ -45,7 +44,7 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Fo } template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1 find_first_of( +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1 find_first_of( _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2) { return std::__find_first_of_ce(__first1, __last1, __first2, __last2, __equal_to()); } diff --git a/system/lib/libcxx/include/__algorithm/find_if.h b/system/lib/libcxx/include/__algorithm/find_if.h index 22092d352b06e..fd63bcc3a50dd 100644 --- a/system/lib/libcxx/include/__algorithm/find_if.h +++ b/system/lib/libcxx/include/__algorithm/find_if.h @@ -19,7 +19,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator find_if(_InputIterator __first, _InputIterator __last, _Predicate __pred) { for (; __first != __last; ++__first) if (__pred(*__first)) diff --git a/system/lib/libcxx/include/__algorithm/find_if_not.h b/system/lib/libcxx/include/__algorithm/find_if_not.h index cc2001967f0c5..b4441b297c4bf 100644 --- a/system/lib/libcxx/include/__algorithm/find_if_not.h +++ b/system/lib/libcxx/include/__algorithm/find_if_not.h @@ -19,7 +19,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator find_if_not(_InputIterator __first, _InputIterator __last, _Predicate __pred) { for (; __first != __last; ++__first) if (!__pred(*__first)) diff --git a/system/lib/libcxx/include/__algorithm/for_each.h b/system/lib/libcxx/include/__algorithm/for_each.h index 259e527f87f91..e08f583504c01 100644 --- a/system/lib/libcxx/include/__algorithm/for_each.h +++ b/system/lib/libcxx/include/__algorithm/for_each.h @@ -14,7 +14,6 @@ #include <__config> #include <__iterator/segmented_iterator.h> #include <__ranges/movable_box.h> -#include <__type_traits/enable_if.h> #include <__utility/in_place.h> #include <__utility/move.h> diff --git a/system/lib/libcxx/include/__algorithm/includes.h b/system/lib/libcxx/include/__algorithm/includes.h index 62af03c374260..bc6c6579693b1 100644 --- a/system/lib/libcxx/include/__algorithm/includes.h +++ b/system/lib/libcxx/include/__algorithm/includes.h @@ -13,8 +13,7 @@ #include <__algorithm/comp_ref_type.h> #include <__config> #include <__functional/identity.h> -#include <__functional/invoke.h> -#include <__iterator/iterator_traits.h> +#include <__type_traits/invoke.h> #include <__type_traits/is_callable.h> #include <__utility/move.h> @@ -47,14 +46,14 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __includes( } template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _Compare __comp) { static_assert( - __is_callable<_Compare, decltype(*__first1), decltype(*__first2)>::value, "Comparator has to be callable"); + __is_callable<_Compare&, decltype(*__first1), decltype(*__first2)>::value, "The comparator has to be callable"); return std::__includes( std::move(__first1), @@ -67,7 +66,7 @@ includes(_InputIterator1 __first1, } template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) { return std::includes(std::move(__first1), std::move(__last1), std::move(__first2), std::move(__last2), __less<>()); } diff --git a/system/lib/libcxx/include/__algorithm/inplace_merge.h b/system/lib/libcxx/include/__algorithm/inplace_merge.h index a6bcc66a2fa47..1fc31b66f4bd6 100644 --- a/system/lib/libcxx/include/__algorithm/inplace_merge.h +++ b/system/lib/libcxx/include/__algorithm/inplace_merge.h @@ -18,16 +18,15 @@ #include <__algorithm/rotate.h> #include <__algorithm/upper_bound.h> #include <__config> +#include <__cstddef/ptrdiff_t.h> #include <__functional/identity.h> -#include <__iterator/advance.h> -#include <__iterator/distance.h> #include <__iterator/iterator_traits.h> #include <__iterator/reverse_iterator.h> #include <__memory/destruct_n.h> -#include <__memory/temporary_buffer.h> #include <__memory/unique_ptr.h> +#include <__memory/unique_temporary_buffer.h> +#include <__utility/move.h> #include <__utility/pair.h> -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -45,17 +44,17 @@ class __invert // invert the sense of a comparison _Predicate __p_; public: - _LIBCPP_HIDE_FROM_ABI __invert() {} + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 __invert() {} - _LIBCPP_HIDE_FROM_ABI explicit __invert(_Predicate __p) : __p_(__p) {} + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 explicit __invert(_Predicate __p) : __p_(__p) {} template - _LIBCPP_HIDE_FROM_ABI bool operator()(const _T1& __x) { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool operator()(const _T1& __x) { return !__p_(__x); } template - _LIBCPP_HIDE_FROM_ABI bool operator()(const _T1& __x, const _T2& __y) { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 bool operator()(const _T1& __x, const _T2& __y) { return __p_(__y, __x); } }; @@ -67,7 +66,7 @@ template -_LIBCPP_HIDE_FROM_ABI void __half_inplace_merge( +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __half_inplace_merge( _InputIterator1 __first1, _Sent1 __last1, _InputIterator2 __first2, @@ -92,7 +91,7 @@ _LIBCPP_HIDE_FROM_ABI void __half_inplace_merge( } template -_LIBCPP_HIDE_FROM_ABI void __buffered_inplace_merge( +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __buffered_inplace_merge( _BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last, @@ -123,7 +122,7 @@ _LIBCPP_HIDE_FROM_ABI void __buffered_inplace_merge( } template -void __inplace_merge( +_LIBCPP_CONSTEXPR_SINCE_CXX26 void __inplace_merge( _BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last, @@ -208,16 +207,19 @@ _LIBCPP_HIDE_FROM_ABI void __inplace_merge( _BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last, _Compare&& __comp) { typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type; typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type; - difference_type __len1 = _IterOps<_AlgPolicy>::distance(__first, __middle); - difference_type __len2 = _IterOps<_AlgPolicy>::distance(__middle, __last); - difference_type __buf_size = std::min(__len1, __len2); - // TODO: Remove the use of std::get_temporary_buffer - _LIBCPP_SUPPRESS_DEPRECATED_PUSH - pair __buf = std::get_temporary_buffer(__buf_size); - _LIBCPP_SUPPRESS_DEPRECATED_POP - unique_ptr __h(__buf.first); + difference_type __len1 = _IterOps<_AlgPolicy>::distance(__first, __middle); + difference_type __len2 = _IterOps<_AlgPolicy>::distance(__middle, __last); + difference_type __buf_size = std::min(__len1, __len2); + __unique_temporary_buffer __unique_buf = std::__allocate_unique_temporary_buffer(__buf_size); return std::__inplace_merge<_AlgPolicy>( - std::move(__first), std::move(__middle), std::move(__last), __comp, __len1, __len2, __buf.first, __buf.second); + std::move(__first), + std::move(__middle), + std::move(__last), + __comp, + __len1, + __len2, + __unique_buf.get(), + __unique_buf.get_deleter().__count_); } template diff --git a/system/lib/libcxx/include/__algorithm/is_heap.h b/system/lib/libcxx/include/__algorithm/is_heap.h index c589b804a5dc0..dfe06200cedcb 100644 --- a/system/lib/libcxx/include/__algorithm/is_heap.h +++ b/system/lib/libcxx/include/__algorithm/is_heap.h @@ -13,7 +13,6 @@ #include <__algorithm/comp_ref_type.h> #include <__algorithm/is_heap_until.h> #include <__config> -#include <__iterator/iterator_traits.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -22,13 +21,13 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { return std::__is_heap_until(__first, __last, static_cast<__comp_ref_type<_Compare> >(__comp)) == __last; } template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) { return std::is_heap(__first, __last, __less<>()); } diff --git a/system/lib/libcxx/include/__algorithm/is_heap_until.h b/system/lib/libcxx/include/__algorithm/is_heap_until.h index a174f2453cfcc..7444d978e37f5 100644 --- a/system/lib/libcxx/include/__algorithm/is_heap_until.h +++ b/system/lib/libcxx/include/__algorithm/is_heap_until.h @@ -46,13 +46,13 @@ __is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last, _Co } template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { return std::__is_heap_until(__first, __last, static_cast<__comp_ref_type<_Compare> >(__comp)); } template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last) { return std::__is_heap_until(__first, __last, __less<>()); } diff --git a/system/lib/libcxx/include/__algorithm/is_partitioned.h b/system/lib/libcxx/include/__algorithm/is_partitioned.h index 1f7c8b0b267e7..700e452bbfa63 100644 --- a/system/lib/libcxx/include/__algorithm/is_partitioned.h +++ b/system/lib/libcxx/include/__algorithm/is_partitioned.h @@ -18,7 +18,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool is_partitioned(_InputIterator __first, _InputIterator __last, _Predicate __pred) { for (; __first != __last; ++__first) if (!__pred(*__first)) diff --git a/system/lib/libcxx/include/__algorithm/is_permutation.h b/system/lib/libcxx/include/__algorithm/is_permutation.h index 2ddfb32a212bb..1afb11596bc6b 100644 --- a/system/lib/libcxx/include/__algorithm/is_permutation.h +++ b/system/lib/libcxx/include/__algorithm/is_permutation.h @@ -14,12 +14,13 @@ #include <__algorithm/iterator_operations.h> #include <__config> #include <__functional/identity.h> -#include <__functional/invoke.h> #include <__iterator/concepts.h> #include <__iterator/distance.h> #include <__iterator/iterator_traits.h> -#include <__iterator/next.h> +#include <__type_traits/enable_if.h> +#include <__type_traits/invoke.h> #include <__type_traits/is_callable.h> +#include <__type_traits/is_same.h> #include <__utility/move.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -113,7 +114,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __is_permutation_impl( // 2+1 iterators, predicate. Not used by range algorithms. template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __is_permutation( +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __is_permutation( _ForwardIterator1 __first1, _Sentinel1 __last1, _ForwardIterator2 __first2, _BinaryPredicate&& __pred) { // Shorten sequences as much as possible by lopping of any equal prefix. for (; __first1 != __last1; ++__first1, (void)++__first2) { @@ -247,17 +248,17 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __is_permutation( // 2+1 iterators, predicate template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool is_permutation( +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool is_permutation( _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _BinaryPredicate __pred) { - static_assert(__is_callable<_BinaryPredicate, decltype(*__first1), decltype(*__first2)>::value, - "The predicate has to be callable"); + static_assert(__is_callable<_BinaryPredicate&, decltype(*__first1), decltype(*__first2)>::value, + "The comparator has to be callable"); return std::__is_permutation<_ClassicAlgPolicy>(std::move(__first1), std::move(__last1), std::move(__first2), __pred); } // 2+1 iterators template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2) { return std::is_permutation(__first1, __last1, __first2, __equal_to()); } @@ -266,7 +267,7 @@ is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIt // 2+2 iterators template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool is_permutation( +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool is_permutation( _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2) { return std::__is_permutation<_ClassicAlgPolicy>( std::move(__first1), @@ -280,14 +281,14 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 boo // 2+2 iterators, predicate template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool is_permutation( +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool is_permutation( _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred) { - static_assert(__is_callable<_BinaryPredicate, decltype(*__first1), decltype(*__first2)>::value, - "The predicate has to be callable"); + static_assert(__is_callable<_BinaryPredicate&, decltype(*__first1), decltype(*__first2)>::value, + "The comparator has to be callable"); return std::__is_permutation<_ClassicAlgPolicy>( std::move(__first1), diff --git a/system/lib/libcxx/include/__algorithm/is_sorted.h b/system/lib/libcxx/include/__algorithm/is_sorted.h index 3befb1ac9c26a..196ae0beec014 100644 --- a/system/lib/libcxx/include/__algorithm/is_sorted.h +++ b/system/lib/libcxx/include/__algorithm/is_sorted.h @@ -13,7 +13,6 @@ #include <__algorithm/comp_ref_type.h> #include <__algorithm/is_sorted_until.h> #include <__config> -#include <__iterator/iterator_traits.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -22,13 +21,13 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool is_sorted(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) { return std::__is_sorted_until<__comp_ref_type<_Compare> >(__first, __last, __comp) == __last; } template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool is_sorted(_ForwardIterator __first, _ForwardIterator __last) { return std::is_sorted(__first, __last, __less<>()); } diff --git a/system/lib/libcxx/include/__algorithm/is_sorted_until.h b/system/lib/libcxx/include/__algorithm/is_sorted_until.h index 53a49f00de31e..606641949db98 100644 --- a/system/lib/libcxx/include/__algorithm/is_sorted_until.h +++ b/system/lib/libcxx/include/__algorithm/is_sorted_until.h @@ -12,7 +12,6 @@ #include <__algorithm/comp.h> #include <__algorithm/comp_ref_type.h> #include <__config> -#include <__iterator/iterator_traits.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -35,13 +34,13 @@ __is_sorted_until(_ForwardIterator __first, _ForwardIterator __last, _Compare __ } template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator is_sorted_until(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) { return std::__is_sorted_until<__comp_ref_type<_Compare> >(__first, __last, __comp); } template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator is_sorted_until(_ForwardIterator __first, _ForwardIterator __last) { return std::is_sorted_until(__first, __last, __less<>()); } diff --git a/system/lib/libcxx/include/__algorithm/iterator_operations.h b/system/lib/libcxx/include/__algorithm/iterator_operations.h index 8ced989233bc4..e5c89c1e67e3a 100644 --- a/system/lib/libcxx/include/__algorithm/iterator_operations.h +++ b/system/lib/libcxx/include/__algorithm/iterator_operations.h @@ -48,13 +48,13 @@ struct _RangeAlgPolicy {}; template <> struct _IterOps<_RangeAlgPolicy> { template - using __value_type = iter_value_t<_Iter>; + using __value_type _LIBCPP_NODEBUG = iter_value_t<_Iter>; template - using __iterator_category = ranges::__iterator_concept<_Iter>; + using __iterator_category _LIBCPP_NODEBUG = ranges::__iterator_concept<_Iter>; template - using __difference_type = iter_difference_t<_Iter>; + using __difference_type _LIBCPP_NODEBUG = iter_difference_t<_Iter>; static constexpr auto advance = ranges::advance; static constexpr auto distance = ranges::distance; @@ -72,13 +72,13 @@ struct _ClassicAlgPolicy {}; template <> struct _IterOps<_ClassicAlgPolicy> { template - using __value_type = typename iterator_traits<_Iter>::value_type; + using __value_type _LIBCPP_NODEBUG = typename iterator_traits<_Iter>::value_type; template - using __iterator_category = typename iterator_traits<_Iter>::iterator_category; + using __iterator_category _LIBCPP_NODEBUG = typename iterator_traits<_Iter>::iterator_category; template - using __difference_type = typename iterator_traits<_Iter>::difference_type; + using __difference_type _LIBCPP_NODEBUG = typename iterator_traits<_Iter>::difference_type; // advance template @@ -94,10 +94,10 @@ struct _IterOps<_ClassicAlgPolicy> { } template - using __deref_t = decltype(*std::declval<_Iter&>()); + using __deref_t _LIBCPP_NODEBUG = decltype(*std::declval<_Iter&>()); template - using __move_t = decltype(std::move(*std::declval<_Iter&>())); + using __move_t _LIBCPP_NODEBUG = decltype(std::move(*std::declval<_Iter&>())); template _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 static void __validate_iter_reference() { @@ -216,6 +216,9 @@ struct _IterOps<_ClassicAlgPolicy> { } }; +template +using __policy_iter_diff_t _LIBCPP_NODEBUG = typename _IterOps<_AlgPolicy>::template __difference_type<_Iter>; + _LIBCPP_END_NAMESPACE_STD _LIBCPP_POP_MACROS diff --git a/system/lib/libcxx/include/__algorithm/lexicographical_compare.h b/system/lib/libcxx/include/__algorithm/lexicographical_compare.h index edc29e269c88c..ebe7e3b56a292 100644 --- a/system/lib/libcxx/include/__algorithm/lexicographical_compare.h +++ b/system/lib/libcxx/include/__algorithm/lexicographical_compare.h @@ -10,48 +10,120 @@ #define _LIBCPP___ALGORITHM_LEXICOGRAPHICAL_COMPARE_H #include <__algorithm/comp.h> -#include <__algorithm/comp_ref_type.h> +#include <__algorithm/min.h> +#include <__algorithm/mismatch.h> +#include <__algorithm/simd_utils.h> +#include <__algorithm/unwrap_iter.h> #include <__config> +#include <__functional/identity.h> #include <__iterator/iterator_traits.h> +#include <__string/constexpr_c_functions.h> +#include <__type_traits/desugars_to.h> +#include <__type_traits/enable_if.h> +#include <__type_traits/invoke.h> +#include <__type_traits/is_equality_comparable.h> +#include <__type_traits/is_integral.h> +#include <__type_traits/is_trivially_lexicographically_comparable.h> +#include <__type_traits/is_volatile.h> + +#if _LIBCPP_HAS_WIDE_CHARACTERS +# include +#endif #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header #endif +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + _LIBCPP_BEGIN_NAMESPACE_STD -template +template _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __lexicographical_compare( - _InputIterator1 __first1, - _InputIterator1 __last1, - _InputIterator2 __first2, - _InputIterator2 __last2, - _Compare __comp) { - for (; __first2 != __last2; ++__first1, (void)++__first2) { - if (__first1 == __last1 || __comp(*__first1, *__first2)) + _Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2, _Comp& __comp, _Proj1& __proj1, _Proj2& __proj2) { + while (__first2 != __last2) { + if (__first1 == __last1 || + std::__invoke(__comp, std::__invoke(__proj1, *__first1), std::__invoke(__proj2, *__first2))) return true; - if (__comp(*__first2, *__first1)) + if (std::__invoke(__comp, std::__invoke(__proj2, *__first2), std::__invoke(__proj1, *__first1))) return false; + ++__first1; + ++__first2; } return false; } +#if _LIBCPP_STD_VER >= 14 + +// If the comparison operation is equivalent to < and that is a total order, we know that we can use equality comparison +// on that type instead to extract some information. Furthermore, if equality comparison on that type is trivial, the +// user can't observe that we're calling it. So instead of using the user-provided total order, we use std::mismatch, +// which uses equality comparison (and is vertorized). Additionally, if the type is trivially lexicographically +// comparable, we can go one step further and use std::memcmp directly instead of calling std::mismatch. +template && !is_volatile<_Tp>::value && + __libcpp_is_trivially_equality_comparable<_Tp, _Tp>::value && + __is_identity<_Proj1>::value && __is_identity<_Proj2>::value, + int> = 0> +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool +__lexicographical_compare(_Tp* __first1, _Tp* __last1, _Tp* __first2, _Tp* __last2, _Comp&, _Proj1&, _Proj2&) { + if constexpr (__is_trivially_lexicographically_comparable_v<_Tp, _Tp>) { + auto __res = + std::__constexpr_memcmp(__first1, __first2, __element_count(std::min(__last1 - __first1, __last2 - __first2))); + if (__res == 0) + return __last1 - __first1 < __last2 - __first2; + return __res < 0; + } +# if _LIBCPP_HAS_WIDE_CHARACTERS + else if constexpr (is_same<__remove_cv_t<_Tp>, wchar_t>::value) { + auto __res = std::__constexpr_wmemcmp(__first1, __first2, std::min(__last1 - __first1, __last2 - __first2)); + if (__res == 0) + return __last1 - __first1 < __last2 - __first2; + return __res < 0; + } +# endif // _LIBCPP_HAS_WIDE_CHARACTERS + else { + auto __res = std::mismatch(__first1, __last1, __first2, __last2); + if (__res.second == __last2) + return false; + if (__res.first == __last1) + return true; + return *__res.first < *__res.second; + } +} + +#endif // _LIBCPP_STD_VER >= 14 + template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool lexicographical_compare( +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool lexicographical_compare( _InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _Compare __comp) { - return std::__lexicographical_compare<__comp_ref_type<_Compare> >(__first1, __last1, __first2, __last2, __comp); + __identity __proj; + return std::__lexicographical_compare( + std::__unwrap_iter(__first1), + std::__unwrap_iter(__last1), + std::__unwrap_iter(__first2), + std::__unwrap_iter(__last2), + __comp, + __proj, + __proj); } template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool lexicographical_compare( +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool lexicographical_compare( _InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) { return std::lexicographical_compare(__first1, __last1, __first2, __last2, __less<>()); } _LIBCPP_END_NAMESPACE_STD +_LIBCPP_POP_MACROS + #endif // _LIBCPP___ALGORITHM_LEXICOGRAPHICAL_COMPARE_H diff --git a/system/lib/libcxx/include/__algorithm/lower_bound.h b/system/lib/libcxx/include/__algorithm/lower_bound.h index c417d84835497..4fba6748e6d71 100644 --- a/system/lib/libcxx/include/__algorithm/lower_bound.h +++ b/system/lib/libcxx/include/__algorithm/lower_bound.h @@ -14,12 +14,11 @@ #include <__algorithm/iterator_operations.h> #include <__config> #include <__functional/identity.h> -#include <__functional/invoke.h> #include <__iterator/advance.h> #include <__iterator/distance.h> #include <__iterator/iterator_traits.h> +#include <__type_traits/invoke.h> #include <__type_traits/is_callable.h> -#include <__type_traits/remove_reference.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -28,7 +27,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Iter __lower_bound_bisecting( +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Iter __lower_bound_bisecting( _Iter __first, const _Type& __value, typename iterator_traits<_Iter>::difference_type __len, @@ -58,7 +57,7 @@ _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Iter __lo // whereas the one-sided version will yield O(n) operations on both counts, with a \Omega(log(n)) bound on the number of // comparisons. template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator __lower_bound_onesided(_ForwardIterator __first, _Sent __last, const _Type& __value, _Comp& __comp, _Proj& __proj) { // step = 0, ensuring we can always short-circuit when distance is 1 later on if (__first == __last || !std::__invoke(__comp, std::__invoke(__proj, *__first), __value)) @@ -84,22 +83,22 @@ __lower_bound_onesided(_ForwardIterator __first, _Sent __last, const _Type& __va } template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator __lower_bound(_ForwardIterator __first, _Sent __last, const _Type& __value, _Comp& __comp, _Proj& __proj) { const auto __dist = _IterOps<_AlgPolicy>::distance(__first, __last); return std::__lower_bound_bisecting<_AlgPolicy>(__first, __value, __dist, __comp, __proj); } template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp) { - static_assert(__is_callable<_Compare, decltype(*__first), const _Tp&>::value, "The comparator has to be callable"); + static_assert(__is_callable<_Compare&, decltype(*__first), const _Tp&>::value, "The comparator has to be callable"); auto __proj = std::__identity(); return std::__lower_bound<_ClassicAlgPolicy>(__first, __last, __value, __comp, __proj); } template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) { return std::lower_bound(__first, __last, __value, __less<>()); } diff --git a/system/lib/libcxx/include/__algorithm/make_projected.h b/system/lib/libcxx/include/__algorithm/make_projected.h index 5245e523f3df2..4a25822938751 100644 --- a/system/lib/libcxx/include/__algorithm/make_projected.h +++ b/system/lib/libcxx/include/__algorithm/make_projected.h @@ -9,15 +9,13 @@ #ifndef _LIBCPP___ALGORITHM_MAKE_PROJECTED_H #define _LIBCPP___ALGORITHM_MAKE_PROJECTED_H -#include <__concepts/same_as.h> #include <__config> #include <__functional/identity.h> #include <__functional/invoke.h> #include <__type_traits/decay.h> #include <__type_traits/enable_if.h> -#include <__type_traits/integral_constant.h> +#include <__type_traits/invoke.h> #include <__type_traits/is_member_pointer.h> -#include <__type_traits/is_same.h> #include <__utility/declval.h> #include <__utility/forward.h> @@ -36,16 +34,16 @@ struct _ProjectedPred { : __pred(__pred_arg), __proj(__proj_arg) {} template - typename __invoke_of<_Pred&, decltype(std::__invoke(std::declval<_Proj&>(), std::declval<_Tp>()))>::type - _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI - operator()(_Tp&& __v) const { + __invoke_result_t<_Pred&, decltype(std::__invoke(std::declval<_Proj&>(), std::declval<_Tp>()))> _LIBCPP_CONSTEXPR + _LIBCPP_HIDE_FROM_ABI + operator()(_Tp&& __v) const { return std::__invoke(__pred, std::__invoke(__proj, std::forward<_Tp>(__v))); } template - typename __invoke_of<_Pred&, - decltype(std::__invoke(std::declval<_Proj&>(), std::declval<_T1>())), - decltype(std::__invoke(std::declval<_Proj&>(), std::declval<_T2>()))>::type _LIBCPP_CONSTEXPR + __invoke_result_t<_Pred&, + decltype(std::__invoke(std::declval<_Proj&>(), std::declval<_T1>())), + decltype(std::__invoke(std::declval<_Proj&>(), std::declval<_T2>()))> _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI operator()(_T1&& __lhs, _T2&& __rhs) const { return std::__invoke( diff --git a/system/lib/libcxx/include/__algorithm/max.h b/system/lib/libcxx/include/__algorithm/max.h index d4c99f6f36436..1673e6be91238 100644 --- a/system/lib/libcxx/include/__algorithm/max.h +++ b/system/lib/libcxx/include/__algorithm/max.h @@ -25,13 +25,13 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Tp& +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Tp& max(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b, _Compare __comp) { return __comp(__a, __b) ? __b : __a; } template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Tp& +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Tp& max(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b) { return std::max(__a, __b, __less<>()); } @@ -39,13 +39,13 @@ max(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b) #ifndef _LIBCPP_CXX03_LANG template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp max(initializer_list<_Tp> __t, _Compare __comp) { return *std::__max_element<__comp_ref_type<_Compare> >(__t.begin(), __t.end(), __comp); } template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp max(initializer_list<_Tp> __t) { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp max(initializer_list<_Tp> __t) { return *std::max_element(__t.begin(), __t.end(), __less<>()); } diff --git a/system/lib/libcxx/include/__algorithm/max_element.h b/system/lib/libcxx/include/__algorithm/max_element.h index c036726cbccd8..929f337fc10ad 100644 --- a/system/lib/libcxx/include/__algorithm/max_element.h +++ b/system/lib/libcxx/include/__algorithm/max_element.h @@ -13,6 +13,7 @@ #include <__algorithm/comp_ref_type.h> #include <__config> #include <__iterator/iterator_traits.h> +#include <__type_traits/is_callable.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -35,13 +36,15 @@ __max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp } template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) { + static_assert( + __is_callable<_Compare&, decltype(*__first), decltype(*__first)>::value, "The comparator has to be callable"); return std::__max_element<__comp_ref_type<_Compare> >(__first, __last, __comp); } template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator max_element(_ForwardIterator __first, _ForwardIterator __last) { return std::max_element(__first, __last, __less<>()); } diff --git a/system/lib/libcxx/include/__algorithm/merge.h b/system/lib/libcxx/include/__algorithm/merge.h index bad663c4b9f10..ae859b7b63ff6 100644 --- a/system/lib/libcxx/include/__algorithm/merge.h +++ b/system/lib/libcxx/include/__algorithm/merge.h @@ -13,7 +13,6 @@ #include <__algorithm/comp_ref_type.h> #include <__algorithm/copy.h> #include <__config> -#include <__iterator/iterator_traits.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/system/lib/libcxx/include/__algorithm/min.h b/system/lib/libcxx/include/__algorithm/min.h index 1bafad8a461eb..660e0b204e19a 100644 --- a/system/lib/libcxx/include/__algorithm/min.h +++ b/system/lib/libcxx/include/__algorithm/min.h @@ -25,13 +25,13 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Tp& +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Tp& min(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b, _Compare __comp) { return __comp(__b, __a) ? __b : __a; } template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Tp& +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Tp& min(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b) { return std::min(__a, __b, __less<>()); } @@ -39,13 +39,13 @@ min(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b) #ifndef _LIBCPP_CXX03_LANG template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp min(initializer_list<_Tp> __t, _Compare __comp) { return *std::__min_element<__comp_ref_type<_Compare> >(__t.begin(), __t.end(), __comp); } template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp min(initializer_list<_Tp> __t) { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp min(initializer_list<_Tp> __t) { return *std::min_element(__t.begin(), __t.end(), __less<>()); } diff --git a/system/lib/libcxx/include/__algorithm/min_element.h b/system/lib/libcxx/include/__algorithm/min_element.h index 65f3594d630ce..db996365bf1de 100644 --- a/system/lib/libcxx/include/__algorithm/min_element.h +++ b/system/lib/libcxx/include/__algorithm/min_element.h @@ -13,8 +13,8 @@ #include <__algorithm/comp_ref_type.h> #include <__config> #include <__functional/identity.h> -#include <__functional/invoke.h> #include <__iterator/iterator_traits.h> +#include <__type_traits/invoke.h> #include <__type_traits/is_callable.h> #include <__utility/move.h> @@ -48,18 +48,18 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iter __min_element(_Iter __ } template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) { static_assert( __has_forward_iterator_category<_ForwardIterator>::value, "std::min_element requires a ForwardIterator"); static_assert( - __is_callable<_Compare, decltype(*__first), decltype(*__first)>::value, "The comparator has to be callable"); + __is_callable<_Compare&, decltype(*__first), decltype(*__first)>::value, "The comparator has to be callable"); return std::__min_element<__comp_ref_type<_Compare> >(std::move(__first), std::move(__last), __comp); } template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator min_element(_ForwardIterator __first, _ForwardIterator __last) { return std::min_element(__first, __last, __less<>()); } diff --git a/system/lib/libcxx/include/__algorithm/minmax.h b/system/lib/libcxx/include/__algorithm/minmax.h index 9feda2b4c0da9..de0bec0ef72fc 100644 --- a/system/lib/libcxx/include/__algorithm/minmax.h +++ b/system/lib/libcxx/include/__algorithm/minmax.h @@ -24,13 +24,13 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair minmax(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b, _Compare __comp) { return __comp(__b, __a) ? pair(__b, __a) : pair(__a, __b); } template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair minmax(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b) { return std::minmax(__a, __b, __less<>()); } @@ -38,16 +38,16 @@ minmax(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __ #ifndef _LIBCPP_CXX03_LANG template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Tp, _Tp> +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Tp, _Tp> minmax(initializer_list<_Tp> __t, _Compare __comp) { - static_assert(__is_callable<_Compare, _Tp, _Tp>::value, "The comparator has to be callable"); + static_assert(__is_callable<_Compare&, _Tp, _Tp>::value, "The comparator has to be callable"); __identity __proj; auto __ret = std::__minmax_element_impl(__t.begin(), __t.end(), __comp, __proj); return pair<_Tp, _Tp>(*__ret.first, *__ret.second); } template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Tp, _Tp> +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Tp, _Tp> minmax(initializer_list<_Tp> __t) { return std::minmax(__t, __less<>()); } diff --git a/system/lib/libcxx/include/__algorithm/minmax_element.h b/system/lib/libcxx/include/__algorithm/minmax_element.h index 43cb23347c346..dc0c3a818cd57 100644 --- a/system/lib/libcxx/include/__algorithm/minmax_element.h +++ b/system/lib/libcxx/include/__algorithm/minmax_element.h @@ -12,8 +12,8 @@ #include <__algorithm/comp.h> #include <__config> #include <__functional/identity.h> -#include <__functional/invoke.h> #include <__iterator/iterator_traits.h> +#include <__type_traits/invoke.h> #include <__type_traits/is_callable.h> #include <__utility/pair.h> @@ -79,18 +79,18 @@ __minmax_element_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) } template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_ForwardIterator, _ForwardIterator> +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_ForwardIterator, _ForwardIterator> minmax_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) { static_assert( __has_forward_iterator_category<_ForwardIterator>::value, "std::minmax_element requires a ForwardIterator"); static_assert( - __is_callable<_Compare, decltype(*__first), decltype(*__first)>::value, "The comparator has to be callable"); + __is_callable<_Compare&, decltype(*__first), decltype(*__first)>::value, "The comparator has to be callable"); auto __proj = __identity(); return std::__minmax_element_impl(__first, __last, __comp, __proj); } template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_ForwardIterator, _ForwardIterator> +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_ForwardIterator, _ForwardIterator> minmax_element(_ForwardIterator __first, _ForwardIterator __last) { return std::minmax_element(__first, __last, __less<>()); } diff --git a/system/lib/libcxx/include/__algorithm/mismatch.h b/system/lib/libcxx/include/__algorithm/mismatch.h index 632bec02406a4..a6836792c0581 100644 --- a/system/lib/libcxx/include/__algorithm/mismatch.h +++ b/system/lib/libcxx/include/__algorithm/mismatch.h @@ -15,17 +15,18 @@ #include <__algorithm/simd_utils.h> #include <__algorithm/unwrap_iter.h> #include <__config> +#include <__cstddef/size_t.h> #include <__functional/identity.h> #include <__iterator/aliasing_iterator.h> +#include <__iterator/iterator_traits.h> #include <__type_traits/desugars_to.h> +#include <__type_traits/enable_if.h> #include <__type_traits/invoke.h> #include <__type_traits/is_constant_evaluated.h> #include <__type_traits/is_equality_comparable.h> #include <__type_traits/is_integral.h> #include <__utility/move.h> #include <__utility/pair.h> -#include <__utility/unreachable.h> -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -37,7 +38,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Iter1, _Iter2> +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Iter1, _Iter2> __mismatch_loop(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Pred& __pred, _Proj1& __proj1, _Proj2& __proj2) { while (__first1 != __last1) { if (!std::__invoke(__pred, std::__invoke(__proj1, *__first1), std::__invoke(__proj2, *__first2))) @@ -49,7 +50,7 @@ __mismatch_loop(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Pred& __pred, } template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Iter1, _Iter2> +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Iter1, _Iter2> __mismatch(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Pred& __pred, _Proj1& __proj1, _Proj2& __proj2) { return std::__mismatch_loop(__first1, __last1, __first2, __pred, __proj1, __proj2); } @@ -57,7 +58,7 @@ __mismatch(_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Pred& __pred, _Pro #if _LIBCPP_VECTORIZE_ALGORITHMS template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Iter, _Iter> +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Iter, _Iter> __mismatch_vectorized(_Iter __first1, _Iter __last1, _Iter __first2) { using __value_type = __iter_value_type<_Iter>; constexpr size_t __unroll_count = 4; @@ -124,7 +125,7 @@ template ::value && __desugars_to_v<__equal_tag, _Pred, _Tp, _Tp> && __is_identity<_Proj1>::value && __is_identity<_Proj2>::value, int> = 0> -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Tp*, _Tp*> +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Tp*, _Tp*> __mismatch(_Tp* __first1, _Tp* __last1, _Tp* __first2, _Pred&, _Proj1&, _Proj2&) { return std::__mismatch_vectorized(__first1, __last1, __first2); } @@ -137,7 +138,7 @@ template ::value && __is_identity<_Proj2>::value && __can_map_to_integer_v<_Tp> && __libcpp_is_trivially_equality_comparable<_Tp, _Tp>::value, int> = 0> -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Tp*, _Tp*> +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Tp*, _Tp*> __mismatch(_Tp* __first1, _Tp* __last1, _Tp* __first2, _Pred& __pred, _Proj1& __proj1, _Proj2& __proj2) { if (__libcpp_is_constant_evaluated()) { return std::__mismatch_loop(__first1, __last1, __first2, __pred, __proj1, __proj2); @@ -150,7 +151,7 @@ __mismatch(_Tp* __first1, _Tp* __last1, _Tp* __first2, _Pred& __pred, _Proj1& __ #endif // _LIBCPP_VECTORIZE_ALGORITHMS template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2> +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2> mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _BinaryPredicate __pred) { __identity __proj; auto __res = std::__mismatch( @@ -159,14 +160,14 @@ mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __fi } template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2> +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2> mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2) { return std::mismatch(__first1, __last1, __first2, __equal_to()); } #if _LIBCPP_STD_VER >= 14 template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Iter1, _Iter2> __mismatch( +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Iter1, _Iter2> __mismatch( _Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2, _Pred& __pred, _Proj1& __proj1, _Proj2& __proj2) { while (__first1 != __last1 && __first2 != __last2) { if (!std::__invoke(__pred, std::__invoke(__proj1, *__first1), std::__invoke(__proj2, *__first2))) @@ -178,14 +179,14 @@ _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Iter } template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Tp*, _Tp*> +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Tp*, _Tp*> __mismatch(_Tp* __first1, _Tp* __last1, _Tp* __first2, _Tp* __last2, _Pred& __pred, _Proj1& __proj1, _Proj2& __proj2) { auto __len = std::min(__last1 - __first1, __last2 - __first2); return std::__mismatch(__first1, __first1 + __len, __first2, __pred, __proj1, __proj2); } template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2> +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2> mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, @@ -204,7 +205,7 @@ mismatch(_InputIterator1 __first1, } template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2> +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_InputIterator1, _InputIterator2> mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) { return std::mismatch(__first1, __last1, __first2, __last2, __equal_to()); } diff --git a/system/lib/libcxx/include/__algorithm/move.h b/system/lib/libcxx/include/__algorithm/move.h index 1716d43e2a613..6f3b0eb5d2927 100644 --- a/system/lib/libcxx/include/__algorithm/move.h +++ b/system/lib/libcxx/include/__algorithm/move.h @@ -14,8 +14,10 @@ #include <__algorithm/iterator_operations.h> #include <__algorithm/min.h> #include <__config> +#include <__iterator/iterator_traits.h> #include <__iterator/segmented_iterator.h> #include <__type_traits/common_type.h> +#include <__type_traits/enable_if.h> #include <__type_traits/is_constructible.h> #include <__utility/move.h> #include <__utility/pair.h> @@ -48,7 +50,7 @@ struct __move_impl { template struct _MoveSegment { - using _Traits = __segmented_iterator_traits<_InIter>; + using _Traits _LIBCPP_NODEBUG = __segmented_iterator_traits<_InIter>; _OutIter& __result_; diff --git a/system/lib/libcxx/include/__algorithm/move_backward.h b/system/lib/libcxx/include/__algorithm/move_backward.h index 4beb7bdbaac0d..24a8d9b24527a 100644 --- a/system/lib/libcxx/include/__algorithm/move_backward.h +++ b/system/lib/libcxx/include/__algorithm/move_backward.h @@ -13,8 +13,10 @@ #include <__algorithm/iterator_operations.h> #include <__algorithm/min.h> #include <__config> +#include <__iterator/iterator_traits.h> #include <__iterator/segmented_iterator.h> #include <__type_traits/common_type.h> +#include <__type_traits/enable_if.h> #include <__type_traits/is_constructible.h> #include <__utility/move.h> #include <__utility/pair.h> diff --git a/system/lib/libcxx/include/__algorithm/none_of.h b/system/lib/libcxx/include/__algorithm/none_of.h index 50841ba17cc63..e6bd197622292 100644 --- a/system/lib/libcxx/include/__algorithm/none_of.h +++ b/system/lib/libcxx/include/__algorithm/none_of.h @@ -19,7 +19,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool none_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) { for (; __first != __last; ++__first) if (__pred(*__first)) diff --git a/system/lib/libcxx/include/__algorithm/partial_sort_copy.h b/system/lib/libcxx/include/__algorithm/partial_sort_copy.h index ef7c9d34d9498..172f53b290d54 100644 --- a/system/lib/libcxx/include/__algorithm/partial_sort_copy.h +++ b/system/lib/libcxx/include/__algorithm/partial_sort_copy.h @@ -18,8 +18,8 @@ #include <__algorithm/sort_heap.h> #include <__config> #include <__functional/identity.h> -#include <__functional/invoke.h> #include <__iterator/iterator_traits.h> +#include <__type_traits/invoke.h> #include <__type_traits/is_callable.h> #include <__utility/move.h> #include <__utility/pair.h> @@ -76,8 +76,8 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator _RandomAccessIterator __result_first, _RandomAccessIterator __result_last, _Compare __comp) { - static_assert( - __is_callable<_Compare, decltype(*__first), decltype(*__result_first)>::value, "Comparator has to be callable"); + static_assert(__is_callable<_Compare&, decltype(*__first), decltype(*__result_first)>::value, + "The comparator has to be callable"); auto __result = std::__partial_sort_copy<_ClassicAlgPolicy>( __first, diff --git a/system/lib/libcxx/include/__algorithm/partition.h b/system/lib/libcxx/include/__algorithm/partition.h index 824e49b9ec214..669aac3b27555 100644 --- a/system/lib/libcxx/include/__algorithm/partition.h +++ b/system/lib/libcxx/include/__algorithm/partition.h @@ -12,6 +12,7 @@ #include <__algorithm/iterator_operations.h> #include <__config> #include <__iterator/iterator_traits.h> +#include <__type_traits/remove_cvref.h> #include <__utility/move.h> #include <__utility/pair.h> @@ -29,7 +30,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_ForwardIterator, _Forw __partition_impl(_ForwardIterator __first, _Sentinel __last, _Predicate __pred, forward_iterator_tag) { while (true) { if (__first == __last) - return std::make_pair(std::move(__first), std::move(__first)); + return std::make_pair(__first, __first); if (!__pred(*__first)) break; ++__first; diff --git a/system/lib/libcxx/include/__algorithm/pstl.h b/system/lib/libcxx/include/__algorithm/pstl.h index 0bb052b3f97c7..aa7b49de933c3 100644 --- a/system/lib/libcxx/include/__algorithm/pstl.h +++ b/system/lib/libcxx/include/__algorithm/pstl.h @@ -18,7 +18,7 @@ _LIBCPP_PUSH_MACROS #include <__undef_macros> -#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17 +#if _LIBCPP_HAS_EXPERIMENTAL_PSTL && _LIBCPP_STD_VER >= 17 # include <__functional/operations.h> # include <__iterator/cpp17_iterator_concepts.h> @@ -352,7 +352,7 @@ template , enable_if_t, int> = 0> -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI bool +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI bool is_partitioned(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) { _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator, "is_partitioned requires ForwardIterators"); using _Implementation = __pstl::__dispatch<__pstl::__is_partitioned, __pstl::__current_configuration, _RawPolicy>; @@ -656,7 +656,7 @@ _LIBCPP_HIDE_FROM_ABI _ForwardOutIterator transform( _LIBCPP_END_NAMESPACE_STD -#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17 +#endif // _LIBCPP_HAS_EXPERIMENTAL_PSTL && _LIBCPP_STD_VER >= 17 _LIBCPP_POP_MACROS diff --git a/system/lib/libcxx/include/__algorithm/radix_sort.h b/system/lib/libcxx/include/__algorithm/radix_sort.h new file mode 100644 index 0000000000000..de6927995e74c --- /dev/null +++ b/system/lib/libcxx/include/__algorithm/radix_sort.h @@ -0,0 +1,332 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___ALGORITHM_RADIX_SORT_H +#define _LIBCPP___ALGORITHM_RADIX_SORT_H + +// This is an implementation of classic LSD radix sort algorithm, running in linear time and using `O(max(N, M))` +// additional memory, where `N` is size of an input range, `M` - maximum value of +// a radix of the sorted integer type. Type of the radix and its maximum value are determined at compile time +// based on type returned by function `__radix`. The default radix is uint8. + +// The algorithm is equivalent to several consecutive calls of counting sort for each +// radix of the sorted numbers from low to high byte. +// The algorithm uses a temporary buffer of size equal to size of the input range. Each `i`-th pass +// of the algorithm sorts values by `i`-th radix and moves values to the temporary buffer (for each even `i`, counted +// from zero), or moves them back to the initial range (for each odd `i`). If there is only one radix in sorted integers +// (e.g. int8), the sorted values are placed to the buffer, and then moved back to the initial range. + +// The implementation also has several optimizations: +// - the counters for the counting sort are calculated in one pass for all radices; +// - if all values of a radix are the same, we do not sort that radix, and just move items to the buffer; +// - if two consecutive radices satisfies condition above, we do nothing for these two radices. + +#include <__algorithm/for_each.h> +#include <__algorithm/move.h> +#include <__bit/bit_log2.h> +#include <__bit/countl.h> +#include <__config> +#include <__functional/identity.h> +#include <__iterator/distance.h> +#include <__iterator/iterator_traits.h> +#include <__iterator/move_iterator.h> +#include <__iterator/next.h> +#include <__iterator/reverse_iterator.h> +#include <__numeric/partial_sum.h> +#include <__type_traits/decay.h> +#include <__type_traits/enable_if.h> +#include <__type_traits/invoke.h> +#include <__type_traits/is_assignable.h> +#include <__type_traits/is_integral.h> +#include <__type_traits/is_unsigned.h> +#include <__type_traits/make_unsigned.h> +#include <__utility/forward.h> +#include <__utility/integer_sequence.h> +#include <__utility/move.h> +#include <__utility/pair.h> +#include +#include +#include +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER >= 14 + +template +_LIBCPP_HIDE_FROM_ABI pair<_OutputIterator, __iter_value_type<_InputIterator>> +__partial_sum_max(_InputIterator __first, _InputIterator __last, _OutputIterator __result) { + if (__first == __last) + return {__result, 0}; + + auto __max = *__first; + __iter_value_type<_InputIterator> __sum = *__first; + *__result = __sum; + + while (++__first != __last) { + if (__max < *__first) { + __max = *__first; + } + __sum = std::move(__sum) + *__first; + *++__result = __sum; + } + return {++__result, __max}; +} + +template +struct __radix_sort_traits { + using __image_type _LIBCPP_NODEBUG = decay_t<__invoke_result_t<_Map, _Value>>; + static_assert(is_unsigned<__image_type>::value); + + using __radix_type _LIBCPP_NODEBUG = decay_t<__invoke_result_t<_Radix, __image_type>>; + static_assert(is_integral<__radix_type>::value); + + static constexpr auto __radix_value_range = numeric_limits<__radix_type>::max() + 1; + static constexpr auto __radix_size = std::__bit_log2(__radix_value_range); + static constexpr auto __radix_count = sizeof(__image_type) * CHAR_BIT / __radix_size; +}; + +template +struct __counting_sort_traits { + using __image_type _LIBCPP_NODEBUG = decay_t<__invoke_result_t<_Map, _Value>>; + static_assert(is_unsigned<__image_type>::value); + + static constexpr const auto __value_range = numeric_limits<__image_type>::max() + 1; + static constexpr auto __radix_size = std::__bit_log2(__value_range); +}; + +template +_LIBCPP_HIDE_FROM_ABI auto __nth_radix(size_t __radix_number, _Radix __radix, _Integer __n) { + static_assert(is_unsigned<_Integer>::value); + using __traits = __counting_sort_traits<_Integer, _Radix>; + + return __radix(static_cast<_Integer>(__n >> __traits::__radix_size * __radix_number)); +} + +template +_LIBCPP_HIDE_FROM_ABI void +__collect(_ForwardIterator __first, _ForwardIterator __last, _Map __map, _RandomAccessIterator __counters) { + using __value_type = __iter_value_type<_ForwardIterator>; + using __traits = __counting_sort_traits<__value_type, _Map>; + + std::for_each(__first, __last, [&__counters, &__map](const auto& __preimage) { ++__counters[__map(__preimage)]; }); + + const auto __counters_end = __counters + __traits::__value_range; + std::partial_sum(__counters, __counters_end, __counters); +} + +template +_LIBCPP_HIDE_FROM_ABI void +__dispose(_ForwardIterator __first, + _ForwardIterator __last, + _RandomAccessIterator1 __result, + _Map __map, + _RandomAccessIterator2 __counters) { + std::for_each(__first, __last, [&__result, &__counters, &__map](auto&& __preimage) { + auto __index = __counters[__map(__preimage)]++; + __result[__index] = std::move(__preimage); + }); +} + +template +_LIBCPP_HIDE_FROM_ABI bool __collect_impl( + _ForwardIterator __first, + _ForwardIterator __last, + _Map __map, + _Radix __radix, + _RandomAccessIterator1 __counters, + _RandomAccessIterator2 __maximums, + index_sequence<_Radices...>) { + using __value_type = __iter_value_type<_ForwardIterator>; + constexpr auto __radix_value_range = __radix_sort_traits<__value_type, _Map, _Radix>::__radix_value_range; + + auto __previous = numeric_limits<__invoke_result_t<_Map, __value_type>>::min(); + auto __is_sorted = true; + std::for_each(__first, __last, [&__counters, &__map, &__radix, &__previous, &__is_sorted](const auto& __value) { + auto __current = __map(__value); + __is_sorted &= (__current >= __previous); + __previous = __current; + + (++__counters[_Radices][std::__nth_radix(_Radices, __radix, __current)], ...); + }); + + ((__maximums[_Radices] = + std::__partial_sum_max(__counters[_Radices], __counters[_Radices] + __radix_value_range, __counters[_Radices]) + .second), + ...); + + return __is_sorted; +} + +template +_LIBCPP_HIDE_FROM_ABI bool +__collect(_ForwardIterator __first, + _ForwardIterator __last, + _Map __map, + _Radix __radix, + _RandomAccessIterator1 __counters, + _RandomAccessIterator2 __maximums) { + using __value_type = __iter_value_type<_ForwardIterator>; + constexpr auto __radix_count = __radix_sort_traits<__value_type, _Map, _Radix>::__radix_count; + return std::__collect_impl( + __first, __last, __map, __radix, __counters, __maximums, make_index_sequence<__radix_count>()); +} + +template +_LIBCPP_HIDE_FROM_ABI void __dispose_backward( + _BidirectionalIterator __first, + _BidirectionalIterator __last, + _RandomAccessIterator1 __result, + _Map __map, + _RandomAccessIterator2 __counters) { + std::for_each(std::make_reverse_iterator(__last), + std::make_reverse_iterator(__first), + [&__result, &__counters, &__map](auto&& __preimage) { + auto __index = --__counters[__map(__preimage)]; + __result[__index] = std::move(__preimage); + }); +} + +template +_LIBCPP_HIDE_FROM_ABI _RandomAccessIterator +__counting_sort_impl(_ForwardIterator __first, _ForwardIterator __last, _RandomAccessIterator __result, _Map __map) { + using __value_type = __iter_value_type<_ForwardIterator>; + using __traits = __counting_sort_traits<__value_type, _Map>; + + __iter_diff_t<_RandomAccessIterator> __counters[__traits::__value_range + 1] = {0}; + + std::__collect(__first, __last, __map, std::next(std::begin(__counters))); + std::__dispose(__first, __last, __result, __map, std::begin(__counters)); + + return __result + __counters[__traits::__value_range]; +} + +template , _Map, _Radix>::__radix_count == 1, + int> = 0> +_LIBCPP_HIDE_FROM_ABI void __radix_sort_impl( + _RandomAccessIterator1 __first, + _RandomAccessIterator1 __last, + _RandomAccessIterator2 __buffer, + _Map __map, + _Radix __radix) { + auto __buffer_end = std::__counting_sort_impl(__first, __last, __buffer, [&__map, &__radix](const auto& __value) { + return __radix(__map(__value)); + }); + + std::move(__buffer, __buffer_end, __first); +} + +template < + class _RandomAccessIterator1, + class _RandomAccessIterator2, + class _Map, + class _Radix, + enable_if_t< __radix_sort_traits<__iter_value_type<_RandomAccessIterator1>, _Map, _Radix>::__radix_count % 2 == 0, + int> = 0 > +_LIBCPP_HIDE_FROM_ABI void __radix_sort_impl( + _RandomAccessIterator1 __first, + _RandomAccessIterator1 __last, + _RandomAccessIterator2 __buffer_begin, + _Map __map, + _Radix __radix) { + using __value_type = __iter_value_type<_RandomAccessIterator1>; + using __traits = __radix_sort_traits<__value_type, _Map, _Radix>; + + __iter_diff_t<_RandomAccessIterator1> __counters[__traits::__radix_count][__traits::__radix_value_range] = {{0}}; + __iter_diff_t<_RandomAccessIterator1> __maximums[__traits::__radix_count] = {0}; + const auto __is_sorted = std::__collect(__first, __last, __map, __radix, __counters, __maximums); + if (!__is_sorted) { + const auto __range_size = std::distance(__first, __last); + auto __buffer_end = __buffer_begin + __range_size; + for (size_t __radix_number = 0; __radix_number < __traits::__radix_count; __radix_number += 2) { + const auto __n0th_is_single = __maximums[__radix_number] == __range_size; + const auto __n1th_is_single = __maximums[__radix_number + 1] == __range_size; + + if (__n0th_is_single && __n1th_is_single) { + continue; + } + + if (__n0th_is_single) { + std::move(__first, __last, __buffer_begin); + } else { + auto __n0th = [__radix_number, &__map, &__radix](const auto& __v) { + return std::__nth_radix(__radix_number, __radix, __map(__v)); + }; + std::__dispose_backward(__first, __last, __buffer_begin, __n0th, __counters[__radix_number]); + } + + if (__n1th_is_single) { + std::move(__buffer_begin, __buffer_end, __first); + } else { + auto __n1th = [__radix_number, &__map, &__radix](const auto& __v) { + return std::__nth_radix(__radix_number + 1, __radix, __map(__v)); + }; + std::__dispose_backward(__buffer_begin, __buffer_end, __first, __n1th, __counters[__radix_number + 1]); + } + } + } +} + +_LIBCPP_HIDE_FROM_ABI constexpr auto __shift_to_unsigned(bool __b) { return __b; } + +template +_LIBCPP_HIDE_FROM_ABI constexpr auto __shift_to_unsigned(_Ip __n) { + constexpr const auto __min_value = numeric_limits<_Ip>::min(); + return static_cast >(__n ^ __min_value); +} + +struct __low_byte_fn { + template + _LIBCPP_HIDE_FROM_ABI constexpr uint8_t operator()(_Ip __integer) const { + static_assert(is_unsigned<_Ip>::value); + + return static_cast(__integer & 0xff); + } +}; + +template +_LIBCPP_HIDE_FROM_ABI void +__radix_sort(_RandomAccessIterator1 __first, + _RandomAccessIterator1 __last, + _RandomAccessIterator2 __buffer, + _Map __map, + _Radix __radix) { + auto __map_to_unsigned = [__map = std::move(__map)](const auto& __x) { return std::__shift_to_unsigned(__map(__x)); }; + std::__radix_sort_impl(__first, __last, __buffer, __map_to_unsigned, __radix); +} + +template +_LIBCPP_HIDE_FROM_ABI void +__radix_sort(_RandomAccessIterator1 __first, _RandomAccessIterator1 __last, _RandomAccessIterator2 __buffer) { + std::__radix_sort(__first, __last, __buffer, __identity{}, __low_byte_fn{}); +} + +#endif // _LIBCPP_STD_VER >= 14 + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___ALGORITHM_RADIX_SORT_H diff --git a/system/lib/libcxx/include/__algorithm/ranges_adjacent_find.h b/system/lib/libcxx/include/__algorithm/ranges_adjacent_find.h index 3c54f723310a6..731142b29e6c0 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_adjacent_find.h +++ b/system/lib/libcxx/include/__algorithm/ranges_adjacent_find.h @@ -9,9 +9,9 @@ #ifndef _LIBCPP___ALGORITHM_RANGES_ADJACENT_FIND_H #define _LIBCPP___ALGORITHM_RANGES_ADJACENT_FIND_H +#include <__algorithm/adjacent_find.h> #include <__config> #include <__functional/identity.h> -#include <__functional/invoke.h> #include <__functional/ranges_operations.h> #include <__iterator/concepts.h> #include <__iterator/projected.h> @@ -32,30 +32,14 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __adjacent_find { -struct __fn { - template - _LIBCPP_HIDE_FROM_ABI constexpr static _Iter - __adjacent_find_impl(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) { - if (__first == __last) - return __first; - - auto __i = __first; - while (++__i != __last) { - if (std::invoke(__pred, std::invoke(__proj, *__first), std::invoke(__proj, *__i))) - return __first; - __first = __i; - } - return __i; - } - +struct __adjacent_find { template _Sent, class _Proj = identity, indirect_binary_predicate, projected<_Iter, _Proj>> _Pred = ranges::equal_to> [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Iter operator()(_Iter __first, _Sent __last, _Pred __pred = {}, _Proj __proj = {}) const { - return __adjacent_find_impl(std::move(__first), std::move(__last), __pred, __proj); + return std::__adjacent_find(std::move(__first), std::move(__last), __pred, __proj); } template [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Range> operator()(_Range&& __range, _Pred __pred = {}, _Proj __proj = {}) const { - return __adjacent_find_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj); + return std::__adjacent_find(ranges::begin(__range), ranges::end(__range), __pred, __proj); } }; -} // namespace __adjacent_find inline namespace __cpo { -inline constexpr auto adjacent_find = __adjacent_find::__fn{}; +inline constexpr auto adjacent_find = __adjacent_find{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_all_of.h b/system/lib/libcxx/include/__algorithm/ranges_all_of.h index 2f603b32f32d0..c3d6dc08d3c5f 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_all_of.h +++ b/system/lib/libcxx/include/__algorithm/ranges_all_of.h @@ -9,6 +9,7 @@ #ifndef _LIBCPP___ALGORITHM_RANGES_ALL_OF_H #define _LIBCPP___ALGORITHM_RANGES_ALL_OF_H +#include <__algorithm/all_of.h> #include <__config> #include <__functional/identity.h> #include <__functional/invoke.h> @@ -30,24 +31,14 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __all_of { -struct __fn { - template - _LIBCPP_HIDE_FROM_ABI constexpr static bool __all_of_impl(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) { - for (; __first != __last; ++__first) { - if (!std::invoke(__pred, std::invoke(__proj, *__first))) - return false; - } - return true; - } - +struct __all_of { template _Sent, class _Proj = identity, indirect_unary_predicate> _Pred> [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Iter __first, _Sent __last, _Pred __pred, _Proj __proj = {}) const { - return __all_of_impl(std::move(__first), std::move(__last), __pred, __proj); + return std::__all_of(std::move(__first), std::move(__last), __pred, __proj); } template , _Proj>> _Pred> [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Range&& __range, _Pred __pred, _Proj __proj = {}) const { - return __all_of_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj); + return std::__all_of(ranges::begin(__range), ranges::end(__range), __pred, __proj); } }; -} // namespace __all_of inline namespace __cpo { -inline constexpr auto all_of = __all_of::__fn{}; +inline constexpr auto all_of = __all_of{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_any_of.h b/system/lib/libcxx/include/__algorithm/ranges_any_of.h index 205fcecc086e7..7f0fd290f87d5 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_any_of.h +++ b/system/lib/libcxx/include/__algorithm/ranges_any_of.h @@ -9,9 +9,9 @@ #ifndef _LIBCPP___ALGORITHM_RANGES_ANY_OF_H #define _LIBCPP___ALGORITHM_RANGES_ANY_OF_H +#include <__algorithm/any_of.h> #include <__config> #include <__functional/identity.h> -#include <__functional/invoke.h> #include <__iterator/concepts.h> #include <__iterator/projected.h> #include <__ranges/access.h> @@ -30,24 +30,14 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __any_of { -struct __fn { - template - _LIBCPP_HIDE_FROM_ABI constexpr static bool __any_of_impl(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) { - for (; __first != __last; ++__first) { - if (std::invoke(__pred, std::invoke(__proj, *__first))) - return true; - } - return false; - } - +struct __any_of { template _Sent, class _Proj = identity, indirect_unary_predicate> _Pred> [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Iter __first, _Sent __last, _Pred __pred = {}, _Proj __proj = {}) const { - return __any_of_impl(std::move(__first), std::move(__last), __pred, __proj); + return std::__any_of(std::move(__first), std::move(__last), __pred, __proj); } template , _Proj>> _Pred> [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Range&& __range, _Pred __pred, _Proj __proj = {}) const { - return __any_of_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj); + return std::__any_of(ranges::begin(__range), ranges::end(__range), __pred, __proj); } }; -} // namespace __any_of inline namespace __cpo { -inline constexpr auto any_of = __any_of::__fn{}; +inline constexpr auto any_of = __any_of{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_binary_search.h b/system/lib/libcxx/include/__algorithm/ranges_binary_search.h index 1ef2bd62b5995..47bd0997334e8 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_binary_search.h +++ b/system/lib/libcxx/include/__algorithm/ranges_binary_search.h @@ -32,8 +32,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __binary_search { -struct __fn { +struct __binary_search { template _Sent, class _Type, @@ -57,10 +56,9 @@ struct __fn { return __ret != __last && !std::invoke(__comp, __value, std::invoke(__proj, *__ret)); } }; -} // namespace __binary_search inline namespace __cpo { -inline constexpr auto binary_search = __binary_search::__fn{}; +inline constexpr auto binary_search = __binary_search{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_clamp.h b/system/lib/libcxx/include/__algorithm/ranges_clamp.h index e6181ef9435e0..4bb3e46e73bd6 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_clamp.h +++ b/system/lib/libcxx/include/__algorithm/ranges_clamp.h @@ -30,8 +30,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __clamp { -struct __fn { +struct __clamp { template > _Comp = ranges::less> @@ -50,10 +49,9 @@ struct __fn { return __value; } }; -} // namespace __clamp inline namespace __cpo { -inline constexpr auto clamp = __clamp::__fn{}; +inline constexpr auto clamp = __clamp{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_contains.h b/system/lib/libcxx/include/__algorithm/ranges_contains.h index 4836c3baed173..88de215297e5b 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_contains.h +++ b/system/lib/libcxx/include/__algorithm/ranges_contains.h @@ -33,8 +33,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __contains { -struct __fn { +struct __contains { template _Sent, class _Type, class _Proj = identity> requires indirect_binary_predicate, const _Type*> [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool static @@ -50,10 +49,9 @@ struct __fn { ranges::end(__range); } }; -} // namespace __contains inline namespace __cpo { -inline constexpr auto contains = __contains::__fn{}; +inline constexpr auto contains = __contains{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_contains_subrange.h b/system/lib/libcxx/include/__algorithm/ranges_contains_subrange.h index 4398c457fd054..e8740d69dbef2 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_contains_subrange.h +++ b/system/lib/libcxx/include/__algorithm/ranges_contains_subrange.h @@ -35,8 +35,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __contains_subrange { -struct __fn { +struct __contains_subrange { template _Sent1, forward_iterator _Iter2, @@ -81,10 +80,9 @@ struct __fn { return __ret.empty() == false; } }; -} // namespace __contains_subrange inline namespace __cpo { -inline constexpr auto contains_subrange = __contains_subrange::__fn{}; +inline constexpr auto contains_subrange = __contains_subrange{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_copy.h b/system/lib/libcxx/include/__algorithm/ranges_copy.h index e1d6d32f05f7e..a69af9b2bffc3 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_copy.h +++ b/system/lib/libcxx/include/__algorithm/ranges_copy.h @@ -11,7 +11,6 @@ #include <__algorithm/copy.h> #include <__algorithm/in_out_result.h> -#include <__algorithm/iterator_operations.h> #include <__config> #include <__functional/identity.h> #include <__iterator/concepts.h> @@ -37,13 +36,12 @@ namespace ranges { template using copy_result = in_out_result<_InIter, _OutIter>; -namespace __copy { -struct __fn { +struct __copy { template _Sent, weakly_incrementable _OutIter> requires indirectly_copyable<_InIter, _OutIter> _LIBCPP_HIDE_FROM_ABI constexpr copy_result<_InIter, _OutIter> operator()(_InIter __first, _Sent __last, _OutIter __result) const { - auto __ret = std::__copy<_RangeAlgPolicy>(std::move(__first), std::move(__last), std::move(__result)); + auto __ret = std::__copy(std::move(__first), std::move(__last), std::move(__result)); return {std::move(__ret.first), std::move(__ret.second)}; } @@ -51,14 +49,13 @@ struct __fn { requires indirectly_copyable, _OutIter> _LIBCPP_HIDE_FROM_ABI constexpr copy_result, _OutIter> operator()(_Range&& __r, _OutIter __result) const { - auto __ret = std::__copy<_RangeAlgPolicy>(ranges::begin(__r), ranges::end(__r), std::move(__result)); + auto __ret = std::__copy(ranges::begin(__r), ranges::end(__r), std::move(__result)); return {std::move(__ret.first), std::move(__ret.second)}; } }; -} // namespace __copy inline namespace __cpo { -inline constexpr auto copy = __copy::__fn{}; +inline constexpr auto copy = __copy{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_copy_backward.h b/system/lib/libcxx/include/__algorithm/ranges_copy_backward.h index 93e326042503f..81d14e465f7f2 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_copy_backward.h +++ b/system/lib/libcxx/include/__algorithm/ranges_copy_backward.h @@ -35,8 +35,7 @@ namespace ranges { template using copy_backward_result = in_out_result<_Ip, _Op>; -namespace __copy_backward { -struct __fn { +struct __copy_backward { template _Sent1, bidirectional_iterator _InIter2> requires indirectly_copyable<_InIter1, _InIter2> _LIBCPP_HIDE_FROM_ABI constexpr copy_backward_result<_InIter1, _InIter2> @@ -53,10 +52,9 @@ struct __fn { return {std::move(__ret.first), std::move(__ret.second)}; } }; -} // namespace __copy_backward inline namespace __cpo { -inline constexpr auto copy_backward = __copy_backward::__fn{}; +inline constexpr auto copy_backward = __copy_backward{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_copy_if.h b/system/lib/libcxx/include/__algorithm/ranges_copy_if.h index 4b41d2154e7f8..acf74b669d481 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_copy_if.h +++ b/system/lib/libcxx/include/__algorithm/ranges_copy_if.h @@ -9,6 +9,7 @@ #ifndef _LIBCPP___ALGORITHM_RANGES_COPY_IF_H #define _LIBCPP___ALGORITHM_RANGES_COPY_IF_H +#include <__algorithm/copy_if.h> #include <__algorithm/in_out_result.h> #include <__config> #include <__functional/identity.h> @@ -36,20 +37,7 @@ namespace ranges { template using copy_if_result = in_out_result<_Ip, _Op>; -namespace __copy_if { -struct __fn { - template - _LIBCPP_HIDE_FROM_ABI static constexpr copy_if_result<_InIter, _OutIter> - __copy_if_impl(_InIter __first, _Sent __last, _OutIter __result, _Pred& __pred, _Proj& __proj) { - for (; __first != __last; ++__first) { - if (std::invoke(__pred, std::invoke(__proj, *__first))) { - *__result = *__first; - ++__result; - } - } - return {std::move(__first), std::move(__result)}; - } - +struct __copy_if { template _Sent, weakly_incrementable _OutIter, @@ -58,7 +46,8 @@ struct __fn { requires indirectly_copyable<_Iter, _OutIter> _LIBCPP_HIDE_FROM_ABI constexpr copy_if_result<_Iter, _OutIter> operator()(_Iter __first, _Sent __last, _OutIter __result, _Pred __pred, _Proj __proj = {}) const { - return __copy_if_impl(std::move(__first), std::move(__last), std::move(__result), __pred, __proj); + auto __res = std::__copy_if(std::move(__first), std::move(__last), std::move(__result), __pred, __proj); + return {std::move(__res.first), std::move(__res.second)}; } template , _OutIter> _LIBCPP_HIDE_FROM_ABI constexpr copy_if_result, _OutIter> operator()(_Range&& __r, _OutIter __result, _Pred __pred, _Proj __proj = {}) const { - return __copy_if_impl(ranges::begin(__r), ranges::end(__r), std::move(__result), __pred, __proj); + auto __res = std::__copy_if(ranges::begin(__r), ranges::end(__r), std::move(__result), __pred, __proj); + return {std::move(__res.first), std::move(__res.second)}; } }; -} // namespace __copy_if inline namespace __cpo { -inline constexpr auto copy_if = __copy_if::__fn{}; +inline constexpr auto copy_if = __copy_if{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_copy_n.h b/system/lib/libcxx/include/__algorithm/ranges_copy_n.h index 4353fa99278c8..1fbc61674e2dd 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_copy_n.h +++ b/system/lib/libcxx/include/__algorithm/ranges_copy_n.h @@ -37,8 +37,8 @@ namespace ranges { template using copy_n_result = in_out_result<_Ip, _Op>; -namespace __copy_n { -struct __fn { +// TODO: Merge this with copy_n +struct __copy_n { template _LIBCPP_HIDE_FROM_ABI constexpr static copy_n_result<_InIter, _OutIter> __go(_InIter __first, _DiffType __n, _OutIter __result) { @@ -54,7 +54,7 @@ struct __fn { template _LIBCPP_HIDE_FROM_ABI constexpr static copy_n_result<_InIter, _OutIter> __go(_InIter __first, _DiffType __n, _OutIter __result) { - auto __ret = std::__copy<_RangeAlgPolicy>(__first, __first + __n, __result); + auto __ret = std::__copy(__first, __first + __n, __result); return {__ret.first, __ret.second}; } @@ -65,10 +65,9 @@ struct __fn { return __go(std::move(__first), __n, std::move(__result)); } }; -} // namespace __copy_n inline namespace __cpo { -inline constexpr auto copy_n = __copy_n::__fn{}; +inline constexpr auto copy_n = __copy_n{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_count.h b/system/lib/libcxx/include/__algorithm/ranges_count.h index 4f35117438705..2b3969e763079 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_count.h +++ b/system/lib/libcxx/include/__algorithm/ranges_count.h @@ -34,8 +34,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __count { -struct __fn { +struct __count { template _Sent, class _Type, class _Proj = identity> requires indirect_binary_predicate, const _Type*> [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr iter_difference_t<_Iter> @@ -50,10 +49,9 @@ struct __fn { return std::__count<_RangeAlgPolicy>(ranges::begin(__r), ranges::end(__r), __value, __proj); } }; -} // namespace __count inline namespace __cpo { -inline constexpr auto count = __count::__fn{}; +inline constexpr auto count = __count{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_count_if.h b/system/lib/libcxx/include/__algorithm/ranges_count_if.h index 5f2396ff7d531..6adeb78582bf3 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_count_if.h +++ b/system/lib/libcxx/include/__algorithm/ranges_count_if.h @@ -9,9 +9,10 @@ #ifndef _LIBCPP___ALGORITHM_RANGES_COUNT_IF_H #define _LIBCPP___ALGORITHM_RANGES_COUNT_IF_H +#include <__algorithm/count_if.h> +#include <__algorithm/iterator_operations.h> #include <__config> #include <__functional/identity.h> -#include <__functional/invoke.h> #include <__functional/ranges_operations.h> #include <__iterator/concepts.h> #include <__iterator/incrementable_traits.h> @@ -33,26 +34,14 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -template -_LIBCPP_HIDE_FROM_ABI constexpr iter_difference_t<_Iter> -__count_if_impl(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) { - iter_difference_t<_Iter> __counter(0); - for (; __first != __last; ++__first) { - if (std::invoke(__pred, std::invoke(__proj, *__first))) - ++__counter; - } - return __counter; -} - -namespace __count_if { -struct __fn { +struct __count_if { template _Sent, class _Proj = identity, indirect_unary_predicate> _Predicate> [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr iter_difference_t<_Iter> operator()(_Iter __first, _Sent __last, _Predicate __pred, _Proj __proj = {}) const { - return ranges::__count_if_impl(std::move(__first), std::move(__last), __pred, __proj); + return std::__count_if<_RangeAlgPolicy>(std::move(__first), std::move(__last), __pred, __proj); } template , _Proj>> _Predicate> [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr range_difference_t<_Range> operator()(_Range&& __r, _Predicate __pred, _Proj __proj = {}) const { - return ranges::__count_if_impl(ranges::begin(__r), ranges::end(__r), __pred, __proj); + return std::__count_if<_RangeAlgPolicy>(ranges::begin(__r), ranges::end(__r), __pred, __proj); } }; -} // namespace __count_if inline namespace __cpo { -inline constexpr auto count_if = __count_if::__fn{}; +inline constexpr auto count_if = __count_if{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_ends_with.h b/system/lib/libcxx/include/__algorithm/ranges_ends_with.h index 06efdef36b7cf..3621bda389123 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_ends_with.h +++ b/system/lib/libcxx/include/__algorithm/ranges_ends_with.h @@ -22,6 +22,7 @@ #include <__iterator/reverse_iterator.h> #include <__ranges/access.h> #include <__ranges/concepts.h> +#include <__ranges/size.h> #include <__utility/move.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -36,8 +37,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __ends_with { -struct __fn { +struct __ends_with { template _LIBCPP_HIDE_FROM_ABI static constexpr bool __ends_with_fn_impl_bidirectional( _Iter1 __first1, @@ -185,10 +185,9 @@ struct __fn { } } }; -} // namespace __ends_with inline namespace __cpo { -inline constexpr auto ends_with = __ends_with::__fn{}; +inline constexpr auto ends_with = __ends_with{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_equal.h b/system/lib/libcxx/include/__algorithm/ranges_equal.h index edbd0e3641c1b..c26d13f002201 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_equal.h +++ b/system/lib/libcxx/include/__algorithm/ranges_equal.h @@ -34,8 +34,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __equal { -struct __fn { +struct __equal { template _Sent1, input_iterator _Iter2, @@ -93,10 +92,9 @@ struct __fn { return false; } }; -} // namespace __equal inline namespace __cpo { -inline constexpr auto equal = __equal::__fn{}; +inline constexpr auto equal = __equal{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_equal_range.h b/system/lib/libcxx/include/__algorithm/ranges_equal_range.h index 4a308e016b546..cc765f196648e 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_equal_range.h +++ b/system/lib/libcxx/include/__algorithm/ranges_equal_range.h @@ -38,9 +38,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __equal_range { - -struct __fn { +struct __equal_range { template _Sent, class _Tp, @@ -64,10 +62,8 @@ struct __fn { } }; -} // namespace __equal_range - inline namespace __cpo { -inline constexpr auto equal_range = __equal_range::__fn{}; +inline constexpr auto equal_range = __equal_range{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_fill.h b/system/lib/libcxx/include/__algorithm/ranges_fill.h index 7a177d85e9f07..c248009f98fe3 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_fill.h +++ b/system/lib/libcxx/include/__algorithm/ranges_fill.h @@ -28,8 +28,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __fill { -struct __fn { +struct __fill { template _Iter, sentinel_for<_Iter> _Sent> _LIBCPP_HIDE_FROM_ABI constexpr _Iter operator()(_Iter __first, _Sent __last, const _Type& __value) const { if constexpr (random_access_iterator<_Iter> && sized_sentinel_for<_Sent, _Iter>) { @@ -46,10 +45,9 @@ struct __fn { return (*this)(ranges::begin(__range), ranges::end(__range), __value); } }; -} // namespace __fill inline namespace __cpo { -inline constexpr auto fill = __fill::__fn{}; +inline constexpr auto fill = __fill{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_fill_n.h b/system/lib/libcxx/include/__algorithm/ranges_fill_n.h index a6e988c0089ce..1276f13680a9f 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_fill_n.h +++ b/system/lib/libcxx/include/__algorithm/ranges_fill_n.h @@ -9,9 +9,11 @@ #ifndef _LIBCPP___ALGORITHM_RANGES_FILL_N_H #define _LIBCPP___ALGORITHM_RANGES_FILL_N_H +#include <__algorithm/fill_n.h> #include <__config> #include <__iterator/concepts.h> #include <__iterator/incrementable_traits.h> +#include <__utility/move.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -25,22 +27,16 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __fill_n { -struct __fn { +struct __fill_n { template _Iter> _LIBCPP_HIDE_FROM_ABI constexpr _Iter operator()(_Iter __first, iter_difference_t<_Iter> __n, const _Type& __value) const { - for (; __n != 0; --__n) { - *__first = __value; - ++__first; - } - return __first; + return std::__fill_n(std::move(__first), __n, __value); } }; -} // namespace __fill_n inline namespace __cpo { -inline constexpr auto fill_n = __fill_n::__fn{}; +inline constexpr auto fill_n = __fill_n{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_find.h b/system/lib/libcxx/include/__algorithm/ranges_find.h index 6b0d5efe37ab8..1eac4cfa02a4a 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_find.h +++ b/system/lib/libcxx/include/__algorithm/ranges_find.h @@ -36,8 +36,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __find { -struct __fn { +struct __find { template _LIBCPP_HIDE_FROM_ABI static constexpr _Iter __find_unwrap(_Iter __first, _Sent __last, const _Tp& __value, _Proj& __proj) { @@ -64,10 +63,9 @@ struct __fn { return __find_unwrap(ranges::begin(__r), ranges::end(__r), __value, __proj); } }; -} // namespace __find inline namespace __cpo { -inline constexpr auto find = __find::__fn{}; +inline constexpr auto find = __find{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_find_end.h b/system/lib/libcxx/include/__algorithm/ranges_find_end.h index e49e66dd4ac04..682724a48cd5a 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_find_end.h +++ b/system/lib/libcxx/include/__algorithm/ranges_find_end.h @@ -35,8 +35,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __find_end { -struct __fn { +struct __find_end { template _Sent1, forward_iterator _Iter2, @@ -87,10 +86,9 @@ struct __fn { return {__ret.first, __ret.second}; } }; -} // namespace __find_end inline namespace __cpo { -inline constexpr auto find_end = __find_end::__fn{}; +inline constexpr auto find_end = __find_end{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_find_first_of.h b/system/lib/libcxx/include/__algorithm/ranges_find_first_of.h index d92d9686bc442..102e16dd7a55b 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_find_first_of.h +++ b/system/lib/libcxx/include/__algorithm/ranges_find_first_of.h @@ -32,8 +32,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __find_first_of { -struct __fn { +struct __find_first_of { template _LIBCPP_HIDE_FROM_ABI constexpr static _Iter1 __find_first_of_impl( _Iter1 __first1, @@ -90,10 +89,9 @@ struct __fn { __proj2); } }; -} // namespace __find_first_of inline namespace __cpo { -inline constexpr auto find_first_of = __find_first_of::__fn{}; +inline constexpr auto find_first_of = __find_first_of{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_find_if.h b/system/lib/libcxx/include/__algorithm/ranges_find_if.h index 888f9ec3cb2d5..ed6406e6186a3 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_find_if.h +++ b/system/lib/libcxx/include/__algorithm/ranges_find_if.h @@ -42,8 +42,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr _Ip __find_if_impl(_Ip __first, _Sp __last, _Pre return __first; } -namespace __find_if { -struct __fn { +struct __find_if { template _Sp, class _Proj = identity, @@ -59,10 +58,9 @@ struct __fn { return ranges::__find_if_impl(ranges::begin(__r), ranges::end(__r), __pred, __proj); } }; -} // namespace __find_if inline namespace __cpo { -inline constexpr auto find_if = __find_if::__fn{}; +inline constexpr auto find_if = __find_if{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_find_if_not.h b/system/lib/libcxx/include/__algorithm/ranges_find_if_not.h index ec19545b5a1b7..9a359b2afdab1 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_find_if_not.h +++ b/system/lib/libcxx/include/__algorithm/ranges_find_if_not.h @@ -34,8 +34,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __find_if_not { -struct __fn { +struct __find_if_not { template _Sp, class _Proj = identity, @@ -53,10 +52,9 @@ struct __fn { return ranges::__find_if_impl(ranges::begin(__r), ranges::end(__r), __pred2, __proj); } }; -} // namespace __find_if_not inline namespace __cpo { -inline constexpr auto find_if_not = __find_if_not::__fn{}; +inline constexpr auto find_if_not = __find_if_not{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_find_last.h b/system/lib/libcxx/include/__algorithm/ranges_find_last.h index 95f7e77b8ccbe..e7dae1704c2ea 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_find_last.h +++ b/system/lib/libcxx/include/__algorithm/ranges_find_last.h @@ -21,6 +21,7 @@ #include <__ranges/access.h> #include <__ranges/concepts.h> #include <__ranges/subrange.h> +#include <__utility/forward.h> #include <__utility/move.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -72,8 +73,7 @@ __find_last_impl(_Iter __first, _Sent __last, _Pred __pred, _Proj& __proj) { } } -namespace __find_last { -struct __fn { +struct __find_last { template struct __op { const _Type& __value; @@ -97,10 +97,8 @@ struct __fn { return ranges::__find_last_impl(ranges::begin(__range), ranges::end(__range), __op<_Type>{__value}, __proj); } }; -} // namespace __find_last -namespace __find_last_if { -struct __fn { +struct __find_last_if { template struct __op { _Pred& __pred; @@ -127,10 +125,8 @@ struct __fn { return ranges::__find_last_impl(ranges::begin(__range), ranges::end(__range), __op<_Pred>{__pred}, __proj); } }; -} // namespace __find_last_if -namespace __find_last_if_not { -struct __fn { +struct __find_last_if_not { template struct __op { _Pred& __pred; @@ -157,12 +153,11 @@ struct __fn { return ranges::__find_last_impl(ranges::begin(__range), ranges::end(__range), __op<_Pred>{__pred}, __proj); } }; -} // namespace __find_last_if_not inline namespace __cpo { -inline constexpr auto find_last = __find_last::__fn{}; -inline constexpr auto find_last_if = __find_last_if::__fn{}; -inline constexpr auto find_last_if_not = __find_last_if_not::__fn{}; +inline constexpr auto find_last = __find_last{}; +inline constexpr auto find_last_if = __find_last_if{}; +inline constexpr auto find_last_if_not = __find_last_if_not{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/fold.h b/system/lib/libcxx/include/__algorithm/ranges_fold.h similarity index 96% rename from system/lib/libcxx/include/__algorithm/fold.h rename to system/lib/libcxx/include/__algorithm/ranges_fold.h index 255658f523249..d2c3921398504 100644 --- a/system/lib/libcxx/include/__algorithm/fold.h +++ b/system/lib/libcxx/include/__algorithm/ranges_fold.h @@ -7,10 +7,11 @@ // //===----------------------------------------------------------------------===// -#ifndef _LIBCPP___ALGORITHM_FOLD_H -#define _LIBCPP___ALGORITHM_FOLD_H +#ifndef _LIBCPP___ALGORITHM_RANGES_FOLD_H +#define _LIBCPP___ALGORITHM_RANGES_FOLD_H #include <__concepts/assignable.h> +#include <__concepts/constructible.h> #include <__concepts/convertible_to.h> #include <__concepts/invocable.h> #include <__concepts/movable.h> @@ -125,4 +126,4 @@ _LIBCPP_END_NAMESPACE_STD _LIBCPP_POP_MACROS -#endif // _LIBCPP___ALGORITHM_FOLD_H +#endif // _LIBCPP___ALGORITHM_RANGES_FOLD_H diff --git a/system/lib/libcxx/include/__algorithm/ranges_for_each.h b/system/lib/libcxx/include/__algorithm/ranges_for_each.h index 225dc774c8764..de39bc5522753 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_for_each.h +++ b/system/lib/libcxx/include/__algorithm/ranges_for_each.h @@ -36,8 +36,7 @@ namespace ranges { template using for_each_result = in_fun_result<_Iter, _Func>; -namespace __for_each { -struct __fn { +struct __for_each { private: template _LIBCPP_HIDE_FROM_ABI constexpr static for_each_result<_Iter, _Func> @@ -65,10 +64,9 @@ struct __fn { return __for_each_impl(ranges::begin(__range), ranges::end(__range), __func, __proj); } }; -} // namespace __for_each inline namespace __cpo { -inline constexpr auto for_each = __for_each::__fn{}; +inline constexpr auto for_each = __for_each{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_for_each_n.h b/system/lib/libcxx/include/__algorithm/ranges_for_each_n.h index d1fdca34cc5a1..603cb723233c8 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_for_each_n.h +++ b/system/lib/libcxx/include/__algorithm/ranges_for_each_n.h @@ -36,8 +36,7 @@ namespace ranges { template using for_each_n_result = in_fun_result<_Iter, _Func>; -namespace __for_each_n { -struct __fn { +struct __for_each_n { template > _Func> _LIBCPP_HIDE_FROM_ABI constexpr for_each_n_result<_Iter, _Func> operator()(_Iter __first, iter_difference_t<_Iter> __count, _Func __func, _Proj __proj = {}) const { @@ -48,10 +47,9 @@ struct __fn { return {std::move(__first), std::move(__func)}; } }; -} // namespace __for_each_n inline namespace __cpo { -inline constexpr auto for_each_n = __for_each_n::__fn{}; +inline constexpr auto for_each_n = __for_each_n{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_generate.h b/system/lib/libcxx/include/__algorithm/ranges_generate.h index e6467198e6ba2..04333b358eed2 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_generate.h +++ b/system/lib/libcxx/include/__algorithm/ranges_generate.h @@ -12,12 +12,12 @@ #include <__concepts/constructible.h> #include <__concepts/invocable.h> #include <__config> -#include <__functional/invoke.h> #include <__iterator/concepts.h> #include <__iterator/iterator_traits.h> #include <__ranges/access.h> #include <__ranges/concepts.h> #include <__ranges/dangling.h> +#include <__type_traits/invoke.h> #include <__utility/move.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -32,9 +32,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __generate { - -struct __fn { +struct __generate { template _LIBCPP_HIDE_FROM_ABI constexpr static _OutIter __generate_fn_impl(_OutIter __first, _Sent __last, _Func& __gen) { for (; __first != __last; ++__first) { @@ -57,10 +55,8 @@ struct __fn { } }; -} // namespace __generate - inline namespace __cpo { -inline constexpr auto generate = __generate::__fn{}; +inline constexpr auto generate = __generate{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_generate_n.h b/system/lib/libcxx/include/__algorithm/ranges_generate_n.h index cd5fd7483ab2c..a318994d0eaf8 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_generate_n.h +++ b/system/lib/libcxx/include/__algorithm/ranges_generate_n.h @@ -13,12 +13,12 @@ #include <__concepts/invocable.h> #include <__config> #include <__functional/identity.h> -#include <__functional/invoke.h> #include <__iterator/concepts.h> #include <__iterator/incrementable_traits.h> #include <__iterator/iterator_traits.h> #include <__ranges/access.h> #include <__ranges/concepts.h> +#include <__type_traits/invoke.h> #include <__utility/move.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -33,9 +33,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __generate_n { - -struct __fn { +struct __generate_n { template requires invocable<_Func&> && indirectly_writable<_OutIter, invoke_result_t<_Func&>> _LIBCPP_HIDE_FROM_ABI constexpr _OutIter @@ -49,10 +47,8 @@ struct __fn { } }; -} // namespace __generate_n - inline namespace __cpo { -inline constexpr auto generate_n = __generate_n::__fn{}; +inline constexpr auto generate_n = __generate_n{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_includes.h b/system/lib/libcxx/include/__algorithm/ranges_includes.h index c4c3b8ed088d3..9145f3b5564ff 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_includes.h +++ b/system/lib/libcxx/include/__algorithm/ranges_includes.h @@ -35,9 +35,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __includes { - -struct __fn { +struct __includes { template _Sent1, input_iterator _Iter2, @@ -82,10 +80,8 @@ struct __fn { } }; -} // namespace __includes - inline namespace __cpo { -inline constexpr auto includes = __includes::__fn{}; +inline constexpr auto includes = __includes{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_inplace_merge.h b/system/lib/libcxx/include/__algorithm/ranges_inplace_merge.h index d94c0ad465677..5879d0e7ef0fb 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_inplace_merge.h +++ b/system/lib/libcxx/include/__algorithm/ranges_inplace_merge.h @@ -39,9 +39,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __inplace_merge { - -struct __fn { +struct __inplace_merge { template _LIBCPP_HIDE_FROM_ABI static constexpr auto __inplace_merge_impl(_Iter __first, _Iter __middle, _Sent __last, _Comp&& __comp, _Proj&& __proj) { @@ -68,10 +66,8 @@ struct __fn { } }; -} // namespace __inplace_merge - inline namespace __cpo { -inline constexpr auto inplace_merge = __inplace_merge::__fn{}; +inline constexpr auto inplace_merge = __inplace_merge{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_is_heap.h b/system/lib/libcxx/include/__algorithm/ranges_is_heap.h index 3d9e18ce1d906..b4724abfb62a5 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_is_heap.h +++ b/system/lib/libcxx/include/__algorithm/ranges_is_heap.h @@ -34,9 +34,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __is_heap { - -struct __fn { +struct __is_heap { template _LIBCPP_HIDE_FROM_ABI constexpr static bool __is_heap_fn_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) { @@ -65,10 +63,8 @@ struct __fn { } }; -} // namespace __is_heap - inline namespace __cpo { -inline constexpr auto is_heap = __is_heap::__fn{}; +inline constexpr auto is_heap = __is_heap{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_is_heap_until.h b/system/lib/libcxx/include/__algorithm/ranges_is_heap_until.h index 7a2e1fc7705b6..25f3b484faa66 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_is_heap_until.h +++ b/system/lib/libcxx/include/__algorithm/ranges_is_heap_until.h @@ -35,9 +35,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __is_heap_until { - -struct __fn { +struct __is_heap_until { template _LIBCPP_HIDE_FROM_ABI constexpr static _Iter __is_heap_until_fn_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) { @@ -65,10 +63,8 @@ struct __fn { } }; -} // namespace __is_heap_until - inline namespace __cpo { -inline constexpr auto is_heap_until = __is_heap_until::__fn{}; +inline constexpr auto is_heap_until = __is_heap_until{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_is_partitioned.h b/system/lib/libcxx/include/__algorithm/ranges_is_partitioned.h index 5be6fba46fd9e..8092abfcd1de3 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_is_partitioned.h +++ b/system/lib/libcxx/include/__algorithm/ranges_is_partitioned.h @@ -31,8 +31,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __is_partitioned { -struct __fn { +struct __is_partitioned { template _LIBCPP_HIDE_FROM_ABI constexpr static bool __is_partitioned_impl(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) { @@ -70,10 +69,9 @@ struct __fn { return __is_partitioned_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj); } }; -} // namespace __is_partitioned inline namespace __cpo { -inline constexpr auto is_partitioned = __is_partitioned::__fn{}; +inline constexpr auto is_partitioned = __is_partitioned{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_is_permutation.h b/system/lib/libcxx/include/__algorithm/ranges_is_permutation.h index 1f8d67007a573..53a431d2ba425 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_is_permutation.h +++ b/system/lib/libcxx/include/__algorithm/ranges_is_permutation.h @@ -33,8 +33,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __is_permutation { -struct __fn { +struct __is_permutation { template _LIBCPP_HIDE_FROM_ABI constexpr static bool __is_permutation_func_impl( _Iter1 __first1, @@ -91,10 +90,9 @@ struct __fn { __proj2); } }; -} // namespace __is_permutation inline namespace __cpo { -inline constexpr auto is_permutation = __is_permutation::__fn{}; +inline constexpr auto is_permutation = __is_permutation{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_is_sorted.h b/system/lib/libcxx/include/__algorithm/ranges_is_sorted.h index 5b88d422b4b09..ab0670688a0e9 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_is_sorted.h +++ b/system/lib/libcxx/include/__algorithm/ranges_is_sorted.h @@ -31,8 +31,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __is_sorted { -struct __fn { +struct __is_sorted { template _Sent, class _Proj = identity, @@ -51,10 +50,9 @@ struct __fn { return ranges::__is_sorted_until_impl(ranges::begin(__range), __last, __comp, __proj) == __last; } }; -} // namespace __is_sorted inline namespace __cpo { -inline constexpr auto is_sorted = __is_sorted::__fn{}; +inline constexpr auto is_sorted = __is_sorted{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_is_sorted_until.h b/system/lib/libcxx/include/__algorithm/ranges_is_sorted_until.h index 54de530c8b2fd..f2e51c264e4a7 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_is_sorted_until.h +++ b/system/lib/libcxx/include/__algorithm/ranges_is_sorted_until.h @@ -47,8 +47,7 @@ __is_sorted_until_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj return __i; } -namespace __is_sorted_until { -struct __fn { +struct __is_sorted_until { template _Sent, class _Proj = identity, @@ -66,10 +65,9 @@ struct __fn { return ranges::__is_sorted_until_impl(ranges::begin(__range), ranges::end(__range), __comp, __proj); } }; -} // namespace __is_sorted_until inline namespace __cpo { -inline constexpr auto is_sorted_until = __is_sorted_until::__fn{}; +inline constexpr auto is_sorted_until = __is_sorted_until{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_iterator_concept.h b/system/lib/libcxx/include/__algorithm/ranges_iterator_concept.h index 2af891d3af005..58790e95aa803 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_iterator_concept.h +++ b/system/lib/libcxx/include/__algorithm/ranges_iterator_concept.h @@ -44,7 +44,7 @@ consteval auto __get_iterator_concept() { } template -using __iterator_concept = decltype(__get_iterator_concept<_Iter>()); +using __iterator_concept _LIBCPP_NODEBUG = decltype(__get_iterator_concept<_Iter>()); } // namespace ranges _LIBCPP_END_NAMESPACE_STD diff --git a/system/lib/libcxx/include/__algorithm/ranges_lexicographical_compare.h b/system/lib/libcxx/include/__algorithm/ranges_lexicographical_compare.h index 6d82017e302a7..ec12b0cc29ace 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_lexicographical_compare.h +++ b/system/lib/libcxx/include/__algorithm/ranges_lexicographical_compare.h @@ -9,6 +9,8 @@ #ifndef _LIBCPP___ALGORITHM_RANGES_LEXICOGRAPHICAL_COMPARE_H #define _LIBCPP___ALGORITHM_RANGES_LEXICOGRAPHICAL_COMPARE_H +#include <__algorithm/lexicographical_compare.h> +#include <__algorithm/unwrap_range.h> #include <__config> #include <__functional/identity.h> #include <__functional/invoke.h> @@ -31,10 +33,9 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __lexicographical_compare { -struct __fn { +struct __lexicographical_compare { template - _LIBCPP_HIDE_FROM_ABI constexpr static bool __lexicographical_compare_impl( + static _LIBCPP_HIDE_FROM_ABI constexpr bool __lexicographical_compare_unwrap( _Iter1 __first1, _Sent1 __last1, _Iter2 __first2, @@ -42,15 +43,16 @@ struct __fn { _Comp& __comp, _Proj1& __proj1, _Proj2& __proj2) { - while (__first2 != __last2) { - if (__first1 == __last1 || std::invoke(__comp, std::invoke(__proj1, *__first1), std::invoke(__proj2, *__first2))) - return true; - if (std::invoke(__comp, std::invoke(__proj2, *__first2), std::invoke(__proj1, *__first1))) - return false; - ++__first1; - ++__first2; - } - return false; + auto [__first1_un, __last1_un] = std::__unwrap_range(std::move(__first1), std::move(__last1)); + auto [__first2_un, __last2_un] = std::__unwrap_range(std::move(__first2), std::move(__last2)); + return std::__lexicographical_compare( + std::move(__first1_un), + std::move(__last1_un), + std::move(__first2_un), + std::move(__last2_un), + __comp, + __proj1, + __proj2); } template [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()( _Range1&& __range1, _Range2&& __range2, _Comp __comp = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const { - return __lexicographical_compare_impl( + return __lexicographical_compare_unwrap( ranges::begin(__range1), ranges::end(__range1), ranges::begin(__range2), @@ -90,10 +92,9 @@ struct __fn { __proj2); } }; -} // namespace __lexicographical_compare inline namespace __cpo { -inline constexpr auto lexicographical_compare = __lexicographical_compare::__fn{}; +inline constexpr auto lexicographical_compare = __lexicographical_compare{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_lower_bound.h b/system/lib/libcxx/include/__algorithm/ranges_lower_bound.h index 0651147e04249..d1b332849b8b6 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_lower_bound.h +++ b/system/lib/libcxx/include/__algorithm/ranges_lower_bound.h @@ -36,8 +36,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __lower_bound { -struct __fn { +struct __lower_bound { template _Sent, class _Type, @@ -57,10 +56,9 @@ struct __fn { return std::__lower_bound<_RangeAlgPolicy>(ranges::begin(__r), ranges::end(__r), __value, __comp, __proj); } }; -} // namespace __lower_bound inline namespace __cpo { -inline constexpr auto lower_bound = __lower_bound::__fn{}; +inline constexpr auto lower_bound = __lower_bound{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_make_heap.h b/system/lib/libcxx/include/__algorithm/ranges_make_heap.h index fe9c024fbf8a8..97148f77b4181 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_make_heap.h +++ b/system/lib/libcxx/include/__algorithm/ranges_make_heap.h @@ -40,9 +40,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __make_heap { - -struct __fn { +struct __make_heap { template _LIBCPP_HIDE_FROM_ABI constexpr static _Iter __make_heap_fn_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) { @@ -69,10 +67,8 @@ struct __fn { } }; -} // namespace __make_heap - inline namespace __cpo { -inline constexpr auto make_heap = __make_heap::__fn{}; +inline constexpr auto make_heap = __make_heap{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_max.h b/system/lib/libcxx/include/__algorithm/ranges_max.h index d0ee6f314b0c3..f631344422ed5 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_max.h +++ b/system/lib/libcxx/include/__algorithm/ranges_max.h @@ -36,8 +36,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __max { -struct __fn { +struct __max { template > _Comp = ranges::less> @@ -87,10 +86,9 @@ struct __fn { } } }; -} // namespace __max inline namespace __cpo { -inline constexpr auto max = __max::__fn{}; +inline constexpr auto max = __max{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_max_element.h b/system/lib/libcxx/include/__algorithm/ranges_max_element.h index c577309271165..869f71ecc8d20 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_max_element.h +++ b/system/lib/libcxx/include/__algorithm/ranges_max_element.h @@ -32,8 +32,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __max_element { -struct __fn { +struct __max_element { template _Sp, class _Proj = identity, @@ -53,10 +52,9 @@ struct __fn { return ranges::__min_element_impl(ranges::begin(__r), ranges::end(__r), __comp_lhs_rhs_swapped, __proj); } }; -} // namespace __max_element inline namespace __cpo { -inline constexpr auto max_element = __max_element::__fn{}; +inline constexpr auto max_element = __max_element{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_merge.h b/system/lib/libcxx/include/__algorithm/ranges_merge.h index bdf9a62d90bd2..f3e0486fe488e 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_merge.h +++ b/system/lib/libcxx/include/__algorithm/ranges_merge.h @@ -39,42 +39,7 @@ namespace ranges { template using merge_result = in_in_out_result<_InIter1, _InIter2, _OutIter>; -namespace __merge { - -template < class _InIter1, - class _Sent1, - class _InIter2, - class _Sent2, - class _OutIter, - class _Comp, - class _Proj1, - class _Proj2> -_LIBCPP_HIDE_FROM_ABI constexpr merge_result<__remove_cvref_t<_InIter1>, - __remove_cvref_t<_InIter2>, - __remove_cvref_t<_OutIter>> -__merge_impl(_InIter1&& __first1, - _Sent1&& __last1, - _InIter2&& __first2, - _Sent2&& __last2, - _OutIter&& __result, - _Comp&& __comp, - _Proj1&& __proj1, - _Proj2&& __proj2) { - for (; __first1 != __last1 && __first2 != __last2; ++__result) { - if (std::invoke(__comp, std::invoke(__proj2, *__first2), std::invoke(__proj1, *__first1))) { - *__result = *__first2; - ++__first2; - } else { - *__result = *__first1; - ++__first1; - } - } - auto __ret1 = ranges::copy(std::move(__first1), std::move(__last1), std::move(__result)); - auto __ret2 = ranges::copy(std::move(__first2), std::move(__last2), std::move(__ret1.out)); - return {std::move(__ret1.in), std::move(__ret2.in), std::move(__ret2.out)}; -} - -struct __fn { +struct __merge { template _Sent1, input_iterator _InIter2, @@ -120,12 +85,43 @@ struct __fn { __proj1, __proj2); } -}; -} // namespace __merge + template < class _InIter1, + class _Sent1, + class _InIter2, + class _Sent2, + class _OutIter, + class _Comp, + class _Proj1, + class _Proj2> + _LIBCPP_HIDE_FROM_ABI static constexpr merge_result<__remove_cvref_t<_InIter1>, + __remove_cvref_t<_InIter2>, + __remove_cvref_t<_OutIter>> + __merge_impl(_InIter1&& __first1, + _Sent1&& __last1, + _InIter2&& __first2, + _Sent2&& __last2, + _OutIter&& __result, + _Comp&& __comp, + _Proj1&& __proj1, + _Proj2&& __proj2) { + for (; __first1 != __last1 && __first2 != __last2; ++__result) { + if (std::invoke(__comp, std::invoke(__proj2, *__first2), std::invoke(__proj1, *__first1))) { + *__result = *__first2; + ++__first2; + } else { + *__result = *__first1; + ++__first1; + } + } + auto __ret1 = ranges::copy(std::move(__first1), std::move(__last1), std::move(__result)); + auto __ret2 = ranges::copy(std::move(__first2), std::move(__last2), std::move(__ret1.out)); + return {std::move(__ret1.in), std::move(__ret2.in), std::move(__ret2.out)}; + } +}; inline namespace __cpo { -inline constexpr auto merge = __merge::__fn{}; +inline constexpr auto merge = __merge{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_min.h b/system/lib/libcxx/include/__algorithm/ranges_min.h index cc569d2a060c2..302b5d7975b00 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_min.h +++ b/system/lib/libcxx/include/__algorithm/ranges_min.h @@ -35,8 +35,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __min { -struct __fn { +struct __min { template > _Comp = ranges::less> @@ -79,10 +78,9 @@ struct __fn { } } }; -} // namespace __min inline namespace __cpo { -inline constexpr auto min = __min::__fn{}; +inline constexpr auto min = __min{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_min_element.h b/system/lib/libcxx/include/__algorithm/ranges_min_element.h index 588ef258e26f5..fb92ae56bcd62 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_min_element.h +++ b/system/lib/libcxx/include/__algorithm/ranges_min_element.h @@ -46,8 +46,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr _Ip __min_element_impl(_Ip __first, _Sp __last, return __first; } -namespace __min_element { -struct __fn { +struct __min_element { template _Sp, class _Proj = identity, @@ -65,10 +64,9 @@ struct __fn { return ranges::__min_element_impl(ranges::begin(__r), ranges::end(__r), __comp, __proj); } }; -} // namespace __min_element inline namespace __cpo { -inline constexpr auto min_element = __min_element::__fn{}; +inline constexpr auto min_element = __min_element{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_minmax.h b/system/lib/libcxx/include/__algorithm/ranges_minmax.h index 09cbefd91a8c7..5f2e5cb2a1eea 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_minmax.h +++ b/system/lib/libcxx/include/__algorithm/ranges_minmax.h @@ -24,6 +24,7 @@ #include <__ranges/access.h> #include <__ranges/concepts.h> #include <__type_traits/desugars_to.h> +#include <__type_traits/is_integral.h> #include <__type_traits/is_reference.h> #include <__type_traits/is_trivially_copyable.h> #include <__type_traits/remove_cvref.h> @@ -47,8 +48,7 @@ namespace ranges { template using minmax_result = min_max_result<_T1>; -namespace __minmax { -struct __fn { +struct __minmax { template > _Comp = ranges::less> @@ -159,10 +159,9 @@ struct __fn { } } }; -} // namespace __minmax inline namespace __cpo { -inline constexpr auto minmax = __minmax::__fn{}; +inline constexpr auto minmax = __minmax{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_minmax_element.h b/system/lib/libcxx/include/__algorithm/ranges_minmax_element.h index 4bf6d2404e463..e1a22dde0955f 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_minmax_element.h +++ b/system/lib/libcxx/include/__algorithm/ranges_minmax_element.h @@ -40,8 +40,7 @@ namespace ranges { template using minmax_element_result = min_max_result<_T1>; -namespace __minmax_element { -struct __fn { +struct __minmax_element { template _Sp, class _Proj = identity, @@ -61,10 +60,9 @@ struct __fn { return {__ret.first, __ret.second}; } }; -} // namespace __minmax_element inline namespace __cpo { -inline constexpr auto minmax_element = __minmax_element::__fn{}; +inline constexpr auto minmax_element = __minmax_element{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_mismatch.h b/system/lib/libcxx/include/__algorithm/ranges_mismatch.h index c4bf0022a9bcc..b35747dfa43a2 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_mismatch.h +++ b/system/lib/libcxx/include/__algorithm/ranges_mismatch.h @@ -39,8 +39,7 @@ namespace ranges { template using mismatch_result = in_in_result<_I1, _I2>; -namespace __mismatch { -struct __fn { +struct __mismatch { template static _LIBCPP_HIDE_FROM_ABI constexpr mismatch_result<_I1, _I2> __go(_I1 __first1, _S1 __last1, _I2 __first2, _S2 __last2, _Pred& __pred, _Proj1& __proj1, _Proj2& __proj2) { @@ -84,10 +83,9 @@ struct __fn { ranges::begin(__r1), ranges::end(__r1), ranges::begin(__r2), ranges::end(__r2), __pred, __proj1, __proj2); } }; -} // namespace __mismatch inline namespace __cpo { -constexpr inline auto mismatch = __mismatch::__fn{}; +constexpr inline auto mismatch = __mismatch{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_move.h b/system/lib/libcxx/include/__algorithm/ranges_move.h index be869f36c9730..02bf7fd006190 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_move.h +++ b/system/lib/libcxx/include/__algorithm/ranges_move.h @@ -35,8 +35,7 @@ namespace ranges { template using move_result = in_out_result<_InIter, _OutIter>; -namespace __move { -struct __fn { +struct __move { template _LIBCPP_HIDE_FROM_ABI constexpr static move_result<_InIter, _OutIter> __move_impl(_InIter __first, _Sent __last, _OutIter __result) { @@ -58,10 +57,9 @@ struct __fn { return __move_impl(ranges::begin(__range), ranges::end(__range), std::move(__result)); } }; -} // namespace __move inline namespace __cpo { -inline constexpr auto move = __move::__fn{}; +inline constexpr auto move = __move{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_move_backward.h b/system/lib/libcxx/include/__algorithm/ranges_move_backward.h index 6d4071a33b812..4737e6c9756de 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_move_backward.h +++ b/system/lib/libcxx/include/__algorithm/ranges_move_backward.h @@ -37,8 +37,7 @@ namespace ranges { template using move_backward_result = in_out_result<_InIter, _OutIter>; -namespace __move_backward { -struct __fn { +struct __move_backward { template _LIBCPP_HIDE_FROM_ABI constexpr static move_backward_result<_InIter, _OutIter> __move_backward_impl(_InIter __first, _Sent __last, _OutIter __result) { @@ -60,10 +59,9 @@ struct __fn { return __move_backward_impl(ranges::begin(__range), ranges::end(__range), std::move(__result)); } }; -} // namespace __move_backward inline namespace __cpo { -inline constexpr auto move_backward = __move_backward::__fn{}; +inline constexpr auto move_backward = __move_backward{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_next_permutation.h b/system/lib/libcxx/include/__algorithm/ranges_next_permutation.h index 18535e0a6254a..1b485423e892f 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_next_permutation.h +++ b/system/lib/libcxx/include/__algorithm/ranges_next_permutation.h @@ -40,9 +40,7 @@ namespace ranges { template using next_permutation_result = in_found_result<_InIter>; -namespace __next_permutation { - -struct __fn { +struct __next_permutation { template _Sent, class _Comp = ranges::less, class _Proj = identity> requires sortable<_Iter, _Comp, _Proj> _LIBCPP_HIDE_FROM_ABI constexpr next_permutation_result<_Iter> @@ -62,10 +60,8 @@ struct __fn { } }; -} // namespace __next_permutation - inline namespace __cpo { -constexpr inline auto next_permutation = __next_permutation::__fn{}; +constexpr inline auto next_permutation = __next_permutation{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_none_of.h b/system/lib/libcxx/include/__algorithm/ranges_none_of.h index 7df3c1829fcfc..a1612826220d9 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_none_of.h +++ b/system/lib/libcxx/include/__algorithm/ranges_none_of.h @@ -30,8 +30,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __none_of { -struct __fn { +struct __none_of { template _LIBCPP_HIDE_FROM_ABI constexpr static bool __none_of_impl(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) { @@ -59,10 +58,9 @@ struct __fn { return __none_of_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj); } }; -} // namespace __none_of inline namespace __cpo { -inline constexpr auto none_of = __none_of::__fn{}; +inline constexpr auto none_of = __none_of{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_nth_element.h b/system/lib/libcxx/include/__algorithm/ranges_nth_element.h index 90ade9efe10da..e92c51e713cb4 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_nth_element.h +++ b/system/lib/libcxx/include/__algorithm/ranges_nth_element.h @@ -39,9 +39,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __nth_element { - -struct __fn { +struct __nth_element { template _LIBCPP_HIDE_FROM_ABI constexpr static _Iter __nth_element_fn_impl(_Iter __first, _Iter __nth, _Sent __last, _Comp& __comp, _Proj& __proj) { @@ -68,10 +66,8 @@ struct __fn { } }; -} // namespace __nth_element - inline namespace __cpo { -inline constexpr auto nth_element = __nth_element::__fn{}; +inline constexpr auto nth_element = __nth_element{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_partial_sort.h b/system/lib/libcxx/include/__algorithm/ranges_partial_sort.h index c67247d2e0a77..fc8a1f7d93065 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_partial_sort.h +++ b/system/lib/libcxx/include/__algorithm/ranges_partial_sort.h @@ -41,9 +41,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __partial_sort { - -struct __fn { +struct __partial_sort { template _LIBCPP_HIDE_FROM_ABI constexpr static _Iter __partial_sort_fn_impl(_Iter __first, _Iter __middle, _Sent __last, _Comp& __comp, _Proj& __proj) { @@ -66,10 +64,8 @@ struct __fn { } }; -} // namespace __partial_sort - inline namespace __cpo { -inline constexpr auto partial_sort = __partial_sort::__fn{}; +inline constexpr auto partial_sort = __partial_sort{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_partial_sort_copy.h b/system/lib/libcxx/include/__algorithm/ranges_partial_sort_copy.h index b3bdeb78fb6f6..f221504a8cae0 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_partial_sort_copy.h +++ b/system/lib/libcxx/include/__algorithm/ranges_partial_sort_copy.h @@ -42,9 +42,7 @@ namespace ranges { template using partial_sort_copy_result = in_out_result<_InIter, _OutIter>; -namespace __partial_sort_copy { - -struct __fn { +struct __partial_sort_copy { template _Sent1, random_access_iterator _Iter2, @@ -98,10 +96,8 @@ struct __fn { } }; -} // namespace __partial_sort_copy - inline namespace __cpo { -inline constexpr auto partial_sort_copy = __partial_sort_copy::__fn{}; +inline constexpr auto partial_sort_copy = __partial_sort_copy{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_partition.h b/system/lib/libcxx/include/__algorithm/ranges_partition.h index a67ac4c967570..b9cc3c1893709 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_partition.h +++ b/system/lib/libcxx/include/__algorithm/ranges_partition.h @@ -24,6 +24,7 @@ #include <__ranges/access.h> #include <__ranges/concepts.h> #include <__ranges/subrange.h> +#include <__type_traits/remove_cvref.h> #include <__utility/forward.h> #include <__utility/move.h> #include <__utility/pair.h> @@ -40,9 +41,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __partition { - -struct __fn { +struct __partition { template _LIBCPP_HIDE_FROM_ABI static constexpr subrange<__remove_cvref_t<_Iter>> __partition_fn_impl(_Iter&& __first, _Sent&& __last, _Pred&& __pred, _Proj&& __proj) { @@ -72,10 +71,8 @@ struct __fn { } }; -} // namespace __partition - inline namespace __cpo { -inline constexpr auto partition = __partition::__fn{}; +inline constexpr auto partition = __partition{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_partition_copy.h b/system/lib/libcxx/include/__algorithm/ranges_partition_copy.h index d60c865dd2a8a..47878a4017233 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_partition_copy.h +++ b/system/lib/libcxx/include/__algorithm/ranges_partition_copy.h @@ -38,9 +38,7 @@ namespace ranges { template using partition_copy_result = in_out_out_result<_InIter, _OutIter1, _OutIter2>; -namespace __partition_copy { - -struct __fn { +struct __partition_copy { // TODO(ranges): delegate to the classic algorithm. template _LIBCPP_HIDE_FROM_ABI constexpr static partition_copy_result<__remove_cvref_t<_InIter>, @@ -94,10 +92,8 @@ struct __fn { } }; -} // namespace __partition_copy - inline namespace __cpo { -inline constexpr auto partition_copy = __partition_copy::__fn{}; +inline constexpr auto partition_copy = __partition_copy{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_partition_point.h b/system/lib/libcxx/include/__algorithm/ranges_partition_point.h index c5b11b5fed192..324efbb86d64c 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_partition_point.h +++ b/system/lib/libcxx/include/__algorithm/ranges_partition_point.h @@ -35,9 +35,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __partition_point { - -struct __fn { +struct __partition_point { // TODO(ranges): delegate to the classic algorithm. template _LIBCPP_HIDE_FROM_ABI constexpr static _Iter @@ -77,10 +75,8 @@ struct __fn { } }; -} // namespace __partition_point - inline namespace __cpo { -inline constexpr auto partition_point = __partition_point::__fn{}; +inline constexpr auto partition_point = __partition_point{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_pop_heap.h b/system/lib/libcxx/include/__algorithm/ranges_pop_heap.h index 01f92c0f22888..eccf54c094e3d 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_pop_heap.h +++ b/system/lib/libcxx/include/__algorithm/ranges_pop_heap.h @@ -40,9 +40,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __pop_heap { - -struct __fn { +struct __pop_heap { template _LIBCPP_HIDE_FROM_ABI constexpr static _Iter __pop_heap_fn_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) { @@ -70,10 +68,8 @@ struct __fn { } }; -} // namespace __pop_heap - inline namespace __cpo { -inline constexpr auto pop_heap = __pop_heap::__fn{}; +inline constexpr auto pop_heap = __pop_heap{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_prev_permutation.h b/system/lib/libcxx/include/__algorithm/ranges_prev_permutation.h index 225cee9b75ec6..f2294b1cb00ba 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_prev_permutation.h +++ b/system/lib/libcxx/include/__algorithm/ranges_prev_permutation.h @@ -40,9 +40,7 @@ namespace ranges { template using prev_permutation_result = in_found_result<_InIter>; -namespace __prev_permutation { - -struct __fn { +struct __prev_permutation { template _Sent, class _Comp = ranges::less, class _Proj = identity> requires sortable<_Iter, _Comp, _Proj> _LIBCPP_HIDE_FROM_ABI constexpr prev_permutation_result<_Iter> @@ -62,10 +60,8 @@ struct __fn { } }; -} // namespace __prev_permutation - inline namespace __cpo { -constexpr inline auto prev_permutation = __prev_permutation::__fn{}; +constexpr inline auto prev_permutation = __prev_permutation{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_push_heap.h b/system/lib/libcxx/include/__algorithm/ranges_push_heap.h index 9d187af38c531..c5e0465bdcfe1 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_push_heap.h +++ b/system/lib/libcxx/include/__algorithm/ranges_push_heap.h @@ -40,9 +40,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __push_heap { - -struct __fn { +struct __push_heap { template _LIBCPP_HIDE_FROM_ABI constexpr static _Iter __push_heap_fn_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) { @@ -69,10 +67,8 @@ struct __fn { } }; -} // namespace __push_heap - inline namespace __cpo { -inline constexpr auto push_heap = __push_heap::__fn{}; +inline constexpr auto push_heap = __push_heap{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_remove.h b/system/lib/libcxx/include/__algorithm/ranges_remove.h index 17c3a2c5cd06b..6fbc49eba8a72 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_remove.h +++ b/system/lib/libcxx/include/__algorithm/ranges_remove.h @@ -33,8 +33,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __remove { -struct __fn { +struct __remove { template _Sent, class _Type, class _Proj = identity> requires indirect_binary_predicate, const _Type*> [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr subrange<_Iter> @@ -52,10 +51,9 @@ struct __fn { return ranges::__remove_if_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj); } }; -} // namespace __remove inline namespace __cpo { -inline constexpr auto remove = __remove::__fn{}; +inline constexpr auto remove = __remove{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_remove_copy.h b/system/lib/libcxx/include/__algorithm/ranges_remove_copy.h index 84529eceac68c..764c52ee16b27 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_remove_copy.h +++ b/system/lib/libcxx/include/__algorithm/ranges_remove_copy.h @@ -38,9 +38,7 @@ namespace ranges { template using remove_copy_result = in_out_result<_InIter, _OutIter>; -namespace __remove_copy { - -struct __fn { +struct __remove_copy { template _Sent, weakly_incrementable _OutIter, @@ -65,10 +63,8 @@ struct __fn { } }; -} // namespace __remove_copy - inline namespace __cpo { -inline constexpr auto remove_copy = __remove_copy::__fn{}; +inline constexpr auto remove_copy = __remove_copy{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_remove_copy_if.h b/system/lib/libcxx/include/__algorithm/ranges_remove_copy_if.h index 56fe017533120..87136ae8258d6 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_remove_copy_if.h +++ b/system/lib/libcxx/include/__algorithm/ranges_remove_copy_if.h @@ -53,9 +53,7 @@ __remove_copy_if_impl(_InIter __first, _Sent __last, _OutIter __result, _Pred& _ return {std::move(__first), std::move(__result)}; } -namespace __remove_copy_if { - -struct __fn { +struct __remove_copy_if { template _Sent, weakly_incrementable _OutIter, @@ -79,10 +77,8 @@ struct __fn { } }; -} // namespace __remove_copy_if - inline namespace __cpo { -inline constexpr auto remove_copy_if = __remove_copy_if::__fn{}; +inline constexpr auto remove_copy_if = __remove_copy_if{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_remove_if.h b/system/lib/libcxx/include/__algorithm/ranges_remove_if.h index 0ea5d9a01b881..384b3d41d0801 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_remove_if.h +++ b/system/lib/libcxx/include/__algorithm/ranges_remove_if.h @@ -53,8 +53,7 @@ __remove_if_impl(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) { return {__new_end, __i}; } -namespace __remove_if { -struct __fn { +struct __remove_if { template _Sent, class _Proj = identity, @@ -73,10 +72,9 @@ struct __fn { return ranges::__remove_if_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj); } }; -} // namespace __remove_if inline namespace __cpo { -inline constexpr auto remove_if = __remove_if::__fn{}; +inline constexpr auto remove_if = __remove_if{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_replace.h b/system/lib/libcxx/include/__algorithm/ranges_replace.h index 2b88dc032972f..15b1f38554a8c 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_replace.h +++ b/system/lib/libcxx/include/__algorithm/ranges_replace.h @@ -32,8 +32,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __replace { -struct __fn { +struct __replace { template _Sent, class _Type1, class _Type2, class _Proj = identity> requires indirectly_writable<_Iter, const _Type2&> && indirect_binary_predicate, const _Type1*> @@ -52,10 +51,9 @@ struct __fn { return ranges::__replace_if_impl(ranges::begin(__range), ranges::end(__range), __pred, __new_value, __proj); } }; -} // namespace __replace inline namespace __cpo { -inline constexpr auto replace = __replace::__fn{}; +inline constexpr auto replace = __replace{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_replace_copy.h b/system/lib/libcxx/include/__algorithm/ranges_replace_copy.h index 633f993e5c948..7ab1c71543e2a 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_replace_copy.h +++ b/system/lib/libcxx/include/__algorithm/ranges_replace_copy.h @@ -38,9 +38,7 @@ namespace ranges { template using replace_copy_result = in_out_result<_InIter, _OutIter>; -namespace __replace_copy { - -struct __fn { +struct __replace_copy { template _Sent, class _OldType, @@ -77,10 +75,8 @@ struct __fn { } }; -} // namespace __replace_copy - inline namespace __cpo { -inline constexpr auto replace_copy = __replace_copy::__fn{}; +inline constexpr auto replace_copy = __replace_copy{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_replace_copy_if.h b/system/lib/libcxx/include/__algorithm/ranges_replace_copy_if.h index e065c3ac0acc9..852ec45edaefe 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_replace_copy_if.h +++ b/system/lib/libcxx/include/__algorithm/ranges_replace_copy_if.h @@ -52,9 +52,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr replace_copy_if_result<_InIter, _OutIter> __repl return {std::move(__first), std::move(__result)}; } -namespace __replace_copy_if { - -struct __fn { +struct __replace_copy_if { template _Sent, class _Type, @@ -82,10 +80,8 @@ struct __fn { } }; -} // namespace __replace_copy_if - inline namespace __cpo { -inline constexpr auto replace_copy_if = __replace_copy_if::__fn{}; +inline constexpr auto replace_copy_if = __replace_copy_if{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_replace_if.h b/system/lib/libcxx/include/__algorithm/ranges_replace_if.h index 6445f42aea190..baa566810b5d0 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_replace_if.h +++ b/system/lib/libcxx/include/__algorithm/ranges_replace_if.h @@ -42,8 +42,7 @@ __replace_if_impl(_Iter __first, _Sent __last, _Pred& __pred, const _Type& __new return __first; } -namespace __replace_if { -struct __fn { +struct __replace_if { template _Sent, class _Type, @@ -65,10 +64,9 @@ struct __fn { return ranges::__replace_if_impl(ranges::begin(__range), ranges::end(__range), __pred, __new_value, __proj); } }; -} // namespace __replace_if inline namespace __cpo { -inline constexpr auto replace_if = __replace_if::__fn{}; +inline constexpr auto replace_if = __replace_if{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_reverse.h b/system/lib/libcxx/include/__algorithm/ranges_reverse.h index 9ec865995b4a5..4e82118719772 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_reverse.h +++ b/system/lib/libcxx/include/__algorithm/ranges_reverse.h @@ -27,8 +27,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __reverse { -struct __fn { +struct __reverse { template _Sent> requires permutable<_Iter> _LIBCPP_HIDE_FROM_ABI constexpr _Iter operator()(_Iter __first, _Sent __last) const { @@ -65,10 +64,9 @@ struct __fn { return (*this)(ranges::begin(__range), ranges::end(__range)); } }; -} // namespace __reverse inline namespace __cpo { -inline constexpr auto reverse = __reverse::__fn{}; +inline constexpr auto reverse = __reverse{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_reverse_copy.h b/system/lib/libcxx/include/__algorithm/ranges_reverse_copy.h index 60043787a7170..e5ca5cf652dc4 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_reverse_copy.h +++ b/system/lib/libcxx/include/__algorithm/ranges_reverse_copy.h @@ -37,8 +37,7 @@ namespace ranges { template using reverse_copy_result = in_out_result<_InIter, _OutIter>; -namespace __reverse_copy { -struct __fn { +struct __reverse_copy { template _Sent, weakly_incrementable _OutIter> requires indirectly_copyable<_InIter, _OutIter> _LIBCPP_HIDE_FROM_ABI constexpr reverse_copy_result<_InIter, _OutIter> @@ -54,10 +53,9 @@ struct __fn { return {ranges::next(ranges::begin(__range), ranges::end(__range)), std::move(__ret.out)}; } }; -} // namespace __reverse_copy inline namespace __cpo { -inline constexpr auto reverse_copy = __reverse_copy::__fn{}; +inline constexpr auto reverse_copy = __reverse_copy{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_rotate.h b/system/lib/libcxx/include/__algorithm/ranges_rotate.h index 8d33a6f0799bf..c1affc684ae4f 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_rotate.h +++ b/system/lib/libcxx/include/__algorithm/ranges_rotate.h @@ -33,9 +33,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __rotate { - -struct __fn { +struct __rotate { template _LIBCPP_HIDE_FROM_ABI constexpr static subrange<_Iter> __rotate_fn_impl(_Iter __first, _Iter __middle, _Sent __last) { auto __ret = std::__rotate<_RangeAlgPolicy>(std::move(__first), std::move(__middle), std::move(__last)); @@ -55,10 +53,8 @@ struct __fn { } }; -} // namespace __rotate - inline namespace __cpo { -inline constexpr auto rotate = __rotate::__fn{}; +inline constexpr auto rotate = __rotate{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_rotate_copy.h b/system/lib/libcxx/include/__algorithm/ranges_rotate_copy.h index 26fe110b53896..c0b4264a1b253 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_rotate_copy.h +++ b/system/lib/libcxx/include/__algorithm/ranges_rotate_copy.h @@ -34,8 +34,7 @@ namespace ranges { template using rotate_copy_result = in_out_result<_InIter, _OutIter>; -namespace __rotate_copy { -struct __fn { +struct __rotate_copy { template _Sent, weakly_incrementable _OutIter> requires indirectly_copyable<_InIter, _OutIter> _LIBCPP_HIDE_FROM_ABI constexpr rotate_copy_result<_InIter, _OutIter> @@ -52,10 +51,9 @@ struct __fn { return (*this)(ranges::begin(__range), std::move(__middle), ranges::end(__range), std::move(__result)); } }; -} // namespace __rotate_copy inline namespace __cpo { -inline constexpr auto rotate_copy = __rotate_copy::__fn{}; +inline constexpr auto rotate_copy = __rotate_copy{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_sample.h b/system/lib/libcxx/include/__algorithm/ranges_sample.h index e4f60a7b66be2..a3b29608150d2 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_sample.h +++ b/system/lib/libcxx/include/__algorithm/ranges_sample.h @@ -35,9 +35,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __sample { - -struct __fn { +struct __sample { template _Sent, weakly_incrementable _OutIter, class _Gen> requires(forward_iterator<_Iter> || random_access_iterator<_OutIter>) && indirectly_copyable<_Iter, _OutIter> && uniform_random_bit_generator> @@ -58,10 +56,8 @@ struct __fn { } }; -} // namespace __sample - inline namespace __cpo { -inline constexpr auto sample = __sample::__fn{}; +inline constexpr auto sample = __sample{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_search.h b/system/lib/libcxx/include/__algorithm/ranges_search.h index 55294c60631b1..b711512039635 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_search.h +++ b/system/lib/libcxx/include/__algorithm/ranges_search.h @@ -33,8 +33,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __search { -struct __fn { +struct __search { template _LIBCPP_HIDE_FROM_ABI static constexpr subrange<_Iter1> __ranges_search_impl( _Iter1 __first1, @@ -120,10 +119,9 @@ struct __fn { __proj2); } }; -} // namespace __search inline namespace __cpo { -inline constexpr auto search = __search::__fn{}; +inline constexpr auto search = __search{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_search_n.h b/system/lib/libcxx/include/__algorithm/ranges_search_n.h index 56e12755b9bf6..81b568c0965fd 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_search_n.h +++ b/system/lib/libcxx/include/__algorithm/ranges_search_n.h @@ -39,8 +39,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __search_n { -struct __fn { +struct __search_n { template _LIBCPP_HIDE_FROM_ABI static constexpr subrange<_Iter1> __ranges_search_n_impl( _Iter1 __first, _Sent1 __last, _SizeT __count, const _Type& __value, _Pred& __pred, _Proj& __proj) { @@ -100,10 +99,9 @@ struct __fn { return __ranges_search_n_impl(ranges::begin(__range), ranges::end(__range), __count, __value, __pred, __proj); } }; -} // namespace __search_n inline namespace __cpo { -inline constexpr auto search_n = __search_n::__fn{}; +inline constexpr auto search_n = __search_n{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_set_difference.h b/system/lib/libcxx/include/__algorithm/ranges_set_difference.h index 0841fb4ffd0c0..1c83c7bdd5a33 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_set_difference.h +++ b/system/lib/libcxx/include/__algorithm/ranges_set_difference.h @@ -10,7 +10,6 @@ #define _LIBCPP___ALGORITHM_RANGES_SET_DIFFERENCE_H #include <__algorithm/in_out_result.h> -#include <__algorithm/iterator_operations.h> #include <__algorithm/make_projected.h> #include <__algorithm/set_difference.h> #include <__config> @@ -42,9 +41,7 @@ namespace ranges { template using set_difference_result = in_out_result<_InIter, _OutIter>; -namespace __set_difference { - -struct __fn { +struct __set_difference { template _Sent1, input_iterator _InIter2, @@ -63,7 +60,7 @@ struct __fn { _Comp __comp = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const { - auto __ret = std::__set_difference<_RangeAlgPolicy>( + auto __ret = std::__set_difference( __first1, __last1, __first2, __last2, __result, ranges::__make_projected_comp(__comp, __proj1, __proj2)); return {std::move(__ret.first), std::move(__ret.second)}; } @@ -82,7 +79,7 @@ struct __fn { _Comp __comp = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const { - auto __ret = std::__set_difference<_RangeAlgPolicy>( + auto __ret = std::__set_difference( ranges::begin(__range1), ranges::end(__range1), ranges::begin(__range2), @@ -93,10 +90,8 @@ struct __fn { } }; -} // namespace __set_difference - inline namespace __cpo { -inline constexpr auto set_difference = __set_difference::__fn{}; +inline constexpr auto set_difference = __set_difference{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_set_intersection.h b/system/lib/libcxx/include/__algorithm/ranges_set_intersection.h index 9427379745b60..068794cf1b14f 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_set_intersection.h +++ b/system/lib/libcxx/include/__algorithm/ranges_set_intersection.h @@ -40,9 +40,7 @@ namespace ranges { template using set_intersection_result = in_in_out_result<_InIter1, _InIter2, _OutIter>; -namespace __set_intersection { - -struct __fn { +struct __set_intersection { template _Sent1, input_iterator _InIter2, @@ -98,10 +96,8 @@ struct __fn { } }; -} // namespace __set_intersection - inline namespace __cpo { -inline constexpr auto set_intersection = __set_intersection::__fn{}; +inline constexpr auto set_intersection = __set_intersection{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_set_symmetric_difference.h b/system/lib/libcxx/include/__algorithm/ranges_set_symmetric_difference.h index 995eb0999d940..c0a814043192c 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_set_symmetric_difference.h +++ b/system/lib/libcxx/include/__algorithm/ranges_set_symmetric_difference.h @@ -10,7 +10,6 @@ #define _LIBCPP___ALGORITHM_RANGES_SET_SYMMETRIC_DIFFERENCE_H #include <__algorithm/in_in_out_result.h> -#include <__algorithm/iterator_operations.h> #include <__algorithm/make_projected.h> #include <__algorithm/set_symmetric_difference.h> #include <__config> @@ -40,9 +39,7 @@ namespace ranges { template using set_symmetric_difference_result = in_in_out_result<_InIter1, _InIter2, _OutIter>; -namespace __set_symmetric_difference { - -struct __fn { +struct __set_symmetric_difference { template _Sent1, input_iterator _InIter2, @@ -61,7 +58,7 @@ struct __fn { _Comp __comp = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const { - auto __ret = std::__set_symmetric_difference<_RangeAlgPolicy>( + auto __ret = std::__set_symmetric_difference( std::move(__first1), std::move(__last1), std::move(__first2), @@ -87,7 +84,7 @@ struct __fn { _Comp __comp = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const { - auto __ret = std::__set_symmetric_difference<_RangeAlgPolicy>( + auto __ret = std::__set_symmetric_difference( ranges::begin(__range1), ranges::end(__range1), ranges::begin(__range2), @@ -98,10 +95,8 @@ struct __fn { } }; -} // namespace __set_symmetric_difference - inline namespace __cpo { -inline constexpr auto set_symmetric_difference = __set_symmetric_difference::__fn{}; +inline constexpr auto set_symmetric_difference = __set_symmetric_difference{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_set_union.h b/system/lib/libcxx/include/__algorithm/ranges_set_union.h index e870e390cc665..039ffb5932f3a 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_set_union.h +++ b/system/lib/libcxx/include/__algorithm/ranges_set_union.h @@ -10,7 +10,6 @@ #define _LIBCPP___ALGORITHM_RANGES_SET_UNION_H #include <__algorithm/in_in_out_result.h> -#include <__algorithm/iterator_operations.h> #include <__algorithm/make_projected.h> #include <__algorithm/set_union.h> #include <__config> @@ -43,9 +42,7 @@ namespace ranges { template using set_union_result = in_in_out_result<_InIter1, _InIter2, _OutIter>; -namespace __set_union { - -struct __fn { +struct __set_union { template _Sent1, input_iterator _InIter2, @@ -64,7 +61,7 @@ struct __fn { _Comp __comp = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const { - auto __ret = std::__set_union<_RangeAlgPolicy>( + auto __ret = std::__set_union( std::move(__first1), std::move(__last1), std::move(__first2), @@ -88,7 +85,7 @@ struct __fn { _Comp __comp = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const { - auto __ret = std::__set_union<_RangeAlgPolicy>( + auto __ret = std::__set_union( ranges::begin(__range1), ranges::end(__range1), ranges::begin(__range2), @@ -99,10 +96,8 @@ struct __fn { } }; -} // namespace __set_union - inline namespace __cpo { -inline constexpr auto set_union = __set_union::__fn{}; +inline constexpr auto set_union = __set_union{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_shuffle.h b/system/lib/libcxx/include/__algorithm/ranges_shuffle.h index ab98ea22caabe..87cb3685bb95f 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_shuffle.h +++ b/system/lib/libcxx/include/__algorithm/ranges_shuffle.h @@ -39,9 +39,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __shuffle { - -struct __fn { +struct __shuffle { template _Sent, class _Gen> requires permutable<_Iter> && uniform_random_bit_generator> _LIBCPP_HIDE_FROM_ABI _Iter operator()(_Iter __first, _Sent __last, _Gen&& __gen) const { @@ -56,10 +54,8 @@ struct __fn { } }; -} // namespace __shuffle - inline namespace __cpo { -inline constexpr auto shuffle = __shuffle::__fn{}; +inline constexpr auto shuffle = __shuffle{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_sort.h b/system/lib/libcxx/include/__algorithm/ranges_sort.h index 0296c146b3ede..2afad4c41301e 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_sort.h +++ b/system/lib/libcxx/include/__algorithm/ranges_sort.h @@ -39,9 +39,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __sort { - -struct __fn { +struct __sort { template _LIBCPP_HIDE_FROM_ABI constexpr static _Iter __sort_fn_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) { @@ -68,10 +66,8 @@ struct __fn { } }; -} // namespace __sort - inline namespace __cpo { -inline constexpr auto sort = __sort::__fn{}; +inline constexpr auto sort = __sort{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_sort_heap.h b/system/lib/libcxx/include/__algorithm/ranges_sort_heap.h index bab30df1708c7..d3e20874fac50 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_sort_heap.h +++ b/system/lib/libcxx/include/__algorithm/ranges_sort_heap.h @@ -40,9 +40,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __sort_heap { - -struct __fn { +struct __sort_heap { template _LIBCPP_HIDE_FROM_ABI constexpr static _Iter __sort_heap_fn_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) { @@ -69,10 +67,8 @@ struct __fn { } }; -} // namespace __sort_heap - inline namespace __cpo { -inline constexpr auto sort_heap = __sort_heap::__fn{}; +inline constexpr auto sort_heap = __sort_heap{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_stable_partition.h b/system/lib/libcxx/include/__algorithm/ranges_stable_partition.h index f34027ff772c7..cfc02e1e97b3f 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_stable_partition.h +++ b/system/lib/libcxx/include/__algorithm/ranges_stable_partition.h @@ -42,9 +42,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __stable_partition { - -struct __fn { +struct __stable_partition { template _LIBCPP_HIDE_FROM_ABI static subrange<__remove_cvref_t<_Iter>> __stable_partition_fn_impl(_Iter&& __first, _Sent&& __last, _Pred&& __pred, _Proj&& __proj) { @@ -76,10 +74,8 @@ struct __fn { } }; -} // namespace __stable_partition - inline namespace __cpo { -inline constexpr auto stable_partition = __stable_partition::__fn{}; +inline constexpr auto stable_partition = __stable_partition{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_stable_sort.h b/system/lib/libcxx/include/__algorithm/ranges_stable_sort.h index 93909e253cc0f..9c7df80ae9872 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_stable_sort.h +++ b/system/lib/libcxx/include/__algorithm/ranges_stable_sort.h @@ -39,9 +39,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __stable_sort { - -struct __fn { +struct __stable_sort { template _LIBCPP_HIDE_FROM_ABI static _Iter __stable_sort_fn_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) { auto __last_iter = ranges::next(__first, __last); @@ -66,10 +64,8 @@ struct __fn { } }; -} // namespace __stable_sort - inline namespace __cpo { -inline constexpr auto stable_sort = __stable_sort::__fn{}; +inline constexpr auto stable_sort = __stable_sort{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_starts_with.h b/system/lib/libcxx/include/__algorithm/ranges_starts_with.h index 17084e4f24336..ae145d59010ae 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_starts_with.h +++ b/system/lib/libcxx/include/__algorithm/ranges_starts_with.h @@ -32,8 +32,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __starts_with { -struct __fn { +struct __starts_with { template _Sent1, input_iterator _Iter2, @@ -50,7 +49,7 @@ struct __fn { _Pred __pred = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) { - return __mismatch::__fn::__go( + return __mismatch::__go( std::move(__first1), std::move(__last1), std::move(__first2), @@ -69,7 +68,7 @@ struct __fn { requires indirectly_comparable, iterator_t<_Range2>, _Pred, _Proj1, _Proj2> [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr bool operator()(_Range1&& __range1, _Range2&& __range2, _Pred __pred = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) { - return __mismatch::__fn::__go( + return __mismatch::__go( ranges::begin(__range1), ranges::end(__range1), ranges::begin(__range2), @@ -80,9 +79,8 @@ struct __fn { .in2 == ranges::end(__range2); } }; -} // namespace __starts_with inline namespace __cpo { -inline constexpr auto starts_with = __starts_with::__fn{}; +inline constexpr auto starts_with = __starts_with{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_swap_ranges.h b/system/lib/libcxx/include/__algorithm/ranges_swap_ranges.h index b6d9f618395a5..ab6db50d8a13e 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_swap_ranges.h +++ b/system/lib/libcxx/include/__algorithm/ranges_swap_ranges.h @@ -36,8 +36,7 @@ namespace ranges { template using swap_ranges_result = in_in_result<_I1, _I2>; -namespace __swap_ranges { -struct __fn { +struct __swap_ranges { template _S1, input_iterator _I2, sentinel_for<_I2> _S2> requires indirectly_swappable<_I1, _I2> _LIBCPP_HIDE_FROM_ABI constexpr swap_ranges_result<_I1, _I2> @@ -54,10 +53,9 @@ struct __fn { return operator()(ranges::begin(__r1), ranges::end(__r1), ranges::begin(__r2), ranges::end(__r2)); } }; -} // namespace __swap_ranges inline namespace __cpo { -inline constexpr auto swap_ranges = __swap_ranges::__fn{}; +inline constexpr auto swap_ranges = __swap_ranges{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_transform.h b/system/lib/libcxx/include/__algorithm/ranges_transform.h index 7850ec4f84656..091311821968c 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_transform.h +++ b/system/lib/libcxx/include/__algorithm/ranges_transform.h @@ -41,8 +41,7 @@ using unary_transform_result = in_out_result<_Ip, _Op>; template using binary_transform_result = in_in_out_result<_I1, _I2, _O1>; -namespace __transform { -struct __fn { +struct __transform { private: template _LIBCPP_HIDE_FROM_ABI static constexpr unary_transform_result<_InIter, _OutIter> @@ -161,10 +160,9 @@ struct __fn { __projection2); } }; -} // namespace __transform inline namespace __cpo { -inline constexpr auto transform = __transform::__fn{}; +inline constexpr auto transform = __transform{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_unique.h b/system/lib/libcxx/include/__algorithm/ranges_unique.h index 7a9b784321873..a817359abd889 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_unique.h +++ b/system/lib/libcxx/include/__algorithm/ranges_unique.h @@ -40,9 +40,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __unique { - -struct __fn { +struct __unique { template _Sent, class _Proj = identity, @@ -66,10 +64,8 @@ struct __fn { } }; -} // namespace __unique - inline namespace __cpo { -inline constexpr auto unique = __unique::__fn{}; +inline constexpr auto unique = __unique{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_unique_copy.h b/system/lib/libcxx/include/__algorithm/ranges_unique_copy.h index 61133885ae809..ee7f0a0187b73 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_unique_copy.h +++ b/system/lib/libcxx/include/__algorithm/ranges_unique_copy.h @@ -44,12 +44,10 @@ namespace ranges { template using unique_copy_result = in_out_result<_InIter, _OutIter>; -namespace __unique_copy { - template concept __can_reread_from_output = (input_iterator<_OutIter> && same_as, iter_value_t<_OutIter>>); -struct __fn { +struct __unique_copy { template static consteval auto __get_algo_tag() { if constexpr (forward_iterator<_InIter>) { @@ -62,7 +60,7 @@ struct __fn { } template - using __algo_tag_t = decltype(__get_algo_tag<_InIter, _OutIter>()); + using __algo_tag_t _LIBCPP_NODEBUG = decltype(__get_algo_tag<_InIter, _OutIter>()); template _Sent, @@ -104,10 +102,8 @@ struct __fn { } }; -} // namespace __unique_copy - inline namespace __cpo { -inline constexpr auto unique_copy = __unique_copy::__fn{}; +inline constexpr auto unique_copy = __unique_copy{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/ranges_upper_bound.h b/system/lib/libcxx/include/__algorithm/ranges_upper_bound.h index fa6fa7f70ed5a..4b2835d4d58de 100644 --- a/system/lib/libcxx/include/__algorithm/ranges_upper_bound.h +++ b/system/lib/libcxx/include/__algorithm/ranges_upper_bound.h @@ -30,8 +30,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD namespace ranges { -namespace __upper_bound { -struct __fn { +struct __upper_bound { template _Sent, class _Type, @@ -60,10 +59,9 @@ struct __fn { ranges::begin(__r), ranges::end(__r), __value, __comp_lhs_rhs_swapped, __proj); } }; -} // namespace __upper_bound inline namespace __cpo { -inline constexpr auto upper_bound = __upper_bound::__fn{}; +inline constexpr auto upper_bound = __upper_bound{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__algorithm/remove.h b/system/lib/libcxx/include/__algorithm/remove.h index fd01c23cb6708..b2d7023c5b072 100644 --- a/system/lib/libcxx/include/__algorithm/remove.h +++ b/system/lib/libcxx/include/__algorithm/remove.h @@ -24,7 +24,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator remove(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) { __first = std::find(__first, __last, __value); if (__first != __last) { diff --git a/system/lib/libcxx/include/__algorithm/remove_if.h b/system/lib/libcxx/include/__algorithm/remove_if.h index b14f3c0efa7e9..56fd745569eeb 100644 --- a/system/lib/libcxx/include/__algorithm/remove_if.h +++ b/system/lib/libcxx/include/__algorithm/remove_if.h @@ -23,7 +23,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator remove_if(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) { __first = std::find_if<_ForwardIterator, _Predicate&>(__first, __last, __pred); if (__first != __last) { diff --git a/system/lib/libcxx/include/__algorithm/search.h b/system/lib/libcxx/include/__algorithm/search.h index b82ca78095354..161fd39d861a6 100644 --- a/system/lib/libcxx/include/__algorithm/search.h +++ b/system/lib/libcxx/include/__algorithm/search.h @@ -14,11 +14,11 @@ #include <__algorithm/iterator_operations.h> #include <__config> #include <__functional/identity.h> -#include <__functional/invoke.h> #include <__iterator/advance.h> #include <__iterator/concepts.h> #include <__iterator/iterator_traits.h> #include <__type_traits/enable_if.h> +#include <__type_traits/invoke.h> #include <__type_traits/is_callable.h> #include <__utility/pair.h> @@ -160,20 +160,20 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter1, _Iter1> __searc } template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1 +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1 search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred) { - static_assert(__is_callable<_BinaryPredicate, decltype(*__first1), decltype(*__first2)>::value, - "BinaryPredicate has to be callable"); + static_assert(__is_callable<_BinaryPredicate&, decltype(*__first1), decltype(*__first2)>::value, + "The comparator has to be callable"); auto __proj = __identity(); return std::__search_impl(__first1, __last1, __first2, __last2, __pred, __proj, __proj).first; } template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1 +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator1 search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2) { return std::search(__first1, __last1, __first2, __last2, __equal_to()); } diff --git a/system/lib/libcxx/include/__algorithm/search_n.h b/system/lib/libcxx/include/__algorithm/search_n.h index 771647d3168a4..38474e1b2379d 100644 --- a/system/lib/libcxx/include/__algorithm/search_n.h +++ b/system/lib/libcxx/include/__algorithm/search_n.h @@ -14,12 +14,13 @@ #include <__algorithm/iterator_operations.h> #include <__config> #include <__functional/identity.h> -#include <__functional/invoke.h> #include <__iterator/advance.h> #include <__iterator/concepts.h> #include <__iterator/distance.h> #include <__iterator/iterator_traits.h> #include <__ranges/concepts.h> +#include <__type_traits/enable_if.h> +#include <__type_traits/invoke.h> #include <__type_traits/is_callable.h> #include <__utility/convert_to_integral.h> #include <__utility/pair.h> @@ -136,16 +137,16 @@ __search_n_impl(_Iter1 __first, _Sent1 __last, _DiffT __count, const _Type& __va } template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator search_n( +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator search_n( _ForwardIterator __first, _ForwardIterator __last, _Size __count, const _Tp& __value, _BinaryPredicate __pred) { static_assert( - __is_callable<_BinaryPredicate, decltype(*__first), const _Tp&>::value, "BinaryPredicate has to be callable"); + __is_callable<_BinaryPredicate&, decltype(*__first), const _Tp&>::value, "The comparator has to be callable"); auto __proj = __identity(); return std::__search_n_impl(__first, __last, std::__convert_to_integral(__count), __value, __pred, __proj).first; } template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator search_n(_ForwardIterator __first, _ForwardIterator __last, _Size __count, const _Tp& __value) { return std::search_n(__first, __last, std::__convert_to_integral(__count), __value, __equal_to()); } diff --git a/system/lib/libcxx/include/__algorithm/set_difference.h b/system/lib/libcxx/include/__algorithm/set_difference.h index f414bcecb50df..0cd1bc45d64f7 100644 --- a/system/lib/libcxx/include/__algorithm/set_difference.h +++ b/system/lib/libcxx/include/__algorithm/set_difference.h @@ -12,10 +12,8 @@ #include <__algorithm/comp.h> #include <__algorithm/comp_ref_type.h> #include <__algorithm/copy.h> -#include <__algorithm/iterator_operations.h> #include <__config> #include <__functional/identity.h> -#include <__functional/invoke.h> #include <__iterator/iterator_traits.h> #include <__type_traits/remove_cvref.h> #include <__utility/move.h> @@ -30,7 +28,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD -template +template _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<__remove_cvref_t<_InIter1>, __remove_cvref_t<_OutIter> > __set_difference( _InIter1&& __first1, _Sent1&& __last1, _InIter2&& __first2, _Sent2&& __last2, _OutIter&& __result, _Comp&& __comp) { @@ -46,7 +44,7 @@ __set_difference( ++__first2; } } - return std::__copy<_AlgPolicy>(std::move(__first1), std::move(__last1), std::move(__result)); + return std::__copy(std::move(__first1), std::move(__last1), std::move(__result)); } template @@ -57,8 +55,7 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator set_d _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) { - return std::__set_difference<_ClassicAlgPolicy, __comp_ref_type<_Compare> >( - __first1, __last1, __first2, __last2, __result, __comp) + return std::__set_difference<__comp_ref_type<_Compare> >(__first1, __last1, __first2, __last2, __result, __comp) .second; } @@ -69,7 +66,7 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator set_d _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result) { - return std::__set_difference<_ClassicAlgPolicy>(__first1, __last1, __first2, __last2, __result, __less<>()).second; + return std::__set_difference(__first1, __last1, __first2, __last2, __result, __less<>()).second; } _LIBCPP_END_NAMESPACE_STD diff --git a/system/lib/libcxx/include/__algorithm/set_intersection.h b/system/lib/libcxx/include/__algorithm/set_intersection.h index bb0d86cd0f58d..6246e24b9ca4e 100644 --- a/system/lib/libcxx/include/__algorithm/set_intersection.h +++ b/system/lib/libcxx/include/__algorithm/set_intersection.h @@ -19,6 +19,7 @@ #include <__iterator/next.h> #include <__type_traits/is_same.h> #include <__utility/exchange.h> +#include <__utility/forward.h> #include <__utility/move.h> #include <__utility/swap.h> @@ -84,7 +85,7 @@ template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __set_intersection_result<_InForwardIter1, _InForwardIter2, _OutIter> __set_intersection( _InForwardIter1 __first1, @@ -129,7 +130,7 @@ template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __set_intersection_result<_InInputIter1, _InInputIter2, _OutIter> __set_intersection( _InInputIter1 __first1, @@ -160,7 +161,7 @@ __set_intersection( } template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __set_intersection_result<_InIter1, _InIter2, _OutIter> __set_intersection( _InIter1 __first1, _Sent1 __last1, _InIter2 __first2, _Sent2 __last2, _OutIter __result, _Compare&& __comp) { diff --git a/system/lib/libcxx/include/__algorithm/set_symmetric_difference.h b/system/lib/libcxx/include/__algorithm/set_symmetric_difference.h index db36665a61365..91ea4067c0d0f 100644 --- a/system/lib/libcxx/include/__algorithm/set_symmetric_difference.h +++ b/system/lib/libcxx/include/__algorithm/set_symmetric_difference.h @@ -12,7 +12,6 @@ #include <__algorithm/comp.h> #include <__algorithm/comp_ref_type.h> #include <__algorithm/copy.h> -#include <__algorithm/iterator_operations.h> #include <__config> #include <__iterator/iterator_traits.h> #include <__utility/move.h> @@ -39,13 +38,13 @@ struct __set_symmetric_difference_result { : __in1_(std::move(__in_iter1)), __in2_(std::move(__in_iter2)), __out_(std::move(__out_iter)) {} }; -template +template _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __set_symmetric_difference_result<_InIter1, _InIter2, _OutIter> __set_symmetric_difference( _InIter1 __first1, _Sent1 __last1, _InIter2 __first2, _Sent2 __last2, _OutIter __result, _Compare&& __comp) { while (__first1 != __last1) { if (__first2 == __last2) { - auto __ret1 = std::__copy<_AlgPolicy>(std::move(__first1), std::move(__last1), std::move(__result)); + auto __ret1 = std::__copy(std::move(__first1), std::move(__last1), std::move(__result)); return __set_symmetric_difference_result<_InIter1, _InIter2, _OutIter>( std::move(__ret1.first), std::move(__first2), std::move((__ret1.second))); } @@ -63,7 +62,7 @@ __set_symmetric_difference( ++__first2; } } - auto __ret2 = std::__copy<_AlgPolicy>(std::move(__first2), std::move(__last2), std::move(__result)); + auto __ret2 = std::__copy(std::move(__first2), std::move(__last2), std::move(__result)); return __set_symmetric_difference_result<_InIter1, _InIter2, _OutIter>( std::move(__first1), std::move(__ret2.first), std::move((__ret2.second))); } @@ -76,7 +75,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator set_symmetri _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) { - return std::__set_symmetric_difference<_ClassicAlgPolicy, __comp_ref_type<_Compare> >( + return std::__set_symmetric_difference<__comp_ref_type<_Compare> >( std::move(__first1), std::move(__last1), std::move(__first2), diff --git a/system/lib/libcxx/include/__algorithm/set_union.h b/system/lib/libcxx/include/__algorithm/set_union.h index a79c50fd3cf2f..393dddce4302a 100644 --- a/system/lib/libcxx/include/__algorithm/set_union.h +++ b/system/lib/libcxx/include/__algorithm/set_union.h @@ -12,7 +12,6 @@ #include <__algorithm/comp.h> #include <__algorithm/comp_ref_type.h> #include <__algorithm/copy.h> -#include <__algorithm/iterator_operations.h> #include <__config> #include <__iterator/iterator_traits.h> #include <__utility/move.h> @@ -39,12 +38,12 @@ struct __set_union_result { : __in1_(std::move(__in_iter1)), __in2_(std::move(__in_iter2)), __out_(std::move(__out_iter)) {} }; -template +template _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __set_union_result<_InIter1, _InIter2, _OutIter> __set_union( _InIter1 __first1, _Sent1 __last1, _InIter2 __first2, _Sent2 __last2, _OutIter __result, _Compare&& __comp) { for (; __first1 != __last1; ++__result) { if (__first2 == __last2) { - auto __ret1 = std::__copy<_AlgPolicy>(std::move(__first1), std::move(__last1), std::move(__result)); + auto __ret1 = std::__copy(std::move(__first1), std::move(__last1), std::move(__result)); return __set_union_result<_InIter1, _InIter2, _OutIter>( std::move(__ret1.first), std::move(__first2), std::move((__ret1.second))); } @@ -59,7 +58,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __set_union_result<_InIter1, ++__first1; } } - auto __ret2 = std::__copy<_AlgPolicy>(std::move(__first2), std::move(__last2), std::move(__result)); + auto __ret2 = std::__copy(std::move(__first2), std::move(__last2), std::move(__result)); return __set_union_result<_InIter1, _InIter2, _OutIter>( std::move(__first1), std::move(__ret2.first), std::move((__ret2.second))); } @@ -72,7 +71,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator set_union( _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) { - return std::__set_union<_ClassicAlgPolicy, __comp_ref_type<_Compare> >( + return std::__set_union<__comp_ref_type<_Compare> >( std::move(__first1), std::move(__last1), std::move(__first2), diff --git a/system/lib/libcxx/include/__algorithm/shuffle.h b/system/lib/libcxx/include/__algorithm/shuffle.h index c9c56ce8c2c0b..7177fbb469ba7 100644 --- a/system/lib/libcxx/include/__algorithm/shuffle.h +++ b/system/lib/libcxx/include/__algorithm/shuffle.h @@ -11,12 +11,12 @@ #include <__algorithm/iterator_operations.h> #include <__config> +#include <__cstddef/ptrdiff_t.h> #include <__iterator/iterator_traits.h> #include <__random/uniform_int_distribution.h> #include <__utility/forward.h> #include <__utility/move.h> #include <__utility/swap.h> -#include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) diff --git a/system/lib/libcxx/include/__algorithm/simd_utils.h b/system/lib/libcxx/include/__algorithm/simd_utils.h index 549197be80183..4e03723a32854 100644 --- a/system/lib/libcxx/include/__algorithm/simd_utils.h +++ b/system/lib/libcxx/include/__algorithm/simd_utils.h @@ -14,10 +14,10 @@ #include <__bit/countl.h> #include <__bit/countr.h> #include <__config> +#include <__cstddef/size_t.h> #include <__type_traits/is_arithmetic.h> #include <__type_traits/is_same.h> #include <__utility/integer_sequence.h> -#include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -70,7 +70,7 @@ struct __get_as_integer_type_impl<8> { }; template -using __get_as_integer_type_t = typename __get_as_integer_type_impl::type; +using __get_as_integer_type_t _LIBCPP_NODEBUG = typename __get_as_integer_type_impl::type; // This isn't specialized for 64 byte vectors on purpose. They have the potential to significantly reduce performance // in mixed simd/non-simd workloads and don't provide any performance improvement for currently vectorized algorithms @@ -90,7 +90,7 @@ inline constexpr size_t __native_vector_size = 1; # endif template -using __simd_vector __attribute__((__ext_vector_type__(_Np))) = _ArithmeticT; +using __simd_vector __attribute__((__ext_vector_type__(_Np))) _LIBCPP_NODEBUG = _ArithmeticT; template inline constexpr size_t __simd_vector_size_v = []() -> size_t { @@ -106,23 +106,23 @@ _LIBCPP_HIDE_FROM_ABI _Tp __simd_vector_underlying_type_impl(__simd_vector<_Tp, } template -using __simd_vector_underlying_type_t = decltype(std::__simd_vector_underlying_type_impl(_VecT{})); +using __simd_vector_underlying_type_t _LIBCPP_NODEBUG = decltype(std::__simd_vector_underlying_type_impl(_VecT{})); // This isn't inlined without always_inline when loading chars. template -_LIBCPP_NODISCARD _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _VecT __load_vector(_Iter __iter) noexcept { +[[__nodiscard__]] _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _VecT __load_vector(_Iter __iter) noexcept { return [=](index_sequence<_Indices...>) _LIBCPP_ALWAYS_INLINE noexcept { return _VecT{__iter[_Indices]...}; }(make_index_sequence<__simd_vector_size_v<_VecT>>{}); } template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI bool __all_of(__simd_vector<_Tp, _Np> __vec) noexcept { +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool __all_of(__simd_vector<_Tp, _Np> __vec) noexcept { return __builtin_reduce_and(__builtin_convertvector(__vec, __simd_vector)); } template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI size_t __find_first_set(__simd_vector<_Tp, _Np> __vec) noexcept { +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI size_t __find_first_set(__simd_vector<_Tp, _Np> __vec) noexcept { using __mask_vec = __simd_vector; // This has MSan disabled du to https://github.com/llvm/llvm-project/issues/85876 @@ -151,7 +151,7 @@ _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI size_t __find_first_set(__simd_vector<_T } template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI size_t __find_first_not_set(__simd_vector<_Tp, _Np> __vec) noexcept { +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI size_t __find_first_not_set(__simd_vector<_Tp, _Np> __vec) noexcept { return std::__find_first_set(~__vec); } diff --git a/system/lib/libcxx/include/__algorithm/sort.h b/system/lib/libcxx/include/__algorithm/sort.h index 07b5814639e9e..8dd0721f2c65f 100644 --- a/system/lib/libcxx/include/__algorithm/sort.h +++ b/system/lib/libcxx/include/__algorithm/sort.h @@ -27,9 +27,14 @@ #include <__functional/ranges_operations.h> #include <__iterator/iterator_traits.h> #include <__type_traits/conditional.h> +#include <__type_traits/desugars_to.h> #include <__type_traits/disjunction.h> +#include <__type_traits/enable_if.h> #include <__type_traits/is_arithmetic.h> #include <__type_traits/is_constant_evaluated.h> +#include <__type_traits/is_same.h> +#include <__type_traits/is_trivially_copyable.h> +#include <__type_traits/remove_cvref.h> #include <__utility/move.h> #include <__utility/pair.h> #include @@ -44,110 +49,11 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD -// stable, 2-3 compares, 0-2 swaps - -template -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 unsigned -__sort3(_ForwardIterator __x, _ForwardIterator __y, _ForwardIterator __z, _Compare __c) { - using _Ops = _IterOps<_AlgPolicy>; - - unsigned __r = 0; - if (!__c(*__y, *__x)) // if x <= y - { - if (!__c(*__z, *__y)) // if y <= z - return __r; // x <= y && y <= z - // x <= y && y > z - _Ops::iter_swap(__y, __z); // x <= z && y < z - __r = 1; - if (__c(*__y, *__x)) // if x > y - { - _Ops::iter_swap(__x, __y); // x < y && y <= z - __r = 2; - } - return __r; // x <= y && y < z - } - if (__c(*__z, *__y)) // x > y, if y > z - { - _Ops::iter_swap(__x, __z); // x < y && y < z - __r = 1; - return __r; - } - _Ops::iter_swap(__x, __y); // x > y && y <= z - __r = 1; // x < y && x <= z - if (__c(*__z, *__y)) // if y > z - { - _Ops::iter_swap(__y, __z); // x <= y && y < z - __r = 2; - } - return __r; -} // x <= y && y <= z - -// stable, 3-6 compares, 0-5 swaps - -template -_LIBCPP_HIDE_FROM_ABI void -__sort4(_ForwardIterator __x1, _ForwardIterator __x2, _ForwardIterator __x3, _ForwardIterator __x4, _Compare __c) { - using _Ops = _IterOps<_AlgPolicy>; - std::__sort3<_AlgPolicy, _Compare>(__x1, __x2, __x3, __c); - if (__c(*__x4, *__x3)) { - _Ops::iter_swap(__x3, __x4); - if (__c(*__x3, *__x2)) { - _Ops::iter_swap(__x2, __x3); - if (__c(*__x2, *__x1)) { - _Ops::iter_swap(__x1, __x2); - } - } - } -} - -// stable, 4-10 compares, 0-9 swaps - -template -_LIBCPP_HIDE_FROM_ABI void -__sort5(_ForwardIterator __x1, - _ForwardIterator __x2, - _ForwardIterator __x3, - _ForwardIterator __x4, - _ForwardIterator __x5, - _Comp __comp) { - using _Ops = _IterOps<_AlgPolicy>; - - std::__sort4<_AlgPolicy, _Comp>(__x1, __x2, __x3, __x4, __comp); - if (__comp(*__x5, *__x4)) { - _Ops::iter_swap(__x4, __x5); - if (__comp(*__x4, *__x3)) { - _Ops::iter_swap(__x3, __x4); - if (__comp(*__x3, *__x2)) { - _Ops::iter_swap(__x2, __x3); - if (__comp(*__x2, *__x1)) { - _Ops::iter_swap(__x1, __x2); - } - } - } - } -} - -// The comparator being simple is a prerequisite for using the branchless optimization. -template -struct __is_simple_comparator : false_type {}; -template <> -struct __is_simple_comparator<__less<>&> : true_type {}; -template -struct __is_simple_comparator&> : true_type {}; -template -struct __is_simple_comparator&> : true_type {}; -#if _LIBCPP_STD_VER >= 20 -template <> -struct __is_simple_comparator : true_type {}; -template <> -struct __is_simple_comparator : true_type {}; -#endif - template ::value_type> -using __use_branchless_sort = - integral_constant::value && sizeof(_Tp) <= sizeof(void*) && - is_arithmetic<_Tp>::value && __is_simple_comparator<_Compare>::value>; +inline const bool __use_branchless_sort = + __libcpp_is_contiguous_iterator<_Iter>::value && __is_cheap_to_copy<_Tp> && is_arithmetic<_Tp>::value && + (__desugars_to_v<__less_tag, __remove_cvref_t<_Compare>, _Tp, _Tp> || + __desugars_to_v<__greater_tag, __remove_cvref_t<_Compare>, _Tp, _Tp>); namespace __detail { @@ -158,59 +64,88 @@ enum { __block_size = sizeof(uint64_t) * 8 }; // Ensures that __c(*__x, *__y) is true by swapping *__x and *__y if necessary. template -inline _LIBCPP_HIDE_FROM_ABI void __cond_swap(_RandomAccessIterator __x, _RandomAccessIterator __y, _Compare __c) { +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool +__cond_swap(_RandomAccessIterator __x, _RandomAccessIterator __y, _Compare __c) { // Note: this function behaves correctly even with proxy iterators (because it relies on `value_type`). using value_type = typename iterator_traits<_RandomAccessIterator>::value_type; bool __r = __c(*__x, *__y); value_type __tmp = __r ? *__x : *__y; *__y = __r ? *__y : *__x; *__x = __tmp; + return !__r; } // Ensures that *__x, *__y and *__z are ordered according to the comparator __c, // under the assumption that *__y and *__z are already ordered. template -inline _LIBCPP_HIDE_FROM_ABI void +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool __partially_sorted_swap(_RandomAccessIterator __x, _RandomAccessIterator __y, _RandomAccessIterator __z, _Compare __c) { // Note: this function behaves correctly even with proxy iterators (because it relies on `value_type`). using value_type = typename iterator_traits<_RandomAccessIterator>::value_type; - bool __r = __c(*__z, *__x); - value_type __tmp = __r ? *__z : *__x; - *__z = __r ? *__x : *__z; - __r = __c(__tmp, *__y); - *__x = __r ? *__x : *__y; - *__y = __r ? *__y : __tmp; + bool __r1 = __c(*__z, *__x); + value_type __tmp = __r1 ? *__z : *__x; + *__z = __r1 ? *__x : *__z; + bool __r2 = __c(__tmp, *__y); + *__x = __r2 ? *__x : *__y; + *__y = __r2 ? *__y : __tmp; + return !__r1 || !__r2; } +// stable, 2-3 compares, 0-2 swaps + template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI void __sort3_maybe_branchless( - _RandomAccessIterator __x1, _RandomAccessIterator __x2, _RandomAccessIterator __x3, _Compare __c) { - std::__cond_swap<_Compare>(__x2, __x3, __c); - std::__partially_sorted_swap<_Compare>(__x1, __x2, __x3, __c); + __enable_if_t<__use_branchless_sort<_Compare, _RandomAccessIterator>, int> = 0> +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool +__sort3(_RandomAccessIterator __x1, _RandomAccessIterator __x2, _RandomAccessIterator __x3, _Compare __c) { + bool __swapped1 = std::__cond_swap<_Compare>(__x2, __x3, __c); + bool __swapped2 = std::__partially_sorted_swap<_Compare>(__x1, __x2, __x3, __c); + return __swapped1 || __swapped2; } template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI void __sort3_maybe_branchless( - _RandomAccessIterator __x1, _RandomAccessIterator __x2, _RandomAccessIterator __x3, _Compare __c) { - std::__sort3<_AlgPolicy, _Compare>(__x1, __x2, __x3, __c); -} + __enable_if_t, int> = 0> +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool +__sort3(_RandomAccessIterator __x, _RandomAccessIterator __y, _RandomAccessIterator __z, _Compare __c) { + using _Ops = _IterOps<_AlgPolicy>; + + if (!__c(*__y, *__x)) // if x <= y + { + if (!__c(*__z, *__y)) // if y <= z + return false; // x <= y && y <= z + // x <= y && y > z + _Ops::iter_swap(__y, __z); // x <= z && y < z + if (__c(*__y, *__x)) // if x > y + _Ops::iter_swap(__x, __y); // x < y && y <= z + return true; // x <= y && y < z + } + if (__c(*__z, *__y)) // x > y, if y > z + { + _Ops::iter_swap(__x, __z); // x < y && y < z + return true; + } + _Ops::iter_swap(__x, __y); // x > y && y <= z + // x < y && x <= z + if (__c(*__z, *__y)) // if y > z + _Ops::iter_swap(__y, __z); // x <= y && y < z + return true; +} // x <= y && y <= z + +// stable, 3-6 compares, 0-5 swaps template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI void __sort4_maybe_branchless( - _RandomAccessIterator __x1, - _RandomAccessIterator __x2, - _RandomAccessIterator __x3, - _RandomAccessIterator __x4, - _Compare __c) { + __enable_if_t<__use_branchless_sort<_Compare, _RandomAccessIterator>, int> = 0> +inline _LIBCPP_HIDE_FROM_ABI void +__sort4(_RandomAccessIterator __x1, + _RandomAccessIterator __x2, + _RandomAccessIterator __x3, + _RandomAccessIterator __x4, + _Compare __c) { std::__cond_swap<_Compare>(__x1, __x3, __c); std::__cond_swap<_Compare>(__x2, __x4, __c); std::__cond_swap<_Compare>(__x1, __x2, __c); @@ -221,27 +156,39 @@ inline _LIBCPP_HIDE_FROM_ABI void __sort4_maybe_branchless( template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI void __sort4_maybe_branchless( - _RandomAccessIterator __x1, - _RandomAccessIterator __x2, - _RandomAccessIterator __x3, - _RandomAccessIterator __x4, - _Compare __c) { - std::__sort4<_AlgPolicy, _Compare>(__x1, __x2, __x3, __x4, __c); + __enable_if_t, int> = 0> +inline _LIBCPP_HIDE_FROM_ABI void +__sort4(_RandomAccessIterator __x1, + _RandomAccessIterator __x2, + _RandomAccessIterator __x3, + _RandomAccessIterator __x4, + _Compare __c) { + using _Ops = _IterOps<_AlgPolicy>; + std::__sort3<_AlgPolicy, _Compare>(__x1, __x2, __x3, __c); + if (__c(*__x4, *__x3)) { + _Ops::iter_swap(__x3, __x4); + if (__c(*__x3, *__x2)) { + _Ops::iter_swap(__x2, __x3); + if (__c(*__x2, *__x1)) { + _Ops::iter_swap(__x1, __x2); + } + } + } } +// stable, 4-10 compares, 0-9 swaps + template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI void __sort5_maybe_branchless( - _RandomAccessIterator __x1, - _RandomAccessIterator __x2, - _RandomAccessIterator __x3, - _RandomAccessIterator __x4, - _RandomAccessIterator __x5, - _Compare __c) { + __enable_if_t<__use_branchless_sort<_Compare, _RandomAccessIterator>, int> = 0> +inline _LIBCPP_HIDE_FROM_ABI void +__sort5(_RandomAccessIterator __x1, + _RandomAccessIterator __x2, + _RandomAccessIterator __x3, + _RandomAccessIterator __x4, + _RandomAccessIterator __x5, + _Compare __c) { std::__cond_swap<_Compare>(__x1, __x2, __c); std::__cond_swap<_Compare>(__x4, __x5, __c); std::__partially_sorted_swap<_Compare>(__x3, __x4, __x5, __c); @@ -253,16 +200,29 @@ inline _LIBCPP_HIDE_FROM_ABI void __sort5_maybe_branchless( template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI void __sort5_maybe_branchless( - _RandomAccessIterator __x1, - _RandomAccessIterator __x2, - _RandomAccessIterator __x3, - _RandomAccessIterator __x4, - _RandomAccessIterator __x5, - _Compare __c) { - std::__sort5<_AlgPolicy, _Compare, _RandomAccessIterator>( - std::move(__x1), std::move(__x2), std::move(__x3), std::move(__x4), std::move(__x5), __c); + __enable_if_t, int> = 0> +inline _LIBCPP_HIDE_FROM_ABI void +__sort5(_RandomAccessIterator __x1, + _RandomAccessIterator __x2, + _RandomAccessIterator __x3, + _RandomAccessIterator __x4, + _RandomAccessIterator __x5, + _Compare __comp) { + using _Ops = _IterOps<_AlgPolicy>; + + std::__sort4<_AlgPolicy, _Compare>(__x1, __x2, __x3, __x4, __comp); + if (__comp(*__x5, *__x4)) { + _Ops::iter_swap(__x4, __x5); + if (__comp(*__x4, *__x3)) { + _Ops::iter_swap(__x3, __x4); + if (__comp(*__x3, *__x2)) { + _Ops::iter_swap(__x2, __x3); + if (__comp(*__x2, *__x1)) { + _Ops::iter_swap(__x1, __x2); + } + } + } + } } // Assumes size > 0 @@ -280,7 +240,7 @@ __selection_sort(_BidirectionalIterator __first, _BidirectionalIterator __last, // Sort the iterator range [__first, __last) using the comparator __comp using // the insertion sort algorithm. template -_LIBCPP_HIDE_FROM_ABI void +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __insertion_sort(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp) { using _Ops = _IterOps<_AlgPolicy>; @@ -352,14 +312,14 @@ __insertion_sort_incomplete(_RandomAccessIterator __first, _RandomAccessIterator _Ops::iter_swap(__first, __last); return true; case 3: - std::__sort3_maybe_branchless<_AlgPolicy, _Comp>(__first, __first + difference_type(1), --__last, __comp); + std::__sort3<_AlgPolicy, _Comp>(__first, __first + difference_type(1), --__last, __comp); return true; case 4: - std::__sort4_maybe_branchless<_AlgPolicy, _Comp>( + std::__sort4<_AlgPolicy, _Comp>( __first, __first + difference_type(1), __first + difference_type(2), --__last, __comp); return true; case 5: - std::__sort5_maybe_branchless<_AlgPolicy, _Comp>( + std::__sort5<_AlgPolicy, _Comp>( __first, __first + difference_type(1), __first + difference_type(2), @@ -370,7 +330,7 @@ __insertion_sort_incomplete(_RandomAccessIterator __first, _RandomAccessIterator } typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; _RandomAccessIterator __j = __first + difference_type(2); - std::__sort3_maybe_branchless<_AlgPolicy, _Comp>(__first, __first + difference_type(1), __j, __comp); + std::__sort3<_AlgPolicy, _Comp>(__first, __first + difference_type(1), __j, __comp); const unsigned __limit = 8; unsigned __count = 0; for (_RandomAccessIterator __i = __j + difference_type(1); __i != __last; ++__i) { @@ -777,14 +737,14 @@ void __introsort(_RandomAccessIterator __first, _Ops::iter_swap(__first, __last); return; case 3: - std::__sort3_maybe_branchless<_AlgPolicy, _Compare>(__first, __first + difference_type(1), --__last, __comp); + std::__sort3<_AlgPolicy, _Compare>(__first, __first + difference_type(1), --__last, __comp); return; case 4: - std::__sort4_maybe_branchless<_AlgPolicy, _Compare>( + std::__sort4<_AlgPolicy, _Compare>( __first, __first + difference_type(1), __first + difference_type(2), --__last, __comp); return; case 5: - std::__sort5_maybe_branchless<_AlgPolicy, _Compare>( + std::__sort5<_AlgPolicy, _Compare>( __first, __first + difference_type(1), __first + difference_type(2), @@ -891,7 +851,7 @@ template void __sort(_RandomAccessIterator, _RandomAccessIterator, _Comp); extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less&, char*>(char*, char*, __less&); -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +#if _LIBCPP_HAS_WIDE_CHARACTERS extern template _LIBCPP_EXPORTED_FROM_ABI void __sort<__less&, wchar_t*>(wchar_t*, wchar_t*, __less&); #endif extern template _LIBCPP_EXPORTED_FROM_ABI void @@ -925,20 +885,18 @@ __sort_dispatch(_RandomAccessIterator __first, _RandomAccessIterator __last, _Co // Only use bitset partitioning for arithmetic types. We should also check // that the default comparator is in use so that we are sure that there are no // branches in the comparator. - std::__introsort<_AlgPolicy, - _Comp&, - _RandomAccessIterator, - __use_branchless_sort<_Comp, _RandomAccessIterator>::value>(__first, __last, __comp, __depth_limit); + std::__introsort<_AlgPolicy, _Comp&, _RandomAccessIterator, __use_branchless_sort<_Comp, _RandomAccessIterator> >( + __first, __last, __comp, __depth_limit); } template -using __is_any_of = _Or...>; +using __is_any_of _LIBCPP_NODEBUG = _Or...>; template -using __sort_is_specialized_in_library = __is_any_of< +using __sort_is_specialized_in_library _LIBCPP_NODEBUG = __is_any_of< _Type, char, -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +#if _LIBCPP_HAS_WIDE_CHARACTERS wchar_t, #endif signed char, diff --git a/system/lib/libcxx/include/__algorithm/stable_partition.h b/system/lib/libcxx/include/__algorithm/stable_partition.h index 8bb1eaf2d2249..2ba7239a3a039 100644 --- a/system/lib/libcxx/include/__algorithm/stable_partition.h +++ b/system/lib/libcxx/include/__algorithm/stable_partition.h @@ -12,15 +12,16 @@ #include <__algorithm/iterator_operations.h> #include <__algorithm/rotate.h> #include <__config> +#include <__cstddef/ptrdiff_t.h> #include <__iterator/advance.h> #include <__iterator/distance.h> #include <__iterator/iterator_traits.h> #include <__memory/destruct_n.h> -#include <__memory/temporary_buffer.h> #include <__memory/unique_ptr.h> +#include <__memory/unique_temporary_buffer.h> +#include <__type_traits/remove_cvref.h> #include <__utility/move.h> #include <__utility/pair.h> -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -132,14 +133,12 @@ __stable_partition_impl(_ForwardIterator __first, _ForwardIterator __last, _Pred // We now have a reduced range [__first, __last) // *__first is known to be false difference_type __len = _IterOps<_AlgPolicy>::distance(__first, __last); + __unique_temporary_buffer __unique_buf; pair __p(0, 0); - unique_ptr __h; if (__len >= __alloc_limit) { - // TODO: Remove the use of std::get_temporary_buffer - _LIBCPP_SUPPRESS_DEPRECATED_PUSH - __p = std::get_temporary_buffer(__len); - _LIBCPP_SUPPRESS_DEPRECATED_POP - __h.reset(__p.first); + __unique_buf = std::__allocate_unique_temporary_buffer(__len); + __p.first = __unique_buf.get(); + __p.second = __unique_buf.get_deleter().__count_; } return std::__stable_partition_impl<_AlgPolicy, _Predicate&>( std::move(__first), std::move(__last), __pred, __len, __p, forward_iterator_tag()); @@ -272,14 +271,12 @@ _LIBCPP_HIDE_FROM_ABI _BidirectionalIterator __stable_partition_impl( // *__last is known to be true // __len >= 2 difference_type __len = _IterOps<_AlgPolicy>::distance(__first, __last) + 1; + __unique_temporary_buffer __unique_buf; pair __p(0, 0); - unique_ptr __h; if (__len >= __alloc_limit) { - // TODO: Remove the use of std::get_temporary_buffer - _LIBCPP_SUPPRESS_DEPRECATED_PUSH - __p = std::get_temporary_buffer(__len); - _LIBCPP_SUPPRESS_DEPRECATED_POP - __h.reset(__p.first); + __unique_buf = std::__allocate_unique_temporary_buffer(__len); + __p.first = __unique_buf.get(); + __p.second = __unique_buf.get_deleter().__count_; } return std::__stable_partition_impl<_AlgPolicy, _Predicate&>( std::move(__first), std::move(__last), __pred, __len, __p, bidirectional_iterator_tag()); diff --git a/system/lib/libcxx/include/__algorithm/stable_sort.h b/system/lib/libcxx/include/__algorithm/stable_sort.h index 726e7e16b3564..3cfbcf08d2c5c 100644 --- a/system/lib/libcxx/include/__algorithm/stable_sort.h +++ b/system/lib/libcxx/include/__algorithm/stable_sort.h @@ -13,17 +13,24 @@ #include <__algorithm/comp_ref_type.h> #include <__algorithm/inplace_merge.h> #include <__algorithm/iterator_operations.h> +#include <__algorithm/radix_sort.h> #include <__algorithm/sort.h> #include <__config> +#include <__cstddef/ptrdiff_t.h> #include <__debug_utils/strict_weak_ordering_check.h> #include <__iterator/iterator_traits.h> +#include <__memory/construct_at.h> #include <__memory/destruct_n.h> -#include <__memory/temporary_buffer.h> #include <__memory/unique_ptr.h> +#include <__memory/unique_temporary_buffer.h> +#include <__type_traits/desugars_to.h> +#include <__type_traits/enable_if.h> +#include <__type_traits/is_integral.h> +#include <__type_traits/is_same.h> #include <__type_traits/is_trivially_assignable.h> +#include <__type_traits/remove_cvref.h> #include <__utility/move.h> #include <__utility/pair.h> -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -35,7 +42,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_HIDE_FROM_ABI void __insertion_sort_move( +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __insertion_sort_move( _BidirectionalIterator __first1, _BidirectionalIterator __last1, typename iterator_traits<_BidirectionalIterator>::value_type* __first2, @@ -47,19 +54,19 @@ _LIBCPP_HIDE_FROM_ABI void __insertion_sort_move( __destruct_n __d(0); unique_ptr __h(__first2, __d); value_type* __last2 = __first2; - ::new ((void*)__last2) value_type(_Ops::__iter_move(__first1)); + std::__construct_at(__last2, _Ops::__iter_move(__first1)); __d.template __incr(); for (++__last2; ++__first1 != __last1; ++__last2) { value_type* __j2 = __last2; value_type* __i2 = __j2; if (__comp(*__first1, *--__i2)) { - ::new ((void*)__j2) value_type(std::move(*__i2)); + std::__construct_at(__j2, std::move(*__i2)); __d.template __incr(); for (--__j2; __i2 != __first2 && __comp(*__first1, *--__i2); --__j2) *__j2 = std::move(*__i2); *__j2 = _Ops::__iter_move(__first1); } else { - ::new ((void*)__j2) value_type(_Ops::__iter_move(__first1)); + std::__construct_at(__j2, _Ops::__iter_move(__first1)); __d.template __incr(); } } @@ -68,7 +75,7 @@ _LIBCPP_HIDE_FROM_ABI void __insertion_sort_move( } template -_LIBCPP_HIDE_FROM_ABI void __merge_move_construct( +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __merge_move_construct( _InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, @@ -83,22 +90,22 @@ _LIBCPP_HIDE_FROM_ABI void __merge_move_construct( for (; true; ++__result) { if (__first1 == __last1) { for (; __first2 != __last2; ++__first2, (void)++__result, __d.template __incr()) - ::new ((void*)__result) value_type(_Ops::__iter_move(__first2)); + std::__construct_at(__result, _Ops::__iter_move(__first2)); __h.release(); return; } if (__first2 == __last2) { for (; __first1 != __last1; ++__first1, (void)++__result, __d.template __incr()) - ::new ((void*)__result) value_type(_Ops::__iter_move(__first1)); + std::__construct_at(__result, _Ops::__iter_move(__first1)); __h.release(); return; } if (__comp(*__first2, *__first1)) { - ::new ((void*)__result) value_type(_Ops::__iter_move(__first2)); + std::__construct_at(__result, _Ops::__iter_move(__first2)); __d.template __incr(); ++__first2; } else { - ::new ((void*)__result) value_type(_Ops::__iter_move(__first1)); + std::__construct_at(__result, _Ops::__iter_move(__first1)); __d.template __incr(); ++__first1; } @@ -106,7 +113,7 @@ _LIBCPP_HIDE_FROM_ABI void __merge_move_construct( } template -_LIBCPP_HIDE_FROM_ABI void __merge_move_assign( +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __merge_move_assign( _InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, @@ -134,19 +141,21 @@ _LIBCPP_HIDE_FROM_ABI void __merge_move_assign( } template -void __stable_sort(_RandomAccessIterator __first, - _RandomAccessIterator __last, - _Compare __comp, - typename iterator_traits<_RandomAccessIterator>::difference_type __len, - typename iterator_traits<_RandomAccessIterator>::value_type* __buff, - ptrdiff_t __buff_size); +_LIBCPP_CONSTEXPR_SINCE_CXX26 void __stable_sort( + _RandomAccessIterator __first, + _RandomAccessIterator __last, + _Compare __comp, + typename iterator_traits<_RandomAccessIterator>::difference_type __len, + typename iterator_traits<_RandomAccessIterator>::value_type* __buff, + ptrdiff_t __buff_size); template -void __stable_sort_move(_RandomAccessIterator __first1, - _RandomAccessIterator __last1, - _Compare __comp, - typename iterator_traits<_RandomAccessIterator>::difference_type __len, - typename iterator_traits<_RandomAccessIterator>::value_type* __first2) { +_LIBCPP_CONSTEXPR_SINCE_CXX26 void __stable_sort_move( + _RandomAccessIterator __first1, + _RandomAccessIterator __last1, + _Compare __comp, + typename iterator_traits<_RandomAccessIterator>::difference_type __len, + typename iterator_traits<_RandomAccessIterator>::value_type* __first2) { using _Ops = _IterOps<_AlgPolicy>; typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; @@ -154,21 +163,21 @@ void __stable_sort_move(_RandomAccessIterator __first1, case 0: return; case 1: - ::new ((void*)__first2) value_type(_Ops::__iter_move(__first1)); + std::__construct_at(__first2, _Ops::__iter_move(__first1)); return; case 2: __destruct_n __d(0); unique_ptr __h2(__first2, __d); if (__comp(*--__last1, *__first1)) { - ::new ((void*)__first2) value_type(_Ops::__iter_move(__last1)); + std::__construct_at(__first2, _Ops::__iter_move(__last1)); __d.template __incr(); ++__first2; - ::new ((void*)__first2) value_type(_Ops::__iter_move(__first1)); + std::__construct_at(__first2, _Ops::__iter_move(__first1)); } else { - ::new ((void*)__first2) value_type(_Ops::__iter_move(__first1)); + std::__construct_at(__first2, _Ops::__iter_move(__first1)); __d.template __incr(); ++__first2; - ::new ((void*)__first2) value_type(_Ops::__iter_move(__last1)); + std::__construct_at(__first2, _Ops::__iter_move(__last1)); } __h2.release(); return; @@ -189,13 +198,36 @@ struct __stable_sort_switch { static const unsigned value = 128 * is_trivially_copy_assignable<_Tp>::value; }; +#if _LIBCPP_STD_VER >= 17 +template +_LIBCPP_HIDE_FROM_ABI constexpr unsigned __radix_sort_min_bound() { + static_assert(is_integral<_Tp>::value); + if constexpr (sizeof(_Tp) == 1) { + return 1 << 8; + } + + return 1 << 10; +} + +template +_LIBCPP_HIDE_FROM_ABI constexpr unsigned __radix_sort_max_bound() { + static_assert(is_integral<_Tp>::value); + if constexpr (sizeof(_Tp) >= 8) { + return 1 << 15; + } + + return 1 << 16; +} +#endif // _LIBCPP_STD_VER >= 17 + template -void __stable_sort(_RandomAccessIterator __first, - _RandomAccessIterator __last, - _Compare __comp, - typename iterator_traits<_RandomAccessIterator>::difference_type __len, - typename iterator_traits<_RandomAccessIterator>::value_type* __buff, - ptrdiff_t __buff_size) { +_LIBCPP_CONSTEXPR_SINCE_CXX26 void __stable_sort( + _RandomAccessIterator __first, + _RandomAccessIterator __last, + _Compare __comp, + typename iterator_traits<_RandomAccessIterator>::difference_type __len, + typename iterator_traits<_RandomAccessIterator>::value_type* __buff, + ptrdiff_t __buff_size) { typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; switch (__len) { @@ -211,6 +243,22 @@ void __stable_sort(_RandomAccessIterator __first, std::__insertion_sort<_AlgPolicy, _Compare>(__first, __last, __comp); return; } + +#if _LIBCPP_STD_VER >= 17 + constexpr auto __default_comp = + __desugars_to_v<__totally_ordered_less_tag, __remove_cvref_t<_Compare>, value_type, value_type >; + constexpr auto __integral_value = + is_integral_v && is_same_v< value_type&, __iter_reference<_RandomAccessIterator>>; + constexpr auto __allowed_radix_sort = __default_comp && __integral_value; + if constexpr (__allowed_radix_sort) { + if (__len <= __buff_size && __len >= static_cast(__radix_sort_min_bound()) && + __len <= static_cast(__radix_sort_max_bound())) { + std::__radix_sort(__first, __last, __buff); + return; + } + } +#endif // _LIBCPP_STD_VER >= 17 + typename iterator_traits<_RandomAccessIterator>::difference_type __l2 = __len / 2; _RandomAccessIterator __m = __first + __l2; if (__len <= __buff_size) { @@ -235,20 +283,18 @@ void __stable_sort(_RandomAccessIterator __first, } template -inline _LIBCPP_HIDE_FROM_ABI void +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __stable_sort_impl(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare& __comp) { using value_type = typename iterator_traits<_RandomAccessIterator>::value_type; using difference_type = typename iterator_traits<_RandomAccessIterator>::difference_type; difference_type __len = __last - __first; + __unique_temporary_buffer __unique_buf; pair __buf(0, 0); - unique_ptr __h; if (__len > static_cast(__stable_sort_switch::value)) { - // TODO: Remove the use of std::get_temporary_buffer - _LIBCPP_SUPPRESS_DEPRECATED_PUSH - __buf = std::get_temporary_buffer(__len); - _LIBCPP_SUPPRESS_DEPRECATED_POP - __h.reset(__buf.first); + __unique_buf = std::__allocate_unique_temporary_buffer(__len); + __buf.first = __unique_buf.get(); + __buf.second = __unique_buf.get_deleter().__count_; } std::__stable_sort<_AlgPolicy, __comp_ref_type<_Compare> >(__first, __last, __comp, __len, __buf.first, __buf.second); @@ -256,18 +302,18 @@ __stable_sort_impl(_RandomAccessIterator __first, _RandomAccessIterator __last, } template -inline _LIBCPP_HIDE_FROM_ABI void +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { std::__stable_sort_impl<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __comp); } template -inline _LIBCPP_HIDE_FROM_ABI void stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last) { +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void +stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last) { std::stable_sort(__first, __last, __less<>()); } _LIBCPP_END_NAMESPACE_STD - _LIBCPP_POP_MACROS #endif // _LIBCPP___ALGORITHM_STABLE_SORT_H diff --git a/system/lib/libcxx/include/__algorithm/three_way_comp_ref_type.h b/system/lib/libcxx/include/__algorithm/three_way_comp_ref_type.h index 5702a1fee0826..f6f76455e4664 100644 --- a/system/lib/libcxx/include/__algorithm/three_way_comp_ref_type.h +++ b/system/lib/libcxx/include/__algorithm/three_way_comp_ref_type.h @@ -61,10 +61,10 @@ struct __debug_three_way_comp { // Pass the comparator by lvalue reference. Or in the debug mode, using a debugging wrapper that stores a reference. # if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG template -using __three_way_comp_ref_type = __debug_three_way_comp<_Comp>; +using __three_way_comp_ref_type _LIBCPP_NODEBUG = __debug_three_way_comp<_Comp>; # else template -using __three_way_comp_ref_type = _Comp&; +using __three_way_comp_ref_type _LIBCPP_NODEBUG = _Comp&; # endif #endif // _LIBCPP_STD_VER >= 20 diff --git a/system/lib/libcxx/include/__algorithm/uniform_random_bit_generator_adaptor.h b/system/lib/libcxx/include/__algorithm/uniform_random_bit_generator_adaptor.h index aef0fbfb7c284..bc7a8925e1287 100644 --- a/system/lib/libcxx/include/__algorithm/uniform_random_bit_generator_adaptor.h +++ b/system/lib/libcxx/include/__algorithm/uniform_random_bit_generator_adaptor.h @@ -10,7 +10,7 @@ #define _LIBCPP___ALGORITHM_RANGES_UNIFORM_RANDOM_BIT_GENERATOR_ADAPTOR_H #include <__config> -#include <__functional/invoke.h> +#include <__type_traits/invoke.h> #include <__type_traits/remove_cvref.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) diff --git a/system/lib/libcxx/include/__algorithm/unique.h b/system/lib/libcxx/include/__algorithm/unique.h index d597014596f2e..307c424a7c2fb 100644 --- a/system/lib/libcxx/include/__algorithm/unique.h +++ b/system/lib/libcxx/include/__algorithm/unique.h @@ -13,6 +13,7 @@ #include <__algorithm/comp.h> #include <__algorithm/iterator_operations.h> #include <__config> +#include <__functional/identity.h> #include <__iterator/iterator_traits.h> #include <__utility/move.h> #include <__utility/pair.h> @@ -29,9 +30,10 @@ _LIBCPP_BEGIN_NAMESPACE_STD // unique template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 std::pair<_Iter, _Iter> +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 std::pair<_Iter, _Iter> __unique(_Iter __first, _Sent __last, _BinaryPredicate&& __pred) { - __first = std::__adjacent_find(__first, __last, __pred); + __identity __proj; + __first = std::__adjacent_find(__first, __last, __pred, __proj); if (__first != __last) { // ... a a ? ... // f i @@ -46,13 +48,13 @@ __unique(_Iter __first, _Sent __last, _BinaryPredicate&& __pred) { } template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator unique(_ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred) { return std::__unique<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __pred).first; } template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator unique(_ForwardIterator __first, _ForwardIterator __last) { return std::unique(__first, __last, __equal_to()); } diff --git a/system/lib/libcxx/include/__algorithm/unwrap_iter.h b/system/lib/libcxx/include/__algorithm/unwrap_iter.h index 8cc0d22d4fc21..b66a682e765fa 100644 --- a/system/lib/libcxx/include/__algorithm/unwrap_iter.h +++ b/system/lib/libcxx/include/__algorithm/unwrap_iter.h @@ -46,7 +46,7 @@ struct __unwrap_iter_impl { // It's a contiguous iterator, so we can use a raw pointer instead template struct __unwrap_iter_impl<_Iter, true> { - using _ToAddressT = decltype(std::__to_address(std::declval<_Iter>())); + using _ToAddressT _LIBCPP_NODEBUG = decltype(std::__to_address(std::declval<_Iter>())); static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Iter __rewrap(_Iter __orig_iter, _ToAddressT __unwrapped_iter) { return __orig_iter + (__unwrapped_iter - std::__to_address(__orig_iter)); diff --git a/system/lib/libcxx/include/__algorithm/upper_bound.h b/system/lib/libcxx/include/__algorithm/upper_bound.h index c39dec2e89698..d77286c9e5af5 100644 --- a/system/lib/libcxx/include/__algorithm/upper_bound.h +++ b/system/lib/libcxx/include/__algorithm/upper_bound.h @@ -18,6 +18,8 @@ #include <__iterator/advance.h> #include <__iterator/distance.h> #include <__iterator/iterator_traits.h> +#include <__type_traits/invoke.h> +#include <__type_traits/is_callable.h> #include <__type_traits/is_constructible.h> #include <__utility/move.h> @@ -48,15 +50,16 @@ __upper_bound(_Iter __first, _Sent __last, const _Tp& __value, _Compare&& __comp } template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp) { + static_assert(__is_callable<_Compare&, const _Tp&, decltype(*__first)>::value, "The comparator has to be callable"); static_assert(is_copy_constructible<_ForwardIterator>::value, "Iterator has to be copy constructible"); return std::__upper_bound<_ClassicAlgPolicy>( std::move(__first), std::move(__last), __value, std::move(__comp), std::__identity()); } template -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) { return std::upper_bound(std::move(__first), std::move(__last), __value, __less<>()); } diff --git a/system/lib/libcxx/include/__assert b/system/lib/libcxx/include/__assert index 49769fb4d4497..90eaa6023587b 100644 --- a/system/lib/libcxx/include/__assert +++ b/system/lib/libcxx/include/__assert @@ -23,10 +23,10 @@ : _LIBCPP_ASSERTION_HANDLER(__FILE__ ":" _LIBCPP_TOSTRING(__LINE__) ": assertion " _LIBCPP_TOSTRING( \ expression) " failed: " message "\n")) -// TODO: __builtin_assume can currently inhibit optimizations. Until this has been fixed and we can add -// assumptions without a clear optimization intent, disable that to avoid worsening the code generation. -// See https://discourse.llvm.org/t/llvm-assume-blocks-optimization/71609 for a discussion. -#if 0 && __has_builtin(__builtin_assume) +// WARNING: __builtin_assume can currently inhibit optimizations. Only add assumptions with a clear +// optimization intent. See https://discourse.llvm.org/t/llvm-assume-blocks-optimization/71609 for a +// discussion. +#if __has_builtin(__builtin_assume) # define _LIBCPP_ASSUME(expression) \ (_LIBCPP_DIAGNOSTIC_PUSH _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wassume") \ __builtin_assume(static_cast(expression)) _LIBCPP_DIAGNOSTIC_POP) @@ -44,18 +44,18 @@ # define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message) _LIBCPP_ASSERT(expression, message) // Disabled checks. // On most modern platforms, dereferencing a null pointer does not lead to an actual memory access. -# define _LIBCPP_ASSERT_NON_NULL(expression, message) _LIBCPP_ASSUME(expression) +# define _LIBCPP_ASSERT_NON_NULL(expression, message) ((void)0) // Overlapping ranges will make algorithms produce incorrect results but don't directly lead to a security // vulnerability. -# define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message) _LIBCPP_ASSUME(expression) -# define _LIBCPP_ASSERT_VALID_DEALLOCATION(expression, message) _LIBCPP_ASSUME(expression) -# define _LIBCPP_ASSERT_VALID_EXTERNAL_API_CALL(expression, message) _LIBCPP_ASSUME(expression) -# define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message) _LIBCPP_ASSUME(expression) -# define _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(expression, message) _LIBCPP_ASSUME(expression) -# define _LIBCPP_ASSERT_PEDANTIC(expression, message) _LIBCPP_ASSUME(expression) -# define _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(expression, message) _LIBCPP_ASSUME(expression) -# define _LIBCPP_ASSERT_INTERNAL(expression, message) _LIBCPP_ASSUME(expression) -# define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) _LIBCPP_ASSUME(expression) +# define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message) ((void)0) +# define _LIBCPP_ASSERT_VALID_DEALLOCATION(expression, message) ((void)0) +# define _LIBCPP_ASSERT_VALID_EXTERNAL_API_CALL(expression, message) ((void)0) +# define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message) ((void)0) +# define _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(expression, message) ((void)0) +# define _LIBCPP_ASSERT_PEDANTIC(expression, message) ((void)0) +# define _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(expression, message) ((void)0) +# define _LIBCPP_ASSERT_INTERNAL(expression, message) ((void)0) +# define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) ((void)0) // Extensive hardening mode checks. @@ -73,8 +73,8 @@ # define _LIBCPP_ASSERT_PEDANTIC(expression, message) _LIBCPP_ASSERT(expression, message) # define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) _LIBCPP_ASSERT(expression, message) // Disabled checks. -# define _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(expression, message) _LIBCPP_ASSUME(expression) -# define _LIBCPP_ASSERT_INTERNAL(expression, message) _LIBCPP_ASSUME(expression) +# define _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(expression, message) ((void)0) +# define _LIBCPP_ASSERT_INTERNAL(expression, message) ((void)0) // Debug hardening mode checks. @@ -99,18 +99,18 @@ #else // All checks disabled. -# define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message) _LIBCPP_ASSUME(expression) -# define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message) _LIBCPP_ASSUME(expression) -# define _LIBCPP_ASSERT_NON_NULL(expression, message) _LIBCPP_ASSUME(expression) -# define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message) _LIBCPP_ASSUME(expression) -# define _LIBCPP_ASSERT_VALID_DEALLOCATION(expression, message) _LIBCPP_ASSUME(expression) -# define _LIBCPP_ASSERT_VALID_EXTERNAL_API_CALL(expression, message) _LIBCPP_ASSUME(expression) -# define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message) _LIBCPP_ASSUME(expression) -# define _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(expression, message) _LIBCPP_ASSUME(expression) -# define _LIBCPP_ASSERT_PEDANTIC(expression, message) _LIBCPP_ASSUME(expression) -# define _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(expression, message) _LIBCPP_ASSUME(expression) -# define _LIBCPP_ASSERT_INTERNAL(expression, message) _LIBCPP_ASSUME(expression) -# define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) _LIBCPP_ASSUME(expression) +# define _LIBCPP_ASSERT_VALID_INPUT_RANGE(expression, message) ((void)0) +# define _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(expression, message) ((void)0) +# define _LIBCPP_ASSERT_NON_NULL(expression, message) ((void)0) +# define _LIBCPP_ASSERT_NON_OVERLAPPING_RANGES(expression, message) ((void)0) +# define _LIBCPP_ASSERT_VALID_DEALLOCATION(expression, message) ((void)0) +# define _LIBCPP_ASSERT_VALID_EXTERNAL_API_CALL(expression, message) ((void)0) +# define _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(expression, message) ((void)0) +# define _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(expression, message) ((void)0) +# define _LIBCPP_ASSERT_PEDANTIC(expression, message) ((void)0) +# define _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(expression, message) ((void)0) +# define _LIBCPP_ASSERT_INTERNAL(expression, message) ((void)0) +# define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) ((void)0) #endif // _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_FAST // clang-format on diff --git a/system/lib/libcxx/include/__assertion_handler b/system/lib/libcxx/include/__assertion_handler index e12ccccdaff37..1d6b21fc6bb45 100644 --- a/system/lib/libcxx/include/__assertion_handler +++ b/system/lib/libcxx/include/__assertion_handler @@ -10,8 +10,13 @@ #ifndef _LIBCPP___ASSERTION_HANDLER #define _LIBCPP___ASSERTION_HANDLER -#include <__config> -#include <__verbose_abort> +#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS) +# include <__cxx03/__config> +# include <__cxx03/__verbose_abort> +#else +# include <__config> +# include <__verbose_abort> +#endif #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/system/lib/libcxx/include/__atomic/aliases.h b/system/lib/libcxx/include/__atomic/aliases.h index e27e09af6b77d..4fccebab25636 100644 --- a/system/lib/libcxx/include/__atomic/aliases.h +++ b/system/lib/libcxx/include/__atomic/aliases.h @@ -14,9 +14,10 @@ #include <__atomic/contention_t.h> #include <__atomic/is_always_lock_free.h> #include <__config> +#include <__cstddef/ptrdiff_t.h> +#include <__cstddef/size_t.h> #include <__type_traits/conditional.h> #include <__type_traits/make_unsigned.h> -#include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -37,12 +38,12 @@ using atomic_long = atomic; using atomic_ulong = atomic; using atomic_llong = atomic; using atomic_ullong = atomic; -#ifndef _LIBCPP_HAS_NO_CHAR8_T +#if _LIBCPP_HAS_CHAR8_T using atomic_char8_t = atomic; #endif using atomic_char16_t = atomic; using atomic_char32_t = atomic; -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +#if _LIBCPP_HAS_WIDE_CHARACTERS using atomic_wchar_t = atomic; #endif @@ -83,19 +84,19 @@ using atomic_uintmax_t = atomic; // C++20 atomic_{signed,unsigned}_lock_free: prefer the contention type most highly, then the largest lock-free type #if _LIBCPP_STD_VER >= 20 # if ATOMIC_LLONG_LOCK_FREE == 2 -using __largest_lock_free_type = long long; +using __largest_lock_free_type _LIBCPP_NODEBUG = long long; # elif ATOMIC_INT_LOCK_FREE == 2 -using __largest_lock_free_type = int; +using __largest_lock_free_type _LIBCPP_NODEBUG = int; # elif ATOMIC_SHORT_LOCK_FREE == 2 -using __largest_lock_free_type = short; +using __largest_lock_free_type _LIBCPP_NODEBUG = short; # elif ATOMIC_CHAR_LOCK_FREE == 2 -using __largest_lock_free_type = char; +using __largest_lock_free_type _LIBCPP_NODEBUG = char; # else # define _LIBCPP_NO_LOCK_FREE_TYPES // There are no lockfree types (this can happen on unusual platforms) # endif # ifndef _LIBCPP_NO_LOCK_FREE_TYPES -using __contention_t_or_largest = +using __contention_t_or_largest _LIBCPP_NODEBUG = __conditional_t<__libcpp_is_always_lock_free<__cxx_contention_t>::__value, __cxx_contention_t, __largest_lock_free_type>; diff --git a/system/lib/libcxx/include/__atomic/atomic.h b/system/lib/libcxx/include/__atomic/atomic.h index bd3f659c22df0..975a479e20400 100644 --- a/system/lib/libcxx/include/__atomic/atomic.h +++ b/system/lib/libcxx/include/__atomic/atomic.h @@ -9,21 +9,24 @@ #ifndef _LIBCPP___ATOMIC_ATOMIC_H #define _LIBCPP___ATOMIC_ATOMIC_H -#include <__atomic/atomic_base.h> +#include <__atomic/atomic_sync.h> #include <__atomic/check_memory_order.h> -#include <__atomic/cxx_atomic_impl.h> +#include <__atomic/is_always_lock_free.h> #include <__atomic/memory_order.h> +#include <__atomic/support.h> #include <__config> -#include <__functional/operations.h> +#include <__cstddef/ptrdiff_t.h> #include <__memory/addressof.h> +#include <__type_traits/enable_if.h> #include <__type_traits/is_floating_point.h> #include <__type_traits/is_function.h> +#include <__type_traits/is_integral.h> +#include <__type_traits/is_nothrow_constructible.h> #include <__type_traits/is_same.h> #include <__type_traits/remove_const.h> #include <__type_traits/remove_pointer.h> #include <__type_traits/remove_volatile.h> #include <__utility/forward.h> -#include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -32,11 +35,202 @@ _LIBCPP_BEGIN_NAMESPACE_STD +template ::value && !is_same<_Tp, bool>::value> +struct __atomic_base // false +{ + mutable __cxx_atomic_impl<_Tp> __a_; + +#if _LIBCPP_STD_VER >= 17 + static constexpr bool is_always_lock_free = __libcpp_is_always_lock_free<__cxx_atomic_impl<_Tp> >::__value; +#endif + + _LIBCPP_HIDE_FROM_ABI bool is_lock_free() const volatile _NOEXCEPT { + return __cxx_atomic_is_lock_free(sizeof(__cxx_atomic_impl<_Tp>)); + } + _LIBCPP_HIDE_FROM_ABI bool is_lock_free() const _NOEXCEPT { + return static_cast<__atomic_base const volatile*>(this)->is_lock_free(); + } + _LIBCPP_HIDE_FROM_ABI void store(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT + _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) { + std::__cxx_atomic_store(std::addressof(__a_), __d, __m); + } + _LIBCPP_HIDE_FROM_ABI void store(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT + _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) { + std::__cxx_atomic_store(std::addressof(__a_), __d, __m); + } + _LIBCPP_HIDE_FROM_ABI _Tp load(memory_order __m = memory_order_seq_cst) const volatile _NOEXCEPT + _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) { + return std::__cxx_atomic_load(std::addressof(__a_), __m); + } + _LIBCPP_HIDE_FROM_ABI _Tp load(memory_order __m = memory_order_seq_cst) const _NOEXCEPT + _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) { + return std::__cxx_atomic_load(std::addressof(__a_), __m); + } + _LIBCPP_HIDE_FROM_ABI operator _Tp() const volatile _NOEXCEPT { return load(); } + _LIBCPP_HIDE_FROM_ABI operator _Tp() const _NOEXCEPT { return load(); } + _LIBCPP_HIDE_FROM_ABI _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { + return std::__cxx_atomic_exchange(std::addressof(__a_), __d, __m); + } + _LIBCPP_HIDE_FROM_ABI _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT { + return std::__cxx_atomic_exchange(std::addressof(__a_), __d, __m); + } + _LIBCPP_HIDE_FROM_ABI bool + compare_exchange_weak(_Tp& __e, _Tp __d, memory_order __s, memory_order __f) volatile _NOEXCEPT + _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) { + return std::__cxx_atomic_compare_exchange_weak(std::addressof(__a_), std::addressof(__e), __d, __s, __f); + } + _LIBCPP_HIDE_FROM_ABI bool compare_exchange_weak(_Tp& __e, _Tp __d, memory_order __s, memory_order __f) _NOEXCEPT + _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) { + return std::__cxx_atomic_compare_exchange_weak(std::addressof(__a_), std::addressof(__e), __d, __s, __f); + } + _LIBCPP_HIDE_FROM_ABI bool + compare_exchange_strong(_Tp& __e, _Tp __d, memory_order __s, memory_order __f) volatile _NOEXCEPT + _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) { + return std::__cxx_atomic_compare_exchange_strong(std::addressof(__a_), std::addressof(__e), __d, __s, __f); + } + _LIBCPP_HIDE_FROM_ABI bool compare_exchange_strong(_Tp& __e, _Tp __d, memory_order __s, memory_order __f) _NOEXCEPT + _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) { + return std::__cxx_atomic_compare_exchange_strong(std::addressof(__a_), std::addressof(__e), __d, __s, __f); + } + _LIBCPP_HIDE_FROM_ABI bool + compare_exchange_weak(_Tp& __e, _Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { + return std::__cxx_atomic_compare_exchange_weak(std::addressof(__a_), std::addressof(__e), __d, __m, __m); + } + _LIBCPP_HIDE_FROM_ABI bool + compare_exchange_weak(_Tp& __e, _Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT { + return std::__cxx_atomic_compare_exchange_weak(std::addressof(__a_), std::addressof(__e), __d, __m, __m); + } + _LIBCPP_HIDE_FROM_ABI bool + compare_exchange_strong(_Tp& __e, _Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { + return std::__cxx_atomic_compare_exchange_strong(std::addressof(__a_), std::addressof(__e), __d, __m, __m); + } + _LIBCPP_HIDE_FROM_ABI bool + compare_exchange_strong(_Tp& __e, _Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT { + return std::__cxx_atomic_compare_exchange_strong(std::addressof(__a_), std::addressof(__e), __d, __m, __m); + } + +#if _LIBCPP_STD_VER >= 20 + _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void wait(_Tp __v, memory_order __m = memory_order_seq_cst) const + volatile _NOEXCEPT { + std::__atomic_wait(*this, __v, __m); + } + _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void + wait(_Tp __v, memory_order __m = memory_order_seq_cst) const _NOEXCEPT { + std::__atomic_wait(*this, __v, __m); + } + _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void notify_one() volatile _NOEXCEPT { + std::__atomic_notify_one(*this); + } + _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void notify_one() _NOEXCEPT { std::__atomic_notify_one(*this); } + _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void notify_all() volatile _NOEXCEPT { + std::__atomic_notify_all(*this); + } + _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void notify_all() _NOEXCEPT { std::__atomic_notify_all(*this); } +#endif // _LIBCPP_STD_VER >= 20 + +#if _LIBCPP_STD_VER >= 20 + _LIBCPP_HIDE_FROM_ABI constexpr __atomic_base() noexcept(is_nothrow_default_constructible_v<_Tp>) : __a_(_Tp()) {} +#else + _LIBCPP_HIDE_FROM_ABI __atomic_base() _NOEXCEPT = default; +#endif + + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __a_(__d) {} + + __atomic_base(const __atomic_base&) = delete; +}; + +// atomic + +template +struct __atomic_base<_Tp, true> : public __atomic_base<_Tp, false> { + using __base _LIBCPP_NODEBUG = __atomic_base<_Tp, false>; + + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __atomic_base() _NOEXCEPT = default; + + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __base(__d) {} + + _LIBCPP_HIDE_FROM_ABI _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { + return std::__cxx_atomic_fetch_add(std::addressof(this->__a_), __op, __m); + } + _LIBCPP_HIDE_FROM_ABI _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT { + return std::__cxx_atomic_fetch_add(std::addressof(this->__a_), __op, __m); + } + _LIBCPP_HIDE_FROM_ABI _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { + return std::__cxx_atomic_fetch_sub(std::addressof(this->__a_), __op, __m); + } + _LIBCPP_HIDE_FROM_ABI _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT { + return std::__cxx_atomic_fetch_sub(std::addressof(this->__a_), __op, __m); + } + _LIBCPP_HIDE_FROM_ABI _Tp fetch_and(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { + return std::__cxx_atomic_fetch_and(std::addressof(this->__a_), __op, __m); + } + _LIBCPP_HIDE_FROM_ABI _Tp fetch_and(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT { + return std::__cxx_atomic_fetch_and(std::addressof(this->__a_), __op, __m); + } + _LIBCPP_HIDE_FROM_ABI _Tp fetch_or(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { + return std::__cxx_atomic_fetch_or(std::addressof(this->__a_), __op, __m); + } + _LIBCPP_HIDE_FROM_ABI _Tp fetch_or(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT { + return std::__cxx_atomic_fetch_or(std::addressof(this->__a_), __op, __m); + } + _LIBCPP_HIDE_FROM_ABI _Tp fetch_xor(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { + return std::__cxx_atomic_fetch_xor(std::addressof(this->__a_), __op, __m); + } + _LIBCPP_HIDE_FROM_ABI _Tp fetch_xor(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT { + return std::__cxx_atomic_fetch_xor(std::addressof(this->__a_), __op, __m); + } + + _LIBCPP_HIDE_FROM_ABI _Tp operator++(int) volatile _NOEXCEPT { return fetch_add(_Tp(1)); } + _LIBCPP_HIDE_FROM_ABI _Tp operator++(int) _NOEXCEPT { return fetch_add(_Tp(1)); } + _LIBCPP_HIDE_FROM_ABI _Tp operator--(int) volatile _NOEXCEPT { return fetch_sub(_Tp(1)); } + _LIBCPP_HIDE_FROM_ABI _Tp operator--(int) _NOEXCEPT { return fetch_sub(_Tp(1)); } + _LIBCPP_HIDE_FROM_ABI _Tp operator++() volatile _NOEXCEPT { return fetch_add(_Tp(1)) + _Tp(1); } + _LIBCPP_HIDE_FROM_ABI _Tp operator++() _NOEXCEPT { return fetch_add(_Tp(1)) + _Tp(1); } + _LIBCPP_HIDE_FROM_ABI _Tp operator--() volatile _NOEXCEPT { return fetch_sub(_Tp(1)) - _Tp(1); } + _LIBCPP_HIDE_FROM_ABI _Tp operator--() _NOEXCEPT { return fetch_sub(_Tp(1)) - _Tp(1); } + _LIBCPP_HIDE_FROM_ABI _Tp operator+=(_Tp __op) volatile _NOEXCEPT { return fetch_add(__op) + __op; } + _LIBCPP_HIDE_FROM_ABI _Tp operator+=(_Tp __op) _NOEXCEPT { return fetch_add(__op) + __op; } + _LIBCPP_HIDE_FROM_ABI _Tp operator-=(_Tp __op) volatile _NOEXCEPT { return fetch_sub(__op) - __op; } + _LIBCPP_HIDE_FROM_ABI _Tp operator-=(_Tp __op) _NOEXCEPT { return fetch_sub(__op) - __op; } + _LIBCPP_HIDE_FROM_ABI _Tp operator&=(_Tp __op) volatile _NOEXCEPT { return fetch_and(__op) & __op; } + _LIBCPP_HIDE_FROM_ABI _Tp operator&=(_Tp __op) _NOEXCEPT { return fetch_and(__op) & __op; } + _LIBCPP_HIDE_FROM_ABI _Tp operator|=(_Tp __op) volatile _NOEXCEPT { return fetch_or(__op) | __op; } + _LIBCPP_HIDE_FROM_ABI _Tp operator|=(_Tp __op) _NOEXCEPT { return fetch_or(__op) | __op; } + _LIBCPP_HIDE_FROM_ABI _Tp operator^=(_Tp __op) volatile _NOEXCEPT { return fetch_xor(__op) ^ __op; } + _LIBCPP_HIDE_FROM_ABI _Tp operator^=(_Tp __op) _NOEXCEPT { return fetch_xor(__op) ^ __op; } +}; + +// Here we need _IsIntegral because the default template argument is not enough +// e.g __atomic_base is __atomic_base, which inherits from +// __atomic_base and the caller of the wait function is +// __atomic_base. So specializing __atomic_base<_Tp> does not work +template +struct __atomic_waitable_traits<__atomic_base<_Tp, _IsIntegral> > { + static _LIBCPP_HIDE_FROM_ABI _Tp __atomic_load(const __atomic_base<_Tp, _IsIntegral>& __a, memory_order __order) { + return __a.load(__order); + } + + static _LIBCPP_HIDE_FROM_ABI _Tp + __atomic_load(const volatile __atomic_base<_Tp, _IsIntegral>& __this, memory_order __order) { + return __this.load(__order); + } + + static _LIBCPP_HIDE_FROM_ABI const __cxx_atomic_impl<_Tp>* + __atomic_contention_address(const __atomic_base<_Tp, _IsIntegral>& __a) { + return std::addressof(__a.__a_); + } + + static _LIBCPP_HIDE_FROM_ABI const volatile __cxx_atomic_impl<_Tp>* + __atomic_contention_address(const volatile __atomic_base<_Tp, _IsIntegral>& __this) { + return std::addressof(__this.__a_); + } +}; + template struct atomic : public __atomic_base<_Tp> { - using __base = __atomic_base<_Tp>; - using value_type = _Tp; - using difference_type = value_type; + using __base _LIBCPP_NODEBUG = __atomic_base<_Tp>; + using value_type = _Tp; + using difference_type = value_type; #if _LIBCPP_STD_VER >= 20 _LIBCPP_HIDE_FROM_ABI atomic() = default; @@ -63,9 +257,9 @@ struct atomic : public __atomic_base<_Tp> { template struct atomic<_Tp*> : public __atomic_base<_Tp*> { - using __base = __atomic_base<_Tp*>; - using value_type = _Tp*; - using difference_type = ptrdiff_t; + using __base _LIBCPP_NODEBUG = __atomic_base<_Tp*>; + using value_type = _Tp*; + using difference_type = ptrdiff_t; _LIBCPP_HIDE_FROM_ABI atomic() _NOEXCEPT = default; @@ -121,6 +315,9 @@ struct atomic<_Tp*> : public __atomic_base<_Tp*> { atomic& operator=(const atomic&) volatile = delete; }; +template +struct __atomic_waitable_traits > : __atomic_waitable_traits<__atomic_base<_Tp> > {}; + #if _LIBCPP_STD_VER >= 20 template requires is_floating_point_v<_Tp> @@ -178,7 +375,8 @@ struct atomic<_Tp> : __atomic_base<_Tp> { auto __builtin_op = [](auto __a, auto __builtin_operand, auto __order) { return std::__cxx_atomic_fetch_add(__a, __builtin_operand, __order); }; - return __rmw_op(std::forward<_This>(__self), __operand, __m, std::plus<>{}, __builtin_op); + auto __plus = [](auto __a, auto __b) { return __a + __b; }; + return __rmw_op(std::forward<_This>(__self), __operand, __m, __plus, __builtin_op); } template @@ -186,13 +384,14 @@ struct atomic<_Tp> : __atomic_base<_Tp> { auto __builtin_op = [](auto __a, auto __builtin_operand, auto __order) { return std::__cxx_atomic_fetch_sub(__a, __builtin_operand, __order); }; - return __rmw_op(std::forward<_This>(__self), __operand, __m, std::minus<>{}, __builtin_op); + auto __minus = [](auto __a, auto __b) { return __a - __b; }; + return __rmw_op(std::forward<_This>(__self), __operand, __m, __minus, __builtin_op); } public: - using __base = __atomic_base<_Tp>; - using value_type = _Tp; - using difference_type = value_type; + using __base _LIBCPP_NODEBUG = __atomic_base<_Tp>; + using value_type = _Tp; + using difference_type = value_type; _LIBCPP_HIDE_FROM_ABI constexpr atomic() noexcept = default; _LIBCPP_HIDE_FROM_ABI constexpr atomic(_Tp __d) noexcept : __base(__d) {} @@ -429,6 +628,8 @@ _LIBCPP_HIDE_FROM_ABI bool atomic_compare_exchange_strong_explicit( return __o->compare_exchange_strong(*__e, __d, __s, __f); } +#if _LIBCPP_STD_VER >= 20 + // atomic_wait template @@ -462,29 +663,27 @@ atomic_wait_explicit(const atomic<_Tp>* __o, typename atomic<_Tp>::value_type __ // atomic_notify_one template -_LIBCPP_DEPRECATED_ATOMIC_SYNC _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void -atomic_notify_one(volatile atomic<_Tp>* __o) _NOEXCEPT { +_LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void atomic_notify_one(volatile atomic<_Tp>* __o) _NOEXCEPT { __o->notify_one(); } template -_LIBCPP_DEPRECATED_ATOMIC_SYNC _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void -atomic_notify_one(atomic<_Tp>* __o) _NOEXCEPT { +_LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void atomic_notify_one(atomic<_Tp>* __o) _NOEXCEPT { __o->notify_one(); } // atomic_notify_all template -_LIBCPP_DEPRECATED_ATOMIC_SYNC _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void -atomic_notify_all(volatile atomic<_Tp>* __o) _NOEXCEPT { +_LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void atomic_notify_all(volatile atomic<_Tp>* __o) _NOEXCEPT { __o->notify_all(); } template -_LIBCPP_DEPRECATED_ATOMIC_SYNC _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void -atomic_notify_all(atomic<_Tp>* __o) _NOEXCEPT { +_LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void atomic_notify_all(atomic<_Tp>* __o) _NOEXCEPT { __o->notify_all(); } +#endif // _LIBCPP_STD_VER >= 20 + // atomic_fetch_add template diff --git a/system/lib/libcxx/include/__atomic/atomic_base.h b/system/lib/libcxx/include/__atomic/atomic_base.h deleted file mode 100644 index 7e26434c9c3a0..0000000000000 --- a/system/lib/libcxx/include/__atomic/atomic_base.h +++ /dev/null @@ -1,221 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___ATOMIC_ATOMIC_BASE_H -#define _LIBCPP___ATOMIC_ATOMIC_BASE_H - -#include <__atomic/atomic_sync.h> -#include <__atomic/check_memory_order.h> -#include <__atomic/cxx_atomic_impl.h> -#include <__atomic/is_always_lock_free.h> -#include <__atomic/memory_order.h> -#include <__config> -#include <__memory/addressof.h> -#include <__type_traits/is_integral.h> -#include <__type_traits/is_nothrow_constructible.h> -#include <__type_traits/is_same.h> -#include - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -template ::value && !is_same<_Tp, bool>::value> -struct __atomic_base // false -{ - mutable __cxx_atomic_impl<_Tp> __a_; - -#if _LIBCPP_STD_VER >= 17 - static constexpr bool is_always_lock_free = __libcpp_is_always_lock_free<__cxx_atomic_impl<_Tp> >::__value; -#endif - - _LIBCPP_HIDE_FROM_ABI bool is_lock_free() const volatile _NOEXCEPT { - return __cxx_atomic_is_lock_free(sizeof(__cxx_atomic_impl<_Tp>)); - } - _LIBCPP_HIDE_FROM_ABI bool is_lock_free() const _NOEXCEPT { - return static_cast<__atomic_base const volatile*>(this)->is_lock_free(); - } - _LIBCPP_HIDE_FROM_ABI void store(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT - _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) { - std::__cxx_atomic_store(std::addressof(__a_), __d, __m); - } - _LIBCPP_HIDE_FROM_ABI void store(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT - _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) { - std::__cxx_atomic_store(std::addressof(__a_), __d, __m); - } - _LIBCPP_HIDE_FROM_ABI _Tp load(memory_order __m = memory_order_seq_cst) const volatile _NOEXCEPT - _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) { - return std::__cxx_atomic_load(std::addressof(__a_), __m); - } - _LIBCPP_HIDE_FROM_ABI _Tp load(memory_order __m = memory_order_seq_cst) const _NOEXCEPT - _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) { - return std::__cxx_atomic_load(std::addressof(__a_), __m); - } - _LIBCPP_HIDE_FROM_ABI operator _Tp() const volatile _NOEXCEPT { return load(); } - _LIBCPP_HIDE_FROM_ABI operator _Tp() const _NOEXCEPT { return load(); } - _LIBCPP_HIDE_FROM_ABI _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { - return std::__cxx_atomic_exchange(std::addressof(__a_), __d, __m); - } - _LIBCPP_HIDE_FROM_ABI _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT { - return std::__cxx_atomic_exchange(std::addressof(__a_), __d, __m); - } - _LIBCPP_HIDE_FROM_ABI bool - compare_exchange_weak(_Tp& __e, _Tp __d, memory_order __s, memory_order __f) volatile _NOEXCEPT - _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) { - return std::__cxx_atomic_compare_exchange_weak(std::addressof(__a_), std::addressof(__e), __d, __s, __f); - } - _LIBCPP_HIDE_FROM_ABI bool compare_exchange_weak(_Tp& __e, _Tp __d, memory_order __s, memory_order __f) _NOEXCEPT - _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) { - return std::__cxx_atomic_compare_exchange_weak(std::addressof(__a_), std::addressof(__e), __d, __s, __f); - } - _LIBCPP_HIDE_FROM_ABI bool - compare_exchange_strong(_Tp& __e, _Tp __d, memory_order __s, memory_order __f) volatile _NOEXCEPT - _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) { - return std::__cxx_atomic_compare_exchange_strong(std::addressof(__a_), std::addressof(__e), __d, __s, __f); - } - _LIBCPP_HIDE_FROM_ABI bool compare_exchange_strong(_Tp& __e, _Tp __d, memory_order __s, memory_order __f) _NOEXCEPT - _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) { - return std::__cxx_atomic_compare_exchange_strong(std::addressof(__a_), std::addressof(__e), __d, __s, __f); - } - _LIBCPP_HIDE_FROM_ABI bool - compare_exchange_weak(_Tp& __e, _Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { - return std::__cxx_atomic_compare_exchange_weak(std::addressof(__a_), std::addressof(__e), __d, __m, __m); - } - _LIBCPP_HIDE_FROM_ABI bool - compare_exchange_weak(_Tp& __e, _Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT { - return std::__cxx_atomic_compare_exchange_weak(std::addressof(__a_), std::addressof(__e), __d, __m, __m); - } - _LIBCPP_HIDE_FROM_ABI bool - compare_exchange_strong(_Tp& __e, _Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { - return std::__cxx_atomic_compare_exchange_strong(std::addressof(__a_), std::addressof(__e), __d, __m, __m); - } - _LIBCPP_HIDE_FROM_ABI bool - compare_exchange_strong(_Tp& __e, _Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT { - return std::__cxx_atomic_compare_exchange_strong(std::addressof(__a_), std::addressof(__e), __d, __m, __m); - } - - _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void wait(_Tp __v, memory_order __m = memory_order_seq_cst) const - volatile _NOEXCEPT { - std::__atomic_wait(*this, __v, __m); - } - _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void - wait(_Tp __v, memory_order __m = memory_order_seq_cst) const _NOEXCEPT { - std::__atomic_wait(*this, __v, __m); - } - _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void notify_one() volatile _NOEXCEPT { - std::__atomic_notify_one(*this); - } - _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void notify_one() _NOEXCEPT { std::__atomic_notify_one(*this); } - _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void notify_all() volatile _NOEXCEPT { - std::__atomic_notify_all(*this); - } - _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void notify_all() _NOEXCEPT { std::__atomic_notify_all(*this); } - -#if _LIBCPP_STD_VER >= 20 - _LIBCPP_HIDE_FROM_ABI constexpr __atomic_base() noexcept(is_nothrow_default_constructible_v<_Tp>) : __a_(_Tp()) {} -#else - _LIBCPP_HIDE_FROM_ABI __atomic_base() _NOEXCEPT = default; -#endif - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __a_(__d) {} - - __atomic_base(const __atomic_base&) = delete; -}; - -// atomic - -template -struct __atomic_base<_Tp, true> : public __atomic_base<_Tp, false> { - using __base = __atomic_base<_Tp, false>; - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __atomic_base() _NOEXCEPT = default; - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __base(__d) {} - - _LIBCPP_HIDE_FROM_ABI _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { - return std::__cxx_atomic_fetch_add(std::addressof(this->__a_), __op, __m); - } - _LIBCPP_HIDE_FROM_ABI _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT { - return std::__cxx_atomic_fetch_add(std::addressof(this->__a_), __op, __m); - } - _LIBCPP_HIDE_FROM_ABI _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { - return std::__cxx_atomic_fetch_sub(std::addressof(this->__a_), __op, __m); - } - _LIBCPP_HIDE_FROM_ABI _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT { - return std::__cxx_atomic_fetch_sub(std::addressof(this->__a_), __op, __m); - } - _LIBCPP_HIDE_FROM_ABI _Tp fetch_and(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { - return std::__cxx_atomic_fetch_and(std::addressof(this->__a_), __op, __m); - } - _LIBCPP_HIDE_FROM_ABI _Tp fetch_and(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT { - return std::__cxx_atomic_fetch_and(std::addressof(this->__a_), __op, __m); - } - _LIBCPP_HIDE_FROM_ABI _Tp fetch_or(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { - return std::__cxx_atomic_fetch_or(std::addressof(this->__a_), __op, __m); - } - _LIBCPP_HIDE_FROM_ABI _Tp fetch_or(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT { - return std::__cxx_atomic_fetch_or(std::addressof(this->__a_), __op, __m); - } - _LIBCPP_HIDE_FROM_ABI _Tp fetch_xor(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT { - return std::__cxx_atomic_fetch_xor(std::addressof(this->__a_), __op, __m); - } - _LIBCPP_HIDE_FROM_ABI _Tp fetch_xor(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT { - return std::__cxx_atomic_fetch_xor(std::addressof(this->__a_), __op, __m); - } - - _LIBCPP_HIDE_FROM_ABI _Tp operator++(int) volatile _NOEXCEPT { return fetch_add(_Tp(1)); } - _LIBCPP_HIDE_FROM_ABI _Tp operator++(int) _NOEXCEPT { return fetch_add(_Tp(1)); } - _LIBCPP_HIDE_FROM_ABI _Tp operator--(int) volatile _NOEXCEPT { return fetch_sub(_Tp(1)); } - _LIBCPP_HIDE_FROM_ABI _Tp operator--(int) _NOEXCEPT { return fetch_sub(_Tp(1)); } - _LIBCPP_HIDE_FROM_ABI _Tp operator++() volatile _NOEXCEPT { return fetch_add(_Tp(1)) + _Tp(1); } - _LIBCPP_HIDE_FROM_ABI _Tp operator++() _NOEXCEPT { return fetch_add(_Tp(1)) + _Tp(1); } - _LIBCPP_HIDE_FROM_ABI _Tp operator--() volatile _NOEXCEPT { return fetch_sub(_Tp(1)) - _Tp(1); } - _LIBCPP_HIDE_FROM_ABI _Tp operator--() _NOEXCEPT { return fetch_sub(_Tp(1)) - _Tp(1); } - _LIBCPP_HIDE_FROM_ABI _Tp operator+=(_Tp __op) volatile _NOEXCEPT { return fetch_add(__op) + __op; } - _LIBCPP_HIDE_FROM_ABI _Tp operator+=(_Tp __op) _NOEXCEPT { return fetch_add(__op) + __op; } - _LIBCPP_HIDE_FROM_ABI _Tp operator-=(_Tp __op) volatile _NOEXCEPT { return fetch_sub(__op) - __op; } - _LIBCPP_HIDE_FROM_ABI _Tp operator-=(_Tp __op) _NOEXCEPT { return fetch_sub(__op) - __op; } - _LIBCPP_HIDE_FROM_ABI _Tp operator&=(_Tp __op) volatile _NOEXCEPT { return fetch_and(__op) & __op; } - _LIBCPP_HIDE_FROM_ABI _Tp operator&=(_Tp __op) _NOEXCEPT { return fetch_and(__op) & __op; } - _LIBCPP_HIDE_FROM_ABI _Tp operator|=(_Tp __op) volatile _NOEXCEPT { return fetch_or(__op) | __op; } - _LIBCPP_HIDE_FROM_ABI _Tp operator|=(_Tp __op) _NOEXCEPT { return fetch_or(__op) | __op; } - _LIBCPP_HIDE_FROM_ABI _Tp operator^=(_Tp __op) volatile _NOEXCEPT { return fetch_xor(__op) ^ __op; } - _LIBCPP_HIDE_FROM_ABI _Tp operator^=(_Tp __op) _NOEXCEPT { return fetch_xor(__op) ^ __op; } -}; - -// Here we need _IsIntegral because the default template argument is not enough -// e.g __atomic_base is __atomic_base, which inherits from -// __atomic_base and the caller of the wait function is -// __atomic_base. So specializing __atomic_base<_Tp> does not work -template -struct __atomic_waitable_traits<__atomic_base<_Tp, _IsIntegral> > { - static _LIBCPP_HIDE_FROM_ABI _Tp __atomic_load(const __atomic_base<_Tp, _IsIntegral>& __a, memory_order __order) { - return __a.load(__order); - } - - static _LIBCPP_HIDE_FROM_ABI _Tp - __atomic_load(const volatile __atomic_base<_Tp, _IsIntegral>& __this, memory_order __order) { - return __this.load(__order); - } - - static _LIBCPP_HIDE_FROM_ABI const __cxx_atomic_impl<_Tp>* - __atomic_contention_address(const __atomic_base<_Tp, _IsIntegral>& __a) { - return std::addressof(__a.__a_); - } - - static _LIBCPP_HIDE_FROM_ABI const volatile __cxx_atomic_impl<_Tp>* - __atomic_contention_address(const volatile __atomic_base<_Tp, _IsIntegral>& __this) { - return std::addressof(__this.__a_); - } -}; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___ATOMIC_ATOMIC_BASE_H diff --git a/system/lib/libcxx/include/__atomic/atomic_flag.h b/system/lib/libcxx/include/__atomic/atomic_flag.h index 00b157cdff78b..5cc6fb0c55d09 100644 --- a/system/lib/libcxx/include/__atomic/atomic_flag.h +++ b/system/lib/libcxx/include/__atomic/atomic_flag.h @@ -11,8 +11,8 @@ #include <__atomic/atomic_sync.h> #include <__atomic/contention_t.h> -#include <__atomic/cxx_atomic_impl.h> #include <__atomic/memory_order.h> +#include <__atomic/support.h> #include <__chrono/duration.h> #include <__config> #include <__memory/addressof.h> @@ -48,26 +48,24 @@ struct atomic_flag { __cxx_atomic_store(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(false), __m); } - _LIBCPP_DEPRECATED_ATOMIC_SYNC _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void - wait(bool __v, memory_order __m = memory_order_seq_cst) const volatile _NOEXCEPT { +#if _LIBCPP_STD_VER >= 20 + _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void wait(bool __v, memory_order __m = memory_order_seq_cst) const + volatile _NOEXCEPT { std::__atomic_wait(*this, _LIBCPP_ATOMIC_FLAG_TYPE(__v), __m); } - _LIBCPP_DEPRECATED_ATOMIC_SYNC _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void + _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void wait(bool __v, memory_order __m = memory_order_seq_cst) const _NOEXCEPT { std::__atomic_wait(*this, _LIBCPP_ATOMIC_FLAG_TYPE(__v), __m); } - _LIBCPP_DEPRECATED_ATOMIC_SYNC _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void notify_one() volatile _NOEXCEPT { - std::__atomic_notify_one(*this); - } - _LIBCPP_DEPRECATED_ATOMIC_SYNC _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void notify_one() _NOEXCEPT { + _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void notify_one() volatile _NOEXCEPT { std::__atomic_notify_one(*this); } + _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void notify_one() _NOEXCEPT { std::__atomic_notify_one(*this); } _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void notify_all() volatile _NOEXCEPT { std::__atomic_notify_all(*this); } - _LIBCPP_DEPRECATED_ATOMIC_SYNC _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void notify_all() _NOEXCEPT { - std::__atomic_notify_all(*this); - } + _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void notify_all() _NOEXCEPT { std::__atomic_notify_all(*this); } +#endif #if _LIBCPP_STD_VER >= 20 _LIBCPP_HIDE_FROM_ABI constexpr atomic_flag() _NOEXCEPT : __a_(false) {} @@ -144,45 +142,45 @@ inline _LIBCPP_HIDE_FROM_ABI void atomic_flag_clear_explicit(atomic_flag* __o, m __o->clear(__m); } -inline _LIBCPP_DEPRECATED_ATOMIC_SYNC _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC void +#if _LIBCPP_STD_VER >= 20 +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC void atomic_flag_wait(const volatile atomic_flag* __o, bool __v) _NOEXCEPT { __o->wait(__v); } -inline _LIBCPP_DEPRECATED_ATOMIC_SYNC _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC void +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC void atomic_flag_wait(const atomic_flag* __o, bool __v) _NOEXCEPT { __o->wait(__v); } -inline _LIBCPP_DEPRECATED_ATOMIC_SYNC _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC void +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC void atomic_flag_wait_explicit(const volatile atomic_flag* __o, bool __v, memory_order __m) _NOEXCEPT { __o->wait(__v, __m); } -inline _LIBCPP_DEPRECATED_ATOMIC_SYNC _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC void +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC void atomic_flag_wait_explicit(const atomic_flag* __o, bool __v, memory_order __m) _NOEXCEPT { __o->wait(__v, __m); } -inline _LIBCPP_DEPRECATED_ATOMIC_SYNC _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC void +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC void atomic_flag_notify_one(volatile atomic_flag* __o) _NOEXCEPT { __o->notify_one(); } -inline _LIBCPP_DEPRECATED_ATOMIC_SYNC _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC void -atomic_flag_notify_one(atomic_flag* __o) _NOEXCEPT { +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC void atomic_flag_notify_one(atomic_flag* __o) _NOEXCEPT { __o->notify_one(); } -inline _LIBCPP_DEPRECATED_ATOMIC_SYNC _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC void +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC void atomic_flag_notify_all(volatile atomic_flag* __o) _NOEXCEPT { __o->notify_all(); } -inline _LIBCPP_DEPRECATED_ATOMIC_SYNC _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC void -atomic_flag_notify_all(atomic_flag* __o) _NOEXCEPT { +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_SYNC void atomic_flag_notify_all(atomic_flag* __o) _NOEXCEPT { __o->notify_all(); } +#endif // _LIBCPP_STD_VER >= 20 _LIBCPP_END_NAMESPACE_STD diff --git a/system/lib/libcxx/include/__atomic/atomic_lock_free.h b/system/lib/libcxx/include/__atomic/atomic_lock_free.h index 0715439db4503..3ae9b8856e810 100644 --- a/system/lib/libcxx/include/__atomic/atomic_lock_free.h +++ b/system/lib/libcxx/include/__atomic/atomic_lock_free.h @@ -18,7 +18,7 @@ #if defined(__CLANG_ATOMIC_BOOL_LOCK_FREE) # define ATOMIC_BOOL_LOCK_FREE __CLANG_ATOMIC_BOOL_LOCK_FREE # define ATOMIC_CHAR_LOCK_FREE __CLANG_ATOMIC_CHAR_LOCK_FREE -# ifndef _LIBCPP_HAS_NO_CHAR8_T +# if _LIBCPP_HAS_CHAR8_T # define ATOMIC_CHAR8_T_LOCK_FREE __CLANG_ATOMIC_CHAR8_T_LOCK_FREE # endif # define ATOMIC_CHAR16_T_LOCK_FREE __CLANG_ATOMIC_CHAR16_T_LOCK_FREE @@ -32,7 +32,7 @@ #elif defined(__GCC_ATOMIC_BOOL_LOCK_FREE) # define ATOMIC_BOOL_LOCK_FREE __GCC_ATOMIC_BOOL_LOCK_FREE # define ATOMIC_CHAR_LOCK_FREE __GCC_ATOMIC_CHAR_LOCK_FREE -# ifndef _LIBCPP_HAS_NO_CHAR8_T +# if _LIBCPP_HAS_CHAR8_T # define ATOMIC_CHAR8_T_LOCK_FREE __GCC_ATOMIC_CHAR8_T_LOCK_FREE # endif # define ATOMIC_CHAR16_T_LOCK_FREE __GCC_ATOMIC_CHAR16_T_LOCK_FREE diff --git a/system/lib/libcxx/include/__atomic/atomic_ref.h b/system/lib/libcxx/include/__atomic/atomic_ref.h index b0180a37ab500..177ea646b6cd0 100644 --- a/system/lib/libcxx/include/__atomic/atomic_ref.h +++ b/system/lib/libcxx/include/__atomic/atomic_ref.h @@ -20,14 +20,16 @@ #include <__assert> #include <__atomic/atomic_sync.h> #include <__atomic/check_memory_order.h> +#include <__atomic/memory_order.h> #include <__atomic/to_gcc_order.h> #include <__concepts/arithmetic.h> #include <__concepts/same_as.h> #include <__config> +#include <__cstddef/byte.h> +#include <__cstddef/ptrdiff_t.h> #include <__memory/addressof.h> #include <__type_traits/has_unique_object_representation.h> #include <__type_traits/is_trivially_copyable.h> -#include #include #include @@ -219,7 +221,7 @@ struct __atomic_ref_base { _LIBCPP_HIDE_FROM_ABI void notify_all() const noexcept { std::__atomic_notify_all(*this); } protected: - typedef _Tp _Aligned_Tp __attribute__((aligned(required_alignment))); + using _Aligned_Tp [[__gnu__::__aligned__(required_alignment), __gnu__::__nodebug__]] = _Tp; _Aligned_Tp* __ptr_; _LIBCPP_HIDE_FROM_ABI __atomic_ref_base(_Tp& __obj) : __ptr_(std::addressof(__obj)) {} @@ -239,7 +241,7 @@ template struct atomic_ref : public __atomic_ref_base<_Tp> { static_assert(is_trivially_copyable_v<_Tp>, "std::atomic_ref requires that 'T' be a trivially copyable type"); - using __base = __atomic_ref_base<_Tp>; + using __base _LIBCPP_NODEBUG = __atomic_ref_base<_Tp>; _LIBCPP_HIDE_FROM_ABI explicit atomic_ref(_Tp& __obj) : __base(__obj) { _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN( @@ -257,7 +259,7 @@ struct atomic_ref : public __atomic_ref_base<_Tp> { template requires(std::integral<_Tp> && !std::same_as) struct atomic_ref<_Tp> : public __atomic_ref_base<_Tp> { - using __base = __atomic_ref_base<_Tp>; + using __base _LIBCPP_NODEBUG = __atomic_ref_base<_Tp>; using difference_type = __base::value_type; @@ -303,7 +305,7 @@ struct atomic_ref<_Tp> : public __atomic_ref_base<_Tp> { template requires std::floating_point<_Tp> struct atomic_ref<_Tp> : public __atomic_ref_base<_Tp> { - using __base = __atomic_ref_base<_Tp>; + using __base _LIBCPP_NODEBUG = __atomic_ref_base<_Tp>; using difference_type = __base::value_type; @@ -342,7 +344,7 @@ struct atomic_ref<_Tp> : public __atomic_ref_base<_Tp> { template struct atomic_ref<_Tp*> : public __atomic_ref_base<_Tp*> { - using __base = __atomic_ref_base<_Tp*>; + using __base _LIBCPP_NODEBUG = __atomic_ref_base<_Tp*>; using difference_type = ptrdiff_t; diff --git a/system/lib/libcxx/include/__atomic/atomic_sync.h b/system/lib/libcxx/include/__atomic/atomic_sync.h index aaf81f58731a9..0dae448d649be 100644 --- a/system/lib/libcxx/include/__atomic/atomic_sync.h +++ b/system/lib/libcxx/include/__atomic/atomic_sync.h @@ -10,14 +10,12 @@ #define _LIBCPP___ATOMIC_ATOMIC_SYNC_H #include <__atomic/contention_t.h> -#include <__atomic/cxx_atomic_impl.h> #include <__atomic/memory_order.h> #include <__atomic/to_gcc_order.h> #include <__chrono/duration.h> #include <__config> #include <__memory/addressof.h> #include <__thread/poll_with_backoff.h> -#include <__thread/support.h> #include <__type_traits/conjunction.h> #include <__type_traits/decay.h> #include <__type_traits/invoke.h> @@ -57,19 +55,8 @@ struct __atomic_waitable< _Tp, decltype(__atomic_waitable_traits<__decay_t<_Tp> >::__atomic_contention_address( std::declval()))> > : true_type {}; -template -struct __atomic_wait_poll_impl { - const _AtomicWaitable& __a_; - _Poll __poll_; - memory_order __order_; - - _LIBCPP_HIDE_FROM_ABI bool operator()() const { - auto __current_val = __atomic_waitable_traits<__decay_t<_AtomicWaitable> >::__atomic_load(__a_, __order_); - return __poll_(__current_val); - } -}; - -#ifndef _LIBCPP_HAS_NO_THREADS +#if _LIBCPP_STD_VER >= 20 +# if _LIBCPP_HAS_THREADS _LIBCPP_AVAILABILITY_SYNC _LIBCPP_EXPORTED_FROM_ABI void __cxx_atomic_notify_one(void const volatile*) _NOEXCEPT; _LIBCPP_AVAILABILITY_SYNC _LIBCPP_EXPORTED_FROM_ABI void __cxx_atomic_notify_all(void const volatile*) _NOEXCEPT; @@ -93,7 +80,7 @@ struct __atomic_wait_backoff_impl { _Poll __poll_; memory_order __order_; - using __waitable_traits = __atomic_waitable_traits<__decay_t<_AtomicWaitable> >; + using __waitable_traits _LIBCPP_NODEBUG = __atomic_waitable_traits<__decay_t<_AtomicWaitable> >; _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI bool @@ -120,15 +107,13 @@ struct __atomic_wait_backoff_impl { _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI bool operator()(chrono::nanoseconds __elapsed) const { - if (__elapsed > chrono::microseconds(64)) { + if (__elapsed > chrono::microseconds(4)) { auto __contention_address = __waitable_traits::__atomic_contention_address(__a_); __cxx_contention_t __monitor_val; if (__update_monitor_val_and_poll(__contention_address, __monitor_val)) return true; std::__libcpp_atomic_wait(__contention_address, __monitor_val); - } else if (__elapsed > chrono::microseconds(4)) - __libcpp_thread_yield(); - else { + } else { } // poll return false; } @@ -144,11 +129,16 @@ struct __atomic_wait_backoff_impl { // value. The predicate function must not return `false` spuriously. template _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void -__atomic_wait_unless(const _AtomicWaitable& __a, _Poll&& __poll, memory_order __order) { +__atomic_wait_unless(const _AtomicWaitable& __a, memory_order __order, _Poll&& __poll) { static_assert(__atomic_waitable<_AtomicWaitable>::value, ""); - __atomic_wait_poll_impl<_AtomicWaitable, __decay_t<_Poll> > __poll_impl = {__a, __poll, __order}; __atomic_wait_backoff_impl<_AtomicWaitable, __decay_t<_Poll> > __backoff_fn = {__a, __poll, __order}; - std::__libcpp_thread_poll_with_backoff(__poll_impl, __backoff_fn); + std::__libcpp_thread_poll_with_backoff( + /* poll */ + [&]() { + auto __current_val = __atomic_waitable_traits<__decay_t<_AtomicWaitable> >::__atomic_load(__a, __order); + return __poll(__current_val); + }, + /* backoff */ __backoff_fn); } template @@ -163,12 +153,17 @@ _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void __atomic_notify_all(const _ std::__cxx_atomic_notify_all(__atomic_waitable_traits<__decay_t<_AtomicWaitable> >::__atomic_contention_address(__a)); } -#else // _LIBCPP_HAS_NO_THREADS +# else // _LIBCPP_HAS_THREADS template -_LIBCPP_HIDE_FROM_ABI void __atomic_wait_unless(const _AtomicWaitable& __a, _Poll&& __poll, memory_order __order) { - __atomic_wait_poll_impl<_AtomicWaitable, __decay_t<_Poll> > __poll_fn = {__a, __poll, __order}; - std::__libcpp_thread_poll_with_backoff(__poll_fn, __spinning_backoff_policy()); +_LIBCPP_HIDE_FROM_ABI void __atomic_wait_unless(const _AtomicWaitable& __a, memory_order __order, _Poll&& __poll) { + std::__libcpp_thread_poll_with_backoff( + /* poll */ + [&]() { + auto __current_val = __atomic_waitable_traits<__decay_t<_AtomicWaitable> >::__atomic_load(__a, __order); + return __poll(__current_val); + }, + /* backoff */ __spinning_backoff_policy()); } template @@ -177,29 +172,24 @@ _LIBCPP_HIDE_FROM_ABI void __atomic_notify_one(const _AtomicWaitable&) {} template _LIBCPP_HIDE_FROM_ABI void __atomic_notify_all(const _AtomicWaitable&) {} -#endif // _LIBCPP_HAS_NO_THREADS +# endif // _LIBCPP_HAS_THREADS template _LIBCPP_HIDE_FROM_ABI bool __cxx_nonatomic_compare_equal(_Tp const& __lhs, _Tp const& __rhs) { return std::memcmp(std::addressof(__lhs), std::addressof(__rhs), sizeof(_Tp)) == 0; } -template -struct __atomic_compare_unequal_to { - _Tp __val_; - _LIBCPP_HIDE_FROM_ABI bool operator()(const _Tp& __arg) const { - return !std::__cxx_nonatomic_compare_equal(__arg, __val_); - } -}; - -template +template _LIBCPP_AVAILABILITY_SYNC _LIBCPP_HIDE_FROM_ABI void -__atomic_wait(_AtomicWaitable& __a, _Up __val, memory_order __order) { +__atomic_wait(_AtomicWaitable& __a, _Tp __val, memory_order __order) { static_assert(__atomic_waitable<_AtomicWaitable>::value, ""); - __atomic_compare_unequal_to<_Up> __nonatomic_equal = {__val}; - std::__atomic_wait_unless(__a, __nonatomic_equal, __order); + std::__atomic_wait_unless(__a, __order, [&](_Tp const& __current) { + return !std::__cxx_nonatomic_compare_equal(__current, __val); + }); } +#endif // C++20 + _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP___ATOMIC_ATOMIC_SYNC_H diff --git a/system/lib/libcxx/include/__atomic/contention_t.h b/system/lib/libcxx/include/__atomic/contention_t.h index 65890f338ce99..5b42a0125f875 100644 --- a/system/lib/libcxx/include/__atomic/contention_t.h +++ b/system/lib/libcxx/include/__atomic/contention_t.h @@ -9,7 +9,7 @@ #ifndef _LIBCPP___ATOMIC_CONTENTION_T_H #define _LIBCPP___ATOMIC_CONTENTION_T_H -#include <__atomic/cxx_atomic_impl.h> +#include <__atomic/support.h> #include <__config> #include @@ -20,12 +20,12 @@ _LIBCPP_BEGIN_NAMESPACE_STD #if defined(__linux__) || (defined(_AIX) && !defined(__64BIT__)) -using __cxx_contention_t = int32_t; +using __cxx_contention_t _LIBCPP_NODEBUG = int32_t; #else -using __cxx_contention_t = int64_t; +using __cxx_contention_t _LIBCPP_NODEBUG = int64_t; #endif // __linux__ || (_AIX && !__64BIT__) -using __cxx_atomic_contention_t = __cxx_atomic_impl<__cxx_contention_t>; +using __cxx_atomic_contention_t _LIBCPP_NODEBUG = __cxx_atomic_impl<__cxx_contention_t>; _LIBCPP_END_NAMESPACE_STD diff --git a/system/lib/libcxx/include/__atomic/fence.h b/system/lib/libcxx/include/__atomic/fence.h index 8c27ea54d62dd..0a63cedddb3f9 100644 --- a/system/lib/libcxx/include/__atomic/fence.h +++ b/system/lib/libcxx/include/__atomic/fence.h @@ -9,8 +9,8 @@ #ifndef _LIBCPP___ATOMIC_FENCE_H #define _LIBCPP___ATOMIC_FENCE_H -#include <__atomic/cxx_atomic_impl.h> #include <__atomic/memory_order.h> +#include <__atomic/support.h> #include <__config> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) diff --git a/system/lib/libcxx/include/__atomic/memory_order.h b/system/lib/libcxx/include/__atomic/memory_order.h index 294121d1c4e7f..44790fe888b36 100644 --- a/system/lib/libcxx/include/__atomic/memory_order.h +++ b/system/lib/libcxx/include/__atomic/memory_order.h @@ -24,7 +24,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD // to pin the underlying type in C++20. enum __legacy_memory_order { __mo_relaxed, __mo_consume, __mo_acquire, __mo_release, __mo_acq_rel, __mo_seq_cst }; -using __memory_order_underlying_t = underlying_type<__legacy_memory_order>::type; +using __memory_order_underlying_t _LIBCPP_NODEBUG = underlying_type<__legacy_memory_order>::type; #if _LIBCPP_STD_VER >= 20 diff --git a/system/lib/libcxx/include/__atomic/support.h b/system/lib/libcxx/include/__atomic/support.h new file mode 100644 index 0000000000000..4b555ab483ca0 --- /dev/null +++ b/system/lib/libcxx/include/__atomic/support.h @@ -0,0 +1,124 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___ATOMIC_SUPPORT_H +#define _LIBCPP___ATOMIC_SUPPORT_H + +#include <__config> +#include <__type_traits/is_trivially_copyable.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +// +// This file implements base support for atomics on the platform. +// +// The following operations and types must be implemented (where _Atmc +// is __cxx_atomic_base_impl for readability): +// +// clang-format off +// +// template +// struct __cxx_atomic_base_impl; +// +// #define __cxx_atomic_is_lock_free(__size) +// +// void __cxx_atomic_thread_fence(memory_order __order) noexcept; +// void __cxx_atomic_signal_fence(memory_order __order) noexcept; +// +// template +// void __cxx_atomic_init(_Atmc<_Tp> volatile* __a, _Tp __val) noexcept; +// template +// void __cxx_atomic_init(_Atmc<_Tp>* __a, _Tp __val) noexcept; +// +// template +// void __cxx_atomic_store(_Atmc<_Tp> volatile* __a, _Tp __val, memory_order __order) noexcept; +// template +// void __cxx_atomic_store(_Atmc<_Tp>* __a, _Tp __val, memory_order __order) noexcept; +// +// template +// _Tp __cxx_atomic_load(_Atmc<_Tp> const volatile* __a, memory_order __order) noexcept; +// template +// _Tp __cxx_atomic_load(_Atmc<_Tp> const* __a, memory_order __order) noexcept; +// +// template +// void __cxx_atomic_load_inplace(_Atmc<_Tp> const volatile* __a, _Tp* __dst, memory_order __order) noexcept; +// template +// void __cxx_atomic_load_inplace(_Atmc<_Tp> const* __a, _Tp* __dst, memory_order __order) noexcept; +// +// template +// _Tp __cxx_atomic_exchange(_Atmc<_Tp> volatile* __a, _Tp __value, memory_order __order) noexcept; +// template +// _Tp __cxx_atomic_exchange(_Atmc<_Tp>* __a, _Tp __value, memory_order __order) noexcept; +// +// template +// bool __cxx_atomic_compare_exchange_strong(_Atmc<_Tp> volatile* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) noexcept; +// template +// bool __cxx_atomic_compare_exchange_strong(_Atmc<_Tp>* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) noexcept; +// +// template +// bool __cxx_atomic_compare_exchange_weak(_Atmc<_Tp> volatile* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) noexcept; +// template +// bool __cxx_atomic_compare_exchange_weak(_Atmc<_Tp>* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) noexcept; +// +// template +// _Tp __cxx_atomic_fetch_add(_Atmc<_Tp> volatile* __a, _Tp __delta, memory_order __order) noexcept; +// template +// _Tp __cxx_atomic_fetch_add(_Atmc<_Tp>* __a, _Tp __delta, memory_order __order) noexcept; +// +// template +// _Tp* __cxx_atomic_fetch_add(_Atmc<_Tp*> volatile* __a, ptrdiff_t __delta, memory_order __order) noexcept; +// template +// _Tp* __cxx_atomic_fetch_add(_Atmc<_Tp*>* __a, ptrdiff_t __delta, memory_order __order) noexcept; +// +// template +// _Tp __cxx_atomic_fetch_sub(_Atmc<_Tp> volatile* __a, _Tp __delta, memory_order __order) noexcept; +// template +// _Tp __cxx_atomic_fetch_sub(_Atmc<_Tp>* __a, _Tp __delta, memory_order __order) noexcept; +// template +// _Tp* __cxx_atomic_fetch_sub(_Atmc<_Tp*> volatile* __a, ptrdiff_t __delta, memory_order __order) noexcept; +// template +// _Tp* __cxx_atomic_fetch_sub(_Atmc<_Tp*>* __a, ptrdiff_t __delta, memory_order __order) noexcept; +// +// template +// _Tp __cxx_atomic_fetch_and(_Atmc<_Tp> volatile* __a, _Tp __pattern, memory_order __order) noexcept; +// template +// _Tp __cxx_atomic_fetch_and(_Atmc<_Tp>* __a, _Tp __pattern, memory_order __order) noexcept; +// +// template +// _Tp __cxx_atomic_fetch_or(_Atmc<_Tp> volatile* __a, _Tp __pattern, memory_order __order) noexcept; +// template +// _Tp __cxx_atomic_fetch_or(_Atmc<_Tp>* __a, _Tp __pattern, memory_order __order) noexcept; +// template +// _Tp __cxx_atomic_fetch_xor(_Atmc<_Tp> volatile* __a, _Tp __pattern, memory_order __order) noexcept; +// template +// _Tp __cxx_atomic_fetch_xor(_Atmc<_Tp>* __a, _Tp __pattern, memory_order __order) noexcept; +// +// clang-format on +// + +#if _LIBCPP_HAS_GCC_ATOMIC_IMP +# include <__atomic/support/gcc.h> +#elif _LIBCPP_HAS_C_ATOMIC_IMP +# include <__atomic/support/c11.h> +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template > +struct __cxx_atomic_impl : public _Base { + static_assert(is_trivially_copyable<_Tp>::value, "std::atomic requires that 'T' be a trivially copyable type"); + + _LIBCPP_HIDE_FROM_ABI __cxx_atomic_impl() _NOEXCEPT = default; + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __cxx_atomic_impl(_Tp __value) _NOEXCEPT : _Base(__value) {} +}; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___ATOMIC_SUPPORT_H diff --git a/system/lib/libcxx/include/__atomic/cxx_atomic_impl.h b/system/lib/libcxx/include/__atomic/support/c11.h similarity index 52% rename from system/lib/libcxx/include/__atomic/cxx_atomic_impl.h rename to system/lib/libcxx/include/__atomic/support/c11.h index 18e88aa97bec7..177a075be4073 100644 --- a/system/lib/libcxx/include/__atomic/cxx_atomic_impl.h +++ b/system/lib/libcxx/include/__atomic/support/c11.h @@ -6,275 +6,39 @@ // //===----------------------------------------------------------------------===// -#ifndef _LIBCPP___ATOMIC_CXX_ATOMIC_IMPL_H -#define _LIBCPP___ATOMIC_CXX_ATOMIC_IMPL_H +#ifndef _LIBCPP___ATOMIC_SUPPORT_C11_H +#define _LIBCPP___ATOMIC_SUPPORT_C11_H #include <__atomic/memory_order.h> -#include <__atomic/to_gcc_order.h> #include <__config> +#include <__cstddef/ptrdiff_t.h> #include <__memory/addressof.h> -#include <__type_traits/is_assignable.h> -#include <__type_traits/is_trivially_copyable.h> #include <__type_traits/remove_const.h> -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - -#if defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) - -// [atomics.types.generic]p1 guarantees _Tp is trivially copyable. Because -// the default operator= in an object is not volatile, a byte-by-byte copy -// is required. -template ::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI void __cxx_atomic_assign_volatile(_Tp& __a_value, _Tv const& __val) { - __a_value = __val; -} -template ::value, int> = 0> -_LIBCPP_HIDE_FROM_ABI void __cxx_atomic_assign_volatile(_Tp volatile& __a_value, _Tv volatile const& __val) { - volatile char* __to = reinterpret_cast(std::addressof(__a_value)); - volatile char* __end = __to + sizeof(_Tp); - volatile const char* __from = reinterpret_cast(std::addressof(__val)); - while (__to != __end) - *__to++ = *__from++; -} - -template -struct __cxx_atomic_base_impl { - _LIBCPP_HIDE_FROM_ABI -# ifndef _LIBCPP_CXX03_LANG - __cxx_atomic_base_impl() _NOEXCEPT = default; -# else - __cxx_atomic_base_impl() _NOEXCEPT : __a_value() { - } -# endif // _LIBCPP_CXX03_LANG - _LIBCPP_CONSTEXPR explicit __cxx_atomic_base_impl(_Tp value) _NOEXCEPT : __a_value(value) {} - _Tp __a_value; -}; - -template -_LIBCPP_HIDE_FROM_ABI void __cxx_atomic_init(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __val) { - __cxx_atomic_assign_volatile(__a->__a_value, __val); -} - -template -_LIBCPP_HIDE_FROM_ABI void __cxx_atomic_init(__cxx_atomic_base_impl<_Tp>* __a, _Tp __val) { - __a->__a_value = __val; -} - -_LIBCPP_HIDE_FROM_ABI inline void __cxx_atomic_thread_fence(memory_order __order) { - __atomic_thread_fence(__to_gcc_order(__order)); -} - -_LIBCPP_HIDE_FROM_ABI inline void __cxx_atomic_signal_fence(memory_order __order) { - __atomic_signal_fence(__to_gcc_order(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI void -__cxx_atomic_store(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __val, memory_order __order) { - __atomic_store(std::addressof(__a->__a_value), std::addressof(__val), __to_gcc_order(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI void __cxx_atomic_store(__cxx_atomic_base_impl<_Tp>* __a, _Tp __val, memory_order __order) { - __atomic_store(std::addressof(__a->__a_value), std::addressof(__val), __to_gcc_order(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_load(const volatile __cxx_atomic_base_impl<_Tp>* __a, memory_order __order) { - _Tp __ret; - __atomic_load(std::addressof(__a->__a_value), std::addressof(__ret), __to_gcc_order(__order)); - return __ret; -} - -template -_LIBCPP_HIDE_FROM_ABI void -__cxx_atomic_load_inplace(const volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp* __dst, memory_order __order) { - __atomic_load(std::addressof(__a->__a_value), __dst, __to_gcc_order(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI void -__cxx_atomic_load_inplace(const __cxx_atomic_base_impl<_Tp>* __a, _Tp* __dst, memory_order __order) { - __atomic_load(std::addressof(__a->__a_value), __dst, __to_gcc_order(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_load(const __cxx_atomic_base_impl<_Tp>* __a, memory_order __order) { - _Tp __ret; - __atomic_load(std::addressof(__a->__a_value), std::addressof(__ret), __to_gcc_order(__order)); - return __ret; -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp -__cxx_atomic_exchange(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __value, memory_order __order) { - _Tp __ret; - __atomic_exchange( - std::addressof(__a->__a_value), std::addressof(__value), std::addressof(__ret), __to_gcc_order(__order)); - return __ret; -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_exchange(__cxx_atomic_base_impl<_Tp>* __a, _Tp __value, memory_order __order) { - _Tp __ret; - __atomic_exchange( - std::addressof(__a->__a_value), std::addressof(__value), std::addressof(__ret), __to_gcc_order(__order)); - return __ret; -} - -template -_LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_compare_exchange_strong( - volatile __cxx_atomic_base_impl<_Tp>* __a, - _Tp* __expected, - _Tp __value, - memory_order __success, - memory_order __failure) { - return __atomic_compare_exchange( - std::addressof(__a->__a_value), - __expected, - std::addressof(__value), - false, - __to_gcc_order(__success), - __to_gcc_failure_order(__failure)); -} - -template -_LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_compare_exchange_strong( - __cxx_atomic_base_impl<_Tp>* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) { - return __atomic_compare_exchange( - std::addressof(__a->__a_value), - __expected, - std::addressof(__value), - false, - __to_gcc_order(__success), - __to_gcc_failure_order(__failure)); -} - -template -_LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_compare_exchange_weak( - volatile __cxx_atomic_base_impl<_Tp>* __a, - _Tp* __expected, - _Tp __value, - memory_order __success, - memory_order __failure) { - return __atomic_compare_exchange( - std::addressof(__a->__a_value), - __expected, - std::addressof(__value), - true, - __to_gcc_order(__success), - __to_gcc_failure_order(__failure)); -} - -template -_LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_compare_exchange_weak( - __cxx_atomic_base_impl<_Tp>* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) { - return __atomic_compare_exchange( - std::addressof(__a->__a_value), - __expected, - std::addressof(__value), - true, - __to_gcc_order(__success), - __to_gcc_failure_order(__failure)); -} - -template -struct __skip_amt { - enum { value = 1 }; -}; - -template -struct __skip_amt<_Tp*> { - enum { value = sizeof(_Tp) }; -}; - -// FIXME: Haven't figured out what the spec says about using arrays with -// atomic_fetch_add. Force a failure rather than creating bad behavior. -template -struct __skip_amt<_Tp[]> {}; -template -struct __skip_amt<_Tp[n]> {}; - -template -_LIBCPP_HIDE_FROM_ABI _Tp -__cxx_atomic_fetch_add(volatile __cxx_atomic_base_impl<_Tp>* __a, _Td __delta, memory_order __order) { - return __atomic_fetch_add(std::addressof(__a->__a_value), __delta * __skip_amt<_Tp>::value, __to_gcc_order(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp>* __a, _Td __delta, memory_order __order) { - return __atomic_fetch_add(std::addressof(__a->__a_value), __delta * __skip_amt<_Tp>::value, __to_gcc_order(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp -__cxx_atomic_fetch_sub(volatile __cxx_atomic_base_impl<_Tp>* __a, _Td __delta, memory_order __order) { - return __atomic_fetch_sub(std::addressof(__a->__a_value), __delta * __skip_amt<_Tp>::value, __to_gcc_order(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp>* __a, _Td __delta, memory_order __order) { - return __atomic_fetch_sub(std::addressof(__a->__a_value), __delta * __skip_amt<_Tp>::value, __to_gcc_order(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp -__cxx_atomic_fetch_and(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) { - return __atomic_fetch_and(std::addressof(__a->__a_value), __pattern, __to_gcc_order(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp -__cxx_atomic_fetch_and(__cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) { - return __atomic_fetch_and(std::addressof(__a->__a_value), __pattern, __to_gcc_order(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp -__cxx_atomic_fetch_or(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) { - return __atomic_fetch_or(std::addressof(__a->__a_value), __pattern, __to_gcc_order(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_fetch_or(__cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) { - return __atomic_fetch_or(std::addressof(__a->__a_value), __pattern, __to_gcc_order(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp -__cxx_atomic_fetch_xor(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) { - return __atomic_fetch_xor(std::addressof(__a->__a_value), __pattern, __to_gcc_order(__order)); -} - -template -_LIBCPP_HIDE_FROM_ABI _Tp -__cxx_atomic_fetch_xor(__cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) { - return __atomic_fetch_xor(std::addressof(__a->__a_value), __pattern, __to_gcc_order(__order)); -} - -# define __cxx_atomic_is_lock_free(__s) __atomic_is_lock_free(__s, 0) +// +// This file implements support for C11-style atomics +// -#elif defined(_LIBCPP_HAS_C_ATOMIC_IMP) +_LIBCPP_BEGIN_NAMESPACE_STD template struct __cxx_atomic_base_impl { _LIBCPP_HIDE_FROM_ABI -# ifndef _LIBCPP_CXX03_LANG +#ifndef _LIBCPP_CXX03_LANG __cxx_atomic_base_impl() _NOEXCEPT = default; -# else +#else __cxx_atomic_base_impl() _NOEXCEPT : __a_value() { } -# endif // _LIBCPP_CXX03_LANG +#endif // _LIBCPP_CXX03_LANG _LIBCPP_CONSTEXPR explicit __cxx_atomic_base_impl(_Tp __value) _NOEXCEPT : __a_value(__value) {} _LIBCPP_DISABLE_EXTENSION_WARNING _Atomic(_Tp) __a_value; }; -# define __cxx_atomic_is_lock_free(__s) __c11_atomic_is_lock_free(__s) +#define __cxx_atomic_is_lock_free(__s) __c11_atomic_is_lock_free(__s) _LIBCPP_HIDE_FROM_ABI inline void __cxx_atomic_thread_fence(memory_order __order) _NOEXCEPT { __c11_atomic_thread_fence(static_cast<__memory_order_underlying_t>(__order)); @@ -495,16 +259,6 @@ __cxx_atomic_fetch_xor(__cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_o std::addressof(__a->__a_value), __pattern, static_cast<__memory_order_underlying_t>(__order)); } -#endif // _LIBCPP_HAS_GCC_ATOMIC_IMP, _LIBCPP_HAS_C_ATOMIC_IMP - -template > -struct __cxx_atomic_impl : public _Base { - static_assert(is_trivially_copyable<_Tp>::value, "std::atomic requires that 'T' be a trivially copyable type"); - - _LIBCPP_HIDE_FROM_ABI __cxx_atomic_impl() _NOEXCEPT = default; - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __cxx_atomic_impl(_Tp __value) _NOEXCEPT : _Base(__value) {} -}; - _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP___ATOMIC_CXX_ATOMIC_IMPL_H +#endif // _LIBCPP___ATOMIC_SUPPORT_C11_H diff --git a/system/lib/libcxx/include/__atomic/support/gcc.h b/system/lib/libcxx/include/__atomic/support/gcc.h new file mode 100644 index 0000000000000..73c1b1c8070a4 --- /dev/null +++ b/system/lib/libcxx/include/__atomic/support/gcc.h @@ -0,0 +1,265 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___ATOMIC_SUPPORT_GCC_H +#define _LIBCPP___ATOMIC_SUPPORT_GCC_H + +#include <__atomic/memory_order.h> +#include <__atomic/to_gcc_order.h> +#include <__config> +#include <__memory/addressof.h> +#include <__type_traits/enable_if.h> +#include <__type_traits/is_assignable.h> +#include <__type_traits/remove_const.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +// +// This file implements support for GCC-style atomics +// + +_LIBCPP_BEGIN_NAMESPACE_STD + +// [atomics.types.generic]p1 guarantees _Tp is trivially copyable. Because +// the default operator= in an object is not volatile, a byte-by-byte copy +// is required. +template ::value, int> = 0> +_LIBCPP_HIDE_FROM_ABI void __cxx_atomic_assign_volatile(_Tp& __a_value, _Tv const& __val) { + __a_value = __val; +} +template ::value, int> = 0> +_LIBCPP_HIDE_FROM_ABI void __cxx_atomic_assign_volatile(_Tp volatile& __a_value, _Tv volatile const& __val) { + volatile char* __to = reinterpret_cast(std::addressof(__a_value)); + volatile char* __end = __to + sizeof(_Tp); + volatile const char* __from = reinterpret_cast(std::addressof(__val)); + while (__to != __end) + *__to++ = *__from++; +} + +template +struct __cxx_atomic_base_impl { + _LIBCPP_HIDE_FROM_ABI +#ifndef _LIBCPP_CXX03_LANG + __cxx_atomic_base_impl() _NOEXCEPT = default; +#else + __cxx_atomic_base_impl() _NOEXCEPT : __a_value() { + } +#endif // _LIBCPP_CXX03_LANG + _LIBCPP_CONSTEXPR explicit __cxx_atomic_base_impl(_Tp value) _NOEXCEPT : __a_value(value) {} + _Tp __a_value; +}; + +template +_LIBCPP_HIDE_FROM_ABI void __cxx_atomic_init(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __val) { + __cxx_atomic_assign_volatile(__a->__a_value, __val); +} + +template +_LIBCPP_HIDE_FROM_ABI void __cxx_atomic_init(__cxx_atomic_base_impl<_Tp>* __a, _Tp __val) { + __a->__a_value = __val; +} + +_LIBCPP_HIDE_FROM_ABI inline void __cxx_atomic_thread_fence(memory_order __order) { + __atomic_thread_fence(__to_gcc_order(__order)); +} + +_LIBCPP_HIDE_FROM_ABI inline void __cxx_atomic_signal_fence(memory_order __order) { + __atomic_signal_fence(__to_gcc_order(__order)); +} + +template +_LIBCPP_HIDE_FROM_ABI void +__cxx_atomic_store(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __val, memory_order __order) { + __atomic_store(std::addressof(__a->__a_value), std::addressof(__val), __to_gcc_order(__order)); +} + +template +_LIBCPP_HIDE_FROM_ABI void __cxx_atomic_store(__cxx_atomic_base_impl<_Tp>* __a, _Tp __val, memory_order __order) { + __atomic_store(std::addressof(__a->__a_value), std::addressof(__val), __to_gcc_order(__order)); +} + +template +_LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_load(const volatile __cxx_atomic_base_impl<_Tp>* __a, memory_order __order) { + _Tp __ret; + __atomic_load(std::addressof(__a->__a_value), std::addressof(__ret), __to_gcc_order(__order)); + return __ret; +} + +template +_LIBCPP_HIDE_FROM_ABI void +__cxx_atomic_load_inplace(const volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp* __dst, memory_order __order) { + __atomic_load(std::addressof(__a->__a_value), __dst, __to_gcc_order(__order)); +} + +template +_LIBCPP_HIDE_FROM_ABI void +__cxx_atomic_load_inplace(const __cxx_atomic_base_impl<_Tp>* __a, _Tp* __dst, memory_order __order) { + __atomic_load(std::addressof(__a->__a_value), __dst, __to_gcc_order(__order)); +} + +template +_LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_load(const __cxx_atomic_base_impl<_Tp>* __a, memory_order __order) { + _Tp __ret; + __atomic_load(std::addressof(__a->__a_value), std::addressof(__ret), __to_gcc_order(__order)); + return __ret; +} + +template +_LIBCPP_HIDE_FROM_ABI _Tp +__cxx_atomic_exchange(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __value, memory_order __order) { + _Tp __ret; + __atomic_exchange( + std::addressof(__a->__a_value), std::addressof(__value), std::addressof(__ret), __to_gcc_order(__order)); + return __ret; +} + +template +_LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_exchange(__cxx_atomic_base_impl<_Tp>* __a, _Tp __value, memory_order __order) { + _Tp __ret; + __atomic_exchange( + std::addressof(__a->__a_value), std::addressof(__value), std::addressof(__ret), __to_gcc_order(__order)); + return __ret; +} + +template +_LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_compare_exchange_strong( + volatile __cxx_atomic_base_impl<_Tp>* __a, + _Tp* __expected, + _Tp __value, + memory_order __success, + memory_order __failure) { + return __atomic_compare_exchange( + std::addressof(__a->__a_value), + __expected, + std::addressof(__value), + false, + __to_gcc_order(__success), + __to_gcc_failure_order(__failure)); +} + +template +_LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_compare_exchange_strong( + __cxx_atomic_base_impl<_Tp>* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) { + return __atomic_compare_exchange( + std::addressof(__a->__a_value), + __expected, + std::addressof(__value), + false, + __to_gcc_order(__success), + __to_gcc_failure_order(__failure)); +} + +template +_LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_compare_exchange_weak( + volatile __cxx_atomic_base_impl<_Tp>* __a, + _Tp* __expected, + _Tp __value, + memory_order __success, + memory_order __failure) { + return __atomic_compare_exchange( + std::addressof(__a->__a_value), + __expected, + std::addressof(__value), + true, + __to_gcc_order(__success), + __to_gcc_failure_order(__failure)); +} + +template +_LIBCPP_HIDE_FROM_ABI bool __cxx_atomic_compare_exchange_weak( + __cxx_atomic_base_impl<_Tp>* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) { + return __atomic_compare_exchange( + std::addressof(__a->__a_value), + __expected, + std::addressof(__value), + true, + __to_gcc_order(__success), + __to_gcc_failure_order(__failure)); +} + +template +struct __skip_amt { + enum { value = 1 }; +}; + +template +struct __skip_amt<_Tp*> { + enum { value = sizeof(_Tp) }; +}; + +// FIXME: Haven't figured out what the spec says about using arrays with +// atomic_fetch_add. Force a failure rather than creating bad behavior. +template +struct __skip_amt<_Tp[]> {}; +template +struct __skip_amt<_Tp[n]> {}; + +template +_LIBCPP_HIDE_FROM_ABI _Tp +__cxx_atomic_fetch_add(volatile __cxx_atomic_base_impl<_Tp>* __a, _Td __delta, memory_order __order) { + return __atomic_fetch_add(std::addressof(__a->__a_value), __delta * __skip_amt<_Tp>::value, __to_gcc_order(__order)); +} + +template +_LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp>* __a, _Td __delta, memory_order __order) { + return __atomic_fetch_add(std::addressof(__a->__a_value), __delta * __skip_amt<_Tp>::value, __to_gcc_order(__order)); +} + +template +_LIBCPP_HIDE_FROM_ABI _Tp +__cxx_atomic_fetch_sub(volatile __cxx_atomic_base_impl<_Tp>* __a, _Td __delta, memory_order __order) { + return __atomic_fetch_sub(std::addressof(__a->__a_value), __delta * __skip_amt<_Tp>::value, __to_gcc_order(__order)); +} + +template +_LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp>* __a, _Td __delta, memory_order __order) { + return __atomic_fetch_sub(std::addressof(__a->__a_value), __delta * __skip_amt<_Tp>::value, __to_gcc_order(__order)); +} + +template +_LIBCPP_HIDE_FROM_ABI _Tp +__cxx_atomic_fetch_and(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) { + return __atomic_fetch_and(std::addressof(__a->__a_value), __pattern, __to_gcc_order(__order)); +} + +template +_LIBCPP_HIDE_FROM_ABI _Tp +__cxx_atomic_fetch_and(__cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) { + return __atomic_fetch_and(std::addressof(__a->__a_value), __pattern, __to_gcc_order(__order)); +} + +template +_LIBCPP_HIDE_FROM_ABI _Tp +__cxx_atomic_fetch_or(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) { + return __atomic_fetch_or(std::addressof(__a->__a_value), __pattern, __to_gcc_order(__order)); +} + +template +_LIBCPP_HIDE_FROM_ABI _Tp __cxx_atomic_fetch_or(__cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) { + return __atomic_fetch_or(std::addressof(__a->__a_value), __pattern, __to_gcc_order(__order)); +} + +template +_LIBCPP_HIDE_FROM_ABI _Tp +__cxx_atomic_fetch_xor(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) { + return __atomic_fetch_xor(std::addressof(__a->__a_value), __pattern, __to_gcc_order(__order)); +} + +template +_LIBCPP_HIDE_FROM_ABI _Tp +__cxx_atomic_fetch_xor(__cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, memory_order __order) { + return __atomic_fetch_xor(std::addressof(__a->__a_value), __pattern, __to_gcc_order(__order)); +} + +#define __cxx_atomic_is_lock_free(__s) __atomic_is_lock_free(__s, 0) + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___ATOMIC_SUPPORT_GCC_H diff --git a/system/lib/libcxx/include/__bit/bit_cast.h b/system/lib/libcxx/include/__bit/bit_cast.h index cd04567381793..735025065a729 100644 --- a/system/lib/libcxx/include/__bit/bit_cast.h +++ b/system/lib/libcxx/include/__bit/bit_cast.h @@ -22,7 +22,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD #ifndef _LIBCPP_CXX03_LANG template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI constexpr _ToType __bit_cast(const _FromType& __from) noexcept { +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI constexpr _ToType __bit_cast(const _FromType& __from) noexcept { return __builtin_bit_cast(_ToType, __from); } diff --git a/system/lib/libcxx/include/__bit/bit_log2.h b/system/lib/libcxx/include/__bit/bit_log2.h index 62936f6786860..94ee6c3b2bb1d 100644 --- a/system/lib/libcxx/include/__bit/bit_log2.h +++ b/system/lib/libcxx/include/__bit/bit_log2.h @@ -10,8 +10,8 @@ #define _LIBCPP___BIT_BIT_LOG2_H #include <__bit/countl.h> -#include <__concepts/arithmetic.h> #include <__config> +#include <__type_traits/is_unsigned_integer.h> #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -20,14 +20,15 @@ _LIBCPP_BEGIN_NAMESPACE_STD -#if _LIBCPP_STD_VER >= 20 +#if _LIBCPP_STD_VER >= 14 -template <__libcpp_unsigned_integer _Tp> +template _LIBCPP_HIDE_FROM_ABI constexpr _Tp __bit_log2(_Tp __t) noexcept { - return numeric_limits<_Tp>::digits - 1 - std::countl_zero(__t); + static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__bit_log2 requires an unsigned integer type"); + return numeric_limits<_Tp>::digits - 1 - std::__countl_zero(__t); } -#endif // _LIBCPP_STD_VER >= 20 +#endif // _LIBCPP_STD_VER >= 14 _LIBCPP_END_NAMESPACE_STD diff --git a/system/lib/libcxx/include/__bit/byteswap.h b/system/lib/libcxx/include/__bit/byteswap.h index 6225ecf2f92df..d761e6a6fdb46 100644 --- a/system/lib/libcxx/include/__bit/byteswap.h +++ b/system/lib/libcxx/include/__bit/byteswap.h @@ -32,7 +32,7 @@ template return __builtin_bswap32(__val); } else if constexpr (sizeof(_Tp) == 8) { return __builtin_bswap64(__val); -# ifndef _LIBCPP_HAS_NO_INT128 +# if _LIBCPP_HAS_INT128 } else if constexpr (sizeof(_Tp) == 16) { # if __has_builtin(__builtin_bswap128) return __builtin_bswap128(__val); @@ -40,7 +40,7 @@ template return static_cast<_Tp>(byteswap(static_cast(__val))) << 64 | static_cast<_Tp>(byteswap(static_cast(__val >> 64))); # endif // __has_builtin(__builtin_bswap128) -# endif // _LIBCPP_HAS_NO_INT128 +# endif // _LIBCPP_HAS_INT128 } else { static_assert(sizeof(_Tp) == 0, "byteswap is unimplemented for integral types of this size"); } diff --git a/system/lib/libcxx/include/__bit/countl.h b/system/lib/libcxx/include/__bit/countl.h index 998a0b44c19dc..d4df1d049b294 100644 --- a/system/lib/libcxx/include/__bit/countl.h +++ b/system/lib/libcxx/include/__bit/countl.h @@ -27,19 +27,19 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_clz(unsigned __x) _NOEXCEPT { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_clz(unsigned __x) _NOEXCEPT { return __builtin_clz(__x); } -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_clz(unsigned long __x) _NOEXCEPT { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_clz(unsigned long __x) _NOEXCEPT { return __builtin_clzl(__x); } -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_clz(unsigned long long __x) _NOEXCEPT { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_clz(unsigned long long __x) _NOEXCEPT { return __builtin_clzll(__x); } -#ifndef _LIBCPP_HAS_NO_INT128 +#if _LIBCPP_HAS_INT128 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_clz(__uint128_t __x) _NOEXCEPT { # if __has_builtin(__builtin_clzg) return __builtin_clzg(__x); @@ -57,7 +57,7 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_clz(__uint128_t __x) : __builtin_clzll(static_cast(__x >> 64)); # endif } -#endif // _LIBCPP_HAS_NO_INT128 +#endif // _LIBCPP_HAS_INT128 template _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 int __countl_zero(_Tp __t) _NOEXCEPT { diff --git a/system/lib/libcxx/include/__bit/countr.h b/system/lib/libcxx/include/__bit/countr.h index 9e92021fba355..2f7571133bd03 100644 --- a/system/lib/libcxx/include/__bit/countr.h +++ b/system/lib/libcxx/include/__bit/countr.h @@ -26,20 +26,20 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_ctz(unsigned __x) _NOEXCEPT { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_ctz(unsigned __x) _NOEXCEPT { return __builtin_ctz(__x); } -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_ctz(unsigned long __x) _NOEXCEPT { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_ctz(unsigned long __x) _NOEXCEPT { return __builtin_ctzl(__x); } -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_ctz(unsigned long long __x) _NOEXCEPT { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __libcpp_ctz(unsigned long long __x) _NOEXCEPT { return __builtin_ctzll(__x); } template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 int __countr_zero(_Tp __t) _NOEXCEPT { +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 int __countr_zero(_Tp __t) _NOEXCEPT { #if __has_builtin(__builtin_ctzg) return __builtin_ctzg(__t, numeric_limits<_Tp>::digits); #else // __has_builtin(__builtin_ctzg) diff --git a/system/lib/libcxx/include/__bit/rotate.h b/system/lib/libcxx/include/__bit/rotate.h index 90e430e9d0425..d79d98de296aa 100644 --- a/system/lib/libcxx/include/__bit/rotate.h +++ b/system/lib/libcxx/include/__bit/rotate.h @@ -26,31 +26,31 @@ _LIBCPP_BEGIN_NAMESPACE_STD template _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp __rotl(_Tp __x, int __s) _NOEXCEPT { static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__rotl requires an unsigned integer type"); - const int __N = numeric_limits<_Tp>::digits; - int __r = __s % __N; + const int __n = numeric_limits<_Tp>::digits; + int __r = __s % __n; if (__r == 0) return __x; if (__r > 0) - return (__x << __r) | (__x >> (__N - __r)); + return (__x << __r) | (__x >> (__n - __r)); - return (__x >> -__r) | (__x << (__N + __r)); + return (__x >> -__r) | (__x << (__n + __r)); } template _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp __rotr(_Tp __x, int __s) _NOEXCEPT { static_assert(__libcpp_is_unsigned_integer<_Tp>::value, "__rotr requires an unsigned integer type"); - const int __N = numeric_limits<_Tp>::digits; - int __r = __s % __N; + const int __n = numeric_limits<_Tp>::digits; + int __r = __s % __n; if (__r == 0) return __x; if (__r > 0) - return (__x >> __r) | (__x << (__N - __r)); + return (__x >> __r) | (__x << (__n - __r)); - return (__x << -__r) | (__x >> (__N + __r)); + return (__x << -__r) | (__x >> (__n + __r)); } #if _LIBCPP_STD_VER >= 20 diff --git a/system/lib/libcxx/include/__bit_reference b/system/lib/libcxx/include/__bit_reference index 22637d4397412..67abb023122ed 100644 --- a/system/lib/libcxx/include/__bit_reference +++ b/system/lib/libcxx/include/__bit_reference @@ -11,20 +11,20 @@ #define _LIBCPP___BIT_REFERENCE #include <__algorithm/copy_n.h> -#include <__algorithm/fill_n.h> #include <__algorithm/min.h> #include <__bit/countr.h> -#include <__bit/invert_if.h> -#include <__bit/popcount.h> #include <__compare/ordering.h> #include <__config> +#include <__cstddef/ptrdiff_t.h> +#include <__cstddef/size_t.h> #include <__fwd/bit_reference.h> #include <__iterator/iterator_traits.h> #include <__memory/construct_at.h> #include <__memory/pointer_traits.h> #include <__type_traits/conditional.h> +#include <__type_traits/is_constant_evaluated.h> +#include <__type_traits/void_t.h> #include <__utility/swap.h> -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -43,10 +43,22 @@ struct __has_storage_type { static const bool value = false; }; +template +struct __size_difference_type_traits { + using difference_type = ptrdiff_t; + using size_type = size_t; +}; + +template +struct __size_difference_type_traits<_Cp, __void_t > { + using difference_type = typename _Cp::difference_type; + using size_type = typename _Cp::size_type; +}; + template ::value> class __bit_reference { - using __storage_type = typename _Cp::__storage_type; - using __storage_pointer = typename _Cp::__storage_pointer; + using __storage_type _LIBCPP_NODEBUG = typename _Cp::__storage_type; + using __storage_pointer _LIBCPP_NODEBUG = typename _Cp::__storage_pointer; __storage_pointer __seg_; __storage_type __mask_; @@ -57,7 +69,7 @@ class __bit_reference { friend class __bit_iterator<_Cp, false>; public: - using __container = typename _Cp::__self; + using __container _LIBCPP_NODEBUG = typename _Cp::__self; _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __bit_reference(const __bit_reference&) = default; @@ -137,8 +149,8 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(bool& __x, template class __bit_const_reference { - using __storage_type = typename _Cp::__storage_type; - using __storage_pointer = typename _Cp::__const_storage_pointer; + using __storage_type _LIBCPP_NODEBUG = typename _Cp::__storage_type; + using __storage_pointer _LIBCPP_NODEBUG = typename _Cp::__const_storage_pointer; __storage_pointer __seg_; __storage_type __mask_; @@ -147,7 +159,7 @@ class __bit_const_reference { friend class __bit_iterator<_Cp, true>; public: - using __container = typename _Cp::__self; + using __container _LIBCPP_NODEBUG = typename _Cp::__self; _LIBCPP_HIDE_FROM_ABI __bit_const_reference(const __bit_const_reference&) = default; __bit_const_reference& operator=(const __bit_const_reference&) = delete; @@ -589,10 +601,10 @@ inline _LIBCPP_HIDE_FROM_ABI __bit_iterator<_Cr, false> swap_ranges( template struct __bit_array { - using difference_type = typename _Cp::difference_type; - using __storage_type = typename _Cp::__storage_type; - using __storage_pointer = typename _Cp::__storage_pointer; - using iterator = typename _Cp::iterator; + using difference_type _LIBCPP_NODEBUG = typename __size_difference_type_traits<_Cp>::difference_type; + using __storage_type _LIBCPP_NODEBUG = typename _Cp::__storage_type; + using __storage_pointer _LIBCPP_NODEBUG = typename _Cp::__storage_pointer; + using iterator _LIBCPP_NODEBUG = typename _Cp::iterator; static const unsigned __bits_per_word = _Cp::__bits_per_word; static const unsigned _Np = 4; @@ -781,7 +793,7 @@ equal(__bit_iterator<_Cp, _IC1> __first1, __bit_iterator<_Cp, _IC1> __last1, __b template class __bit_iterator { public: - using difference_type = typename _Cp::difference_type; + using difference_type = typename __size_difference_type_traits<_Cp>::difference_type; using value_type = bool; using pointer = __bit_iterator; #ifndef _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL @@ -792,8 +804,8 @@ public: using iterator_category = random_access_iterator_tag; private: - using __storage_type = typename _Cp::__storage_type; - using __storage_pointer = + using __storage_type _LIBCPP_NODEBUG = typename _Cp::__storage_type; + using __storage_pointer _LIBCPP_NODEBUG = __conditional_t<_IsConst, typename _Cp::__const_storage_pointer, typename _Cp::__storage_pointer>; static const unsigned __bits_per_word = _Cp::__bits_per_word; @@ -968,7 +980,7 @@ private: template _LIBCPP_CONSTEXPR_SINCE_CXX20 friend void - __fill_n_bool(__bit_iterator<_Dp, false> __first, typename _Dp::size_type __n); + __fill_n_bool(__bit_iterator<_Dp, false> __first, typename __size_difference_type_traits<_Dp>::size_type __n); template _LIBCPP_CONSTEXPR_SINCE_CXX20 friend __bit_iterator<_Dp, false> __copy_aligned( @@ -1011,10 +1023,10 @@ private: equal(__bit_iterator<_Dp, _IC1>, __bit_iterator<_Dp, _IC1>, __bit_iterator<_Dp, _IC2>); template _LIBCPP_CONSTEXPR_SINCE_CXX20 friend __bit_iterator<_Dp, _IC> - __find_bool(__bit_iterator<_Dp, _IC>, typename _Dp::size_type); + __find_bool(__bit_iterator<_Dp, _IC>, typename __size_difference_type_traits<_Dp>::size_type); template - friend typename __bit_iterator<_Dp, _IC>::difference_type _LIBCPP_HIDE_FROM_ABI - _LIBCPP_CONSTEXPR_SINCE_CXX20 __count_bool(__bit_iterator<_Dp, _IC>, typename _Dp::size_type); + friend typename __bit_iterator<_Dp, _IC>::difference_type _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 + __count_bool(__bit_iterator<_Dp, _IC>, typename __size_difference_type_traits<_Dp>::size_type); }; _LIBCPP_END_NAMESPACE_STD diff --git a/system/lib/libcxx/include/__charconv/from_chars_floating_point.h b/system/lib/libcxx/include/__charconv/from_chars_floating_point.h new file mode 100644 index 0000000000000..811e518a81db7 --- /dev/null +++ b/system/lib/libcxx/include/__charconv/from_chars_floating_point.h @@ -0,0 +1,73 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___CHARCONV_FROM_CHARS_FLOATING_POINT_H +#define _LIBCPP___CHARCONV_FROM_CHARS_FLOATING_POINT_H + +#include <__assert> +#include <__charconv/chars_format.h> +#include <__charconv/from_chars_result.h> +#include <__config> +#include <__cstddef/ptrdiff_t.h> +#include <__system_error/errc.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER >= 17 + +template +struct __from_chars_result { + _Fp __value; + ptrdiff_t __n; + errc __ec; +}; + +template +_LIBCPP_EXPORTED_FROM_ABI __from_chars_result<_Fp> __from_chars_floating_point( + _LIBCPP_NOESCAPE const char* __first, _LIBCPP_NOESCAPE const char* __last, chars_format __fmt); + +extern template __from_chars_result __from_chars_floating_point( + _LIBCPP_NOESCAPE const char* __first, _LIBCPP_NOESCAPE const char* __last, chars_format __fmt); + +extern template __from_chars_result __from_chars_floating_point( + _LIBCPP_NOESCAPE const char* __first, _LIBCPP_NOESCAPE const char* __last, chars_format __fmt); + +template +_LIBCPP_HIDE_FROM_ABI from_chars_result +__from_chars(const char* __first, const char* __last, _Fp& __value, chars_format __fmt) { + __from_chars_result<_Fp> __r = std::__from_chars_floating_point<_Fp>(__first, __last, __fmt); + if (__r.__ec != errc::invalid_argument) + __value = __r.__value; + return {__first + __r.__n, __r.__ec}; +} + +_LIBCPP_AVAILABILITY_FROM_CHARS_FLOATING_POINT _LIBCPP_HIDE_FROM_ABI inline from_chars_result +from_chars(const char* __first, const char* __last, float& __value, chars_format __fmt = chars_format::general) { + return std::__from_chars(__first, __last, __value, __fmt); +} + +_LIBCPP_AVAILABILITY_FROM_CHARS_FLOATING_POINT _LIBCPP_HIDE_FROM_ABI inline from_chars_result +from_chars(const char* __first, const char* __last, double& __value, chars_format __fmt = chars_format::general) { + return std::__from_chars(__first, __last, __value, __fmt); +} + +#endif // _LIBCPP_STD_VER >= 17 + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___CHARCONV_FROM_CHARS_FLOATING_POINT_H diff --git a/system/lib/libcxx/include/__charconv/tables.h b/system/lib/libcxx/include/__charconv/tables.h index 6b93536b8c1ba..9568bf841cd02 100644 --- a/system/lib/libcxx/include/__charconv/tables.h +++ b/system/lib/libcxx/include/__charconv/tables.h @@ -95,7 +95,7 @@ inline constexpr uint64_t __pow10_64[20] = { UINT64_C(1000000000000000000), UINT64_C(10000000000000000000)}; -# ifndef _LIBCPP_HAS_NO_INT128 +# if _LIBCPP_HAS_INT128 inline constexpr int __pow10_128_offset = 0; inline constexpr __uint128_t __pow10_128[40] = { UINT64_C(0), diff --git a/system/lib/libcxx/include/__charconv/to_chars_base_10.h b/system/lib/libcxx/include/__charconv/to_chars_base_10.h index c49f4f6797aa4..06e4e692337df 100644 --- a/system/lib/libcxx/include/__charconv/to_chars_base_10.h +++ b/system/lib/libcxx/include/__charconv/to_chars_base_10.h @@ -124,7 +124,7 @@ __base_10_u64(char* __buffer, uint64_t __value) noexcept { return __itoa::__append10(__buffer, __value); } -# ifndef _LIBCPP_HAS_NO_INT128 +# if _LIBCPP_HAS_INT128 /// \returns 10^\a exp /// /// \pre \a exp [19, 39] diff --git a/system/lib/libcxx/include/__charconv/to_chars_integral.h b/system/lib/libcxx/include/__charconv/to_chars_integral.h index 0369f4dfb9bda..710299df9b4da 100644 --- a/system/lib/libcxx/include/__charconv/to_chars_integral.h +++ b/system/lib/libcxx/include/__charconv/to_chars_integral.h @@ -18,14 +18,15 @@ #include <__charconv/to_chars_result.h> #include <__charconv/traits.h> #include <__config> +#include <__cstddef/ptrdiff_t.h> #include <__system_error/errc.h> #include <__type_traits/enable_if.h> #include <__type_traits/integral_constant.h> +#include <__type_traits/is_integral.h> #include <__type_traits/is_same.h> #include <__type_traits/make_32_64_or_128_bit.h> #include <__type_traits/make_unsigned.h> #include <__utility/unreachable.h> -#include #include #include @@ -70,7 +71,7 @@ __to_chars_itoa(char* __first, char* __last, _Tp __value, false_type) { return {__last, errc::value_too_large}; } -# ifndef _LIBCPP_HAS_NO_INT128 +# if _LIBCPP_HAS_INT128 template <> inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI to_chars_result __to_chars_itoa(char* __first, char* __last, __uint128_t __value, false_type) { diff --git a/system/lib/libcxx/include/__charconv/traits.h b/system/lib/libcxx/include/__charconv/traits.h index c91c6da324797..2cb37c8cfb023 100644 --- a/system/lib/libcxx/include/__charconv/traits.h +++ b/system/lib/libcxx/include/__charconv/traits.h @@ -88,7 +88,7 @@ struct _LIBCPP_HIDDEN __traits_base<_Tp, __enable_if_t struct _LIBCPP_HIDDEN __traits_base<_Tp, __enable_if_t > { using type = __uint128_t; diff --git a/system/lib/libcxx/include/__chrono/convert_to_tm.h b/system/lib/libcxx/include/__chrono/convert_to_tm.h index 3a51019b80784..7d06a38d87f26 100644 --- a/system/lib/libcxx/include/__chrono/convert_to_tm.h +++ b/system/lib/libcxx/include/__chrono/convert_to_tm.h @@ -24,6 +24,7 @@ #include <__chrono/sys_info.h> #include <__chrono/system_clock.h> #include <__chrono/time_point.h> +#include <__chrono/utc_clock.h> #include <__chrono/weekday.h> #include <__chrono/year.h> #include <__chrono/year_month.h> @@ -98,6 +99,22 @@ _LIBCPP_HIDE_FROM_ABI _Tm __convert_to_tm(const chrono::sys_time<_Duration> __tp return __result; } +# if _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION +# if _LIBCPP_HAS_EXPERIMENTAL_TZDB + +template +_LIBCPP_HIDE_FROM_ABI _Tm __convert_to_tm(chrono::utc_time<_Duration> __tp) { + _Tm __result = std::__convert_to_tm<_Tm>(chrono::utc_clock::to_sys(__tp)); + + if (chrono::get_leap_second_info(__tp).is_leap_second) + ++__result.tm_sec; + + return __result; +} + +# endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB +# endif // _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION + // Convert a chrono (calendar) time point, or dururation to the given _Tm type, // which must have the same properties as std::tm. template @@ -110,13 +127,19 @@ _LIBCPP_HIDE_FROM_ABI _Tm __convert_to_tm(const _ChronoT& __value) { if constexpr (__is_time_point<_ChronoT>) { if constexpr (same_as) return std::__convert_to_tm<_Tm>(__value); +# if _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION +# if _LIBCPP_HAS_EXPERIMENTAL_TZDB + else if constexpr (same_as) + return std::__convert_to_tm<_Tm>(__value); +# endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB +# endif // _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION else if constexpr (same_as) return std::__convert_to_tm<_Tm>(_ChronoT::clock::to_sys(__value)); else if constexpr (same_as) return std::__convert_to_tm<_Tm>(chrono::sys_time{__value.time_since_epoch()}); else static_assert(sizeof(_ChronoT) == 0, "TODO: Add the missing clock specialization"); - } else if constexpr (chrono::__is_duration<_ChronoT>::value) { + } else if constexpr (chrono::__is_duration_v<_ChronoT>) { // [time.format]/6 // ... However, if a flag refers to a "time of day" (e.g. %H, %I, %p, // etc.), then a specialization of duration is interpreted as the time of @@ -175,18 +198,17 @@ _LIBCPP_HIDE_FROM_ABI _Tm __convert_to_tm(const _ChronoT& __value) { if (__value.hours().count() > std::numeric_limits::max()) std::__throw_format_error("Formatting hh_mm_ss, encountered an hour overflow"); __result.tm_hour = __value.hours().count(); -# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) +# if _LIBCPP_HAS_EXPERIMENTAL_TZDB } else if constexpr (same_as<_ChronoT, chrono::sys_info>) { // Has no time information. } else if constexpr (same_as<_ChronoT, chrono::local_info>) { // Has no time information. -# if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \ - !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# if _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION } else if constexpr (__is_specialization_v<_ChronoT, chrono::zoned_time>) { return std::__convert_to_tm<_Tm>( chrono::sys_time{__value.get_local_time().time_since_epoch()}); # endif -# endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) +# endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB } else static_assert(sizeof(_ChronoT) == 0, "Add the missing type specialization"); diff --git a/system/lib/libcxx/include/__chrono/day.h b/system/lib/libcxx/include/__chrono/day.h index 7342084b08c88..f5b14689a78ac 100644 --- a/system/lib/libcxx/include/__chrono/day.h +++ b/system/lib/libcxx/include/__chrono/day.h @@ -11,8 +11,8 @@ #define _LIBCPP___CHRONO_DAY_H #include <__chrono/duration.h> +#include <__compare/ordering.h> #include <__config> -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/system/lib/libcxx/include/__chrono/duration.h b/system/lib/libcxx/include/__chrono/duration.h index 1e36d7342836f..941aca6009599 100644 --- a/system/lib/libcxx/include/__chrono/duration.h +++ b/system/lib/libcxx/include/__chrono/duration.h @@ -35,26 +35,25 @@ template > class _LIBCPP_TEMPLATE_VIS duration; template -struct __is_duration : false_type {}; +inline const bool __is_duration_v = false; template -struct __is_duration > : true_type {}; +inline const bool __is_duration_v > = true; template -struct __is_duration > : true_type {}; +inline const bool __is_duration_v > = true; template -struct __is_duration > : true_type {}; +inline const bool __is_duration_v > = true; template -struct __is_duration > : true_type {}; +inline const bool __is_duration_v > = true; } // namespace chrono template struct _LIBCPP_TEMPLATE_VIS common_type, chrono::duration<_Rep2, _Period2> > { - typedef chrono::duration::type, typename __ratio_gcd<_Period1, _Period2>::type> - type; + typedef chrono::duration::type, __ratio_gcd<_Period1, _Period2> > type; }; namespace chrono { @@ -102,7 +101,7 @@ struct __duration_cast<_FromDuration, _ToDuration, _Period, false, false> { } }; -template ::value, int> = 0> +template , int> = 0> inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ToDuration duration_cast(const duration<_Rep, _Period>& __fd) { return __duration_cast, _ToDuration>()(__fd); } @@ -124,7 +123,7 @@ struct _LIBCPP_TEMPLATE_VIS duration_values { }; #if _LIBCPP_STD_VER >= 17 -template ::value, int> = 0> +template , int> = 0> inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ToDuration floor(const duration<_Rep, _Period>& __d) { _ToDuration __t = chrono::duration_cast<_ToDuration>(__d); if (__t > __d) @@ -132,7 +131,7 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ToDuration floor(const duration< return __t; } -template ::value, int> = 0> +template , int> = 0> inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ToDuration ceil(const duration<_Rep, _Period>& __d) { _ToDuration __t = chrono::duration_cast<_ToDuration>(__d); if (__t < __d) @@ -140,7 +139,7 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ToDuration ceil(const duration<_ return __t; } -template ::value, int> = 0> +template , int> = 0> inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ToDuration round(const duration<_Rep, _Period>& __d) { _ToDuration __lower = chrono::floor<_ToDuration>(__d); _ToDuration __upper = __lower + _ToDuration{1}; @@ -158,15 +157,15 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ToDuration round(const duration< template class _LIBCPP_TEMPLATE_VIS duration { - static_assert(!__is_duration<_Rep>::value, "A duration representation can not be a duration"); - static_assert(__is_ratio<_Period>::value, "Second template parameter of duration must be a std::ratio"); + static_assert(!__is_duration_v<_Rep>, "A duration representation can not be a duration"); + static_assert(__is_ratio_v<_Period>, "Second template parameter of duration must be a std::ratio"); static_assert(_Period::num > 0, "duration period must be positive"); template struct __no_overflow { private: - static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value; - static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value; + static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>; + static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>; static const intmax_t __n1 = _R1::num / __gcd_n1_n2; static const intmax_t __d1 = _R1::den / __gcd_d1_d2; static const intmax_t __n2 = _R2::num / __gcd_n1_n2; @@ -434,7 +433,7 @@ operator*(const _Rep1& __s, const duration<_Rep2, _Period>& __d) { template ::value && + __enable_if_t && is_convertible::type>::value, int> = 0> inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR duration::type, _Period> @@ -456,7 +455,7 @@ operator/(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2 template ::value && + __enable_if_t && is_convertible::type>::value, int> = 0> inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR duration::type, _Period> @@ -543,8 +542,4 @@ _LIBCPP_END_NAMESPACE_STD _LIBCPP_POP_MACROS -#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 -# include -#endif - #endif // _LIBCPP___CHRONO_DURATION_H diff --git a/system/lib/libcxx/include/__chrono/exception.h b/system/lib/libcxx/include/__chrono/exception.h index 266f8fac44176..1eb5b1b62d92c 100644 --- a/system/lib/libcxx/include/__chrono/exception.h +++ b/system/lib/libcxx/include/__chrono/exception.h @@ -14,7 +14,7 @@ #include // Enable the contents of the header only when libc++ was built with experimental features enabled. -#if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) +#if _LIBCPP_HAS_EXPERIMENTAL_TZDB # include <__chrono/calendar.h> # include <__chrono/local_info.h> @@ -71,9 +71,9 @@ class nonexistent_local_time : public runtime_error { }; template -_LIBCPP_NORETURN _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI void __throw_nonexistent_local_time( +[[noreturn]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI void __throw_nonexistent_local_time( [[maybe_unused]] const local_time<_Duration>& __time, [[maybe_unused]] const local_info& __info) { -# ifndef _LIBCPP_HAS_NO_EXCEPTIONS +# if _LIBCPP_HAS_EXCEPTIONS throw nonexistent_local_time(__time, __info); # else _LIBCPP_VERBOSE_ABORT("nonexistent_local_time was thrown in -fno-exceptions mode"); @@ -115,9 +115,9 @@ class ambiguous_local_time : public runtime_error { }; template -_LIBCPP_NORETURN _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI void __throw_ambiguous_local_time( +[[noreturn]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI void __throw_ambiguous_local_time( [[maybe_unused]] const local_time<_Duration>& __time, [[maybe_unused]] const local_info& __info) { -# ifndef _LIBCPP_HAS_NO_EXCEPTIONS +# if _LIBCPP_HAS_EXCEPTIONS throw ambiguous_local_time(__time, __info); # else _LIBCPP_VERBOSE_ABORT("ambiguous_local_time was thrown in -fno-exceptions mode"); @@ -130,6 +130,6 @@ _LIBCPP_NORETURN _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI void __throw_am _LIBCPP_END_NAMESPACE_STD -#endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) +#endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB #endif // _LIBCPP___CHRONO_EXCEPTION_H diff --git a/system/lib/libcxx/include/__chrono/file_clock.h b/system/lib/libcxx/include/__chrono/file_clock.h index 4dd3f88ce5ba4..b4b7e9dc14e70 100644 --- a/system/lib/libcxx/include/__chrono/file_clock.h +++ b/system/lib/libcxx/include/__chrono/file_clock.h @@ -47,7 +47,7 @@ _LIBCPP_END_NAMESPACE_STD #ifndef _LIBCPP_CXX03_LANG _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM struct _FilesystemClock { -# if !defined(_LIBCPP_HAS_NO_INT128) +# if _LIBCPP_HAS_INT128 typedef __int128_t rep; typedef nano period; # else diff --git a/system/lib/libcxx/include/__chrono/formatter.h b/system/lib/libcxx/include/__chrono/formatter.h index 449c415e95760..d17acd274e4cd 100644 --- a/system/lib/libcxx/include/__chrono/formatter.h +++ b/system/lib/libcxx/include/__chrono/formatter.h @@ -10,55 +10,60 @@ #ifndef _LIBCPP___CHRONO_FORMATTER_H #define _LIBCPP___CHRONO_FORMATTER_H -#include <__algorithm/ranges_copy.h> -#include <__chrono/calendar.h> -#include <__chrono/concepts.h> -#include <__chrono/convert_to_tm.h> -#include <__chrono/day.h> -#include <__chrono/duration.h> -#include <__chrono/file_clock.h> -#include <__chrono/hh_mm_ss.h> -#include <__chrono/local_info.h> -#include <__chrono/month.h> -#include <__chrono/month_weekday.h> -#include <__chrono/monthday.h> -#include <__chrono/ostream.h> -#include <__chrono/parser_std_format_spec.h> -#include <__chrono/statically_widen.h> -#include <__chrono/sys_info.h> -#include <__chrono/system_clock.h> -#include <__chrono/time_point.h> -#include <__chrono/weekday.h> -#include <__chrono/year.h> -#include <__chrono/year_month.h> -#include <__chrono/year_month_day.h> -#include <__chrono/year_month_weekday.h> -#include <__chrono/zoned_time.h> -#include <__concepts/arithmetic.h> -#include <__concepts/same_as.h> #include <__config> -#include <__format/concepts.h> -#include <__format/format_error.h> -#include <__format/format_functions.h> -#include <__format/format_parse_context.h> -#include <__format/formatter.h> -#include <__format/parser_std_format_spec.h> -#include <__format/write_escaped.h> -#include <__memory/addressof.h> -#include <__type_traits/is_specialization.h> -#include -#include -#include -#include -#include - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif + +#if _LIBCPP_HAS_LOCALIZATION + +# include <__algorithm/ranges_copy.h> +# include <__chrono/calendar.h> +# include <__chrono/concepts.h> +# include <__chrono/convert_to_tm.h> +# include <__chrono/day.h> +# include <__chrono/duration.h> +# include <__chrono/file_clock.h> +# include <__chrono/hh_mm_ss.h> +# include <__chrono/local_info.h> +# include <__chrono/month.h> +# include <__chrono/month_weekday.h> +# include <__chrono/monthday.h> +# include <__chrono/ostream.h> +# include <__chrono/parser_std_format_spec.h> +# include <__chrono/statically_widen.h> +# include <__chrono/sys_info.h> +# include <__chrono/system_clock.h> +# include <__chrono/time_point.h> +# include <__chrono/utc_clock.h> +# include <__chrono/weekday.h> +# include <__chrono/year.h> +# include <__chrono/year_month.h> +# include <__chrono/year_month_day.h> +# include <__chrono/year_month_weekday.h> +# include <__chrono/zoned_time.h> +# include <__concepts/arithmetic.h> +# include <__concepts/same_as.h> +# include <__format/concepts.h> +# include <__format/format_error.h> +# include <__format/format_functions.h> +# include <__format/format_parse_context.h> +# include <__format/formatter.h> +# include <__format/parser_std_format_spec.h> +# include <__format/write_escaped.h> +# include <__memory/addressof.h> +# include <__type_traits/is_specialization.h> +# include +# include +# include +# include +# include +# include + +# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +# endif _LIBCPP_BEGIN_NAMESPACE_STD -#if _LIBCPP_STD_VER >= 20 +# if _LIBCPP_STD_VER >= 20 namespace __formatter { @@ -139,25 +144,23 @@ __format_sub_seconds(basic_stringstream<_CharT>& __sstr, const chrono::hh_mm_ss< __value.fractional_width); } -# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && \ - !defined(_LIBCPP_HAS_NO_FILESYSTEM) && !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# if _LIBCPP_HAS_EXPERIMENTAL_TZDB && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM template _LIBCPP_HIDE_FROM_ABI void __format_sub_seconds(basic_stringstream<_CharT>& __sstr, const chrono::zoned_time<_Duration, _TimeZonePtr>& __value) { __formatter::__format_sub_seconds(__sstr, __value.get_local_time().time_since_epoch()); } -# endif +# endif template consteval bool __use_fraction() { if constexpr (__is_time_point<_Tp>) return chrono::hh_mm_ss::fractional_width; -# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && \ - !defined(_LIBCPP_HAS_NO_FILESYSTEM) && !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# if _LIBCPP_HAS_EXPERIMENTAL_TZDB && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM else if constexpr (__is_specialization_v<_Tp, chrono::zoned_time>) return chrono::hh_mm_ss::fractional_width; -# endif - else if constexpr (chrono::__is_duration<_Tp>::value) +# endif + else if constexpr (chrono::__is_duration_v<_Tp>) return chrono::hh_mm_ss<_Tp>::fractional_width; else if constexpr (__is_hh_mm_ss<_Tp>) return _Tp::fractional_width; @@ -225,16 +228,15 @@ struct _LIBCPP_HIDE_FROM_ABI __time_zone { template _LIBCPP_HIDE_FROM_ABI __time_zone __convert_to_time_zone([[maybe_unused]] const _Tp& __value) { -# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) +# if _LIBCPP_HAS_EXPERIMENTAL_TZDB if constexpr (same_as<_Tp, chrono::sys_info>) return {__value.abbrev, __value.offset}; -# if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \ - !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# if _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM else if constexpr (__is_specialization_v<_Tp, chrono::zoned_time>) return __formatter::__convert_to_time_zone(__value.get_info()); -# endif +# endif else -# endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) +# endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB return {"UTC", chrono::seconds{0}}; } @@ -272,7 +274,7 @@ _LIBCPP_HIDE_FROM_ABI void __format_chrono_using_chrono_specs( } break; case _CharT('j'): - if constexpr (chrono::__is_duration<_Tp>::value) + if constexpr (chrono::__is_duration_v<_Tp>) // Converting a duration where the period has a small ratio to days // may fail to compile. This due to loss of precision in the // conversion. In order to avoid that issue convert to seconds as @@ -284,7 +286,7 @@ _LIBCPP_HIDE_FROM_ABI void __format_chrono_using_chrono_specs( break; case _CharT('q'): - if constexpr (chrono::__is_duration<_Tp>::value) { + if constexpr (chrono::__is_duration_v<_Tp>) { __sstr << chrono::__units_suffix<_CharT, typename _Tp::period>(); break; } @@ -300,7 +302,7 @@ _LIBCPP_HIDE_FROM_ABI void __format_chrono_using_chrono_specs( // MSVC STL ignores precision but uses separator // FMT honours precision and has a bug for separator // https://godbolt.org/z/78b7sMxns - if constexpr (chrono::__is_duration<_Tp>::value) { + if constexpr (chrono::__is_duration_v<_Tp>) { __sstr << std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "{}"), __value.count()); break; } @@ -341,16 +343,16 @@ _LIBCPP_HIDE_FROM_ABI void __format_chrono_using_chrono_specs( // // TODO FMT evaluate the comment above. -# if defined(__GLIBC__) || defined(_AIX) || defined(_WIN32) +# if defined(__GLIBC__) || defined(_AIX) || defined(_WIN32) case _CharT('y'): // Glibc fails for negative values, AIX for positive values too. __sstr << std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "{:02}"), (std::abs(__t.tm_year + 1900)) % 100); break; -# endif // defined(__GLIBC__) || defined(_AIX) || defined(_WIN32) +# endif // defined(__GLIBC__) || defined(_AIX) || defined(_WIN32) case _CharT('Y'): // Depending on the platform's libc the range of supported years is - // limited. Intead of of testing all conditions use the internal + // limited. Instead of of testing all conditions use the internal // implementation unconditionally. __formatter::__format_year(__sstr, __t.tm_year + 1900); break; @@ -442,17 +444,16 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool __weekday_ok(const _Tp& __value) { return __value.weekday().ok(); else if constexpr (__is_hh_mm_ss<_Tp>) return true; -# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) +# if _LIBCPP_HAS_EXPERIMENTAL_TZDB else if constexpr (same_as<_Tp, chrono::sys_info>) return true; else if constexpr (same_as<_Tp, chrono::local_info>) return true; -# if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \ - !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# if _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM else if constexpr (__is_specialization_v<_Tp, chrono::zoned_time>) return true; -# endif -# endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) +# endif +# endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB else static_assert(sizeof(_Tp) == 0, "Add the missing type specialization"); } @@ -493,17 +494,16 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool __weekday_name_ok(const _Tp& __value) { return __value.weekday().ok(); else if constexpr (__is_hh_mm_ss<_Tp>) return true; -# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) +# if _LIBCPP_HAS_EXPERIMENTAL_TZDB else if constexpr (same_as<_Tp, chrono::sys_info>) return true; else if constexpr (same_as<_Tp, chrono::local_info>) return true; -# if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \ - !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# if _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM else if constexpr (__is_specialization_v<_Tp, chrono::zoned_time>) return true; -# endif -# endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) +# endif +# endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB else static_assert(sizeof(_Tp) == 0, "Add the missing type specialization"); } @@ -544,17 +544,16 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool __date_ok(const _Tp& __value) { return __value.ok(); else if constexpr (__is_hh_mm_ss<_Tp>) return true; -# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) +# if _LIBCPP_HAS_EXPERIMENTAL_TZDB else if constexpr (same_as<_Tp, chrono::sys_info>) return true; else if constexpr (same_as<_Tp, chrono::local_info>) return true; -# if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \ - !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# if _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM else if constexpr (__is_specialization_v<_Tp, chrono::zoned_time>) return true; -# endif -# endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) +# endif +# endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB else static_assert(sizeof(_Tp) == 0, "Add the missing type specialization"); } @@ -595,17 +594,16 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool __month_name_ok(const _Tp& __value) { return __value.month().ok(); else if constexpr (__is_hh_mm_ss<_Tp>) return true; -# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) +# if _LIBCPP_HAS_EXPERIMENTAL_TZDB else if constexpr (same_as<_Tp, chrono::sys_info>) return true; else if constexpr (same_as<_Tp, chrono::local_info>) return true; -# if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \ - !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# if _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM else if constexpr (__is_specialization_v<_Tp, chrono::zoned_time>) return true; -# endif -# endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) +# endif +# endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB else static_assert(sizeof(_Tp) == 0, "Add the missing type specialization"); } @@ -630,7 +628,7 @@ __format_chrono(const _Tp& __value, if (__chrono_specs.empty()) __sstr << __value; else { - if constexpr (chrono::__is_duration<_Tp>::value) { + if constexpr (chrono::__is_duration_v<_Tp>) { // A duration can be a user defined arithmetic type. Users may specialize // numeric_limits, but they may not specialize is_signed. if constexpr (numeric_limits::is_signed) { @@ -714,7 +712,7 @@ struct _LIBCPP_TEMPLATE_VIS __formatter_chrono { template struct _LIBCPP_TEMPLATE_VIS formatter, _CharT> : public __formatter_chrono<_CharT> { public: - using _Base = __formatter_chrono<_CharT>; + using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>; template _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { @@ -722,10 +720,27 @@ struct _LIBCPP_TEMPLATE_VIS formatter, _CharT> : pub } }; +# if _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM +# if _LIBCPP_HAS_EXPERIMENTAL_TZDB + +template +struct _LIBCPP_TEMPLATE_VIS formatter, _CharT> : public __formatter_chrono<_CharT> { +public: + using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>; + + template + _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { + return _Base::__parse(__ctx, __format_spec::__fields_chrono, __format_spec::__flags::__clock); + } +}; + +# endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB +# endif // _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM + template struct _LIBCPP_TEMPLATE_VIS formatter, _CharT> : public __formatter_chrono<_CharT> { public: - using _Base = __formatter_chrono<_CharT>; + using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>; template _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { @@ -736,7 +751,7 @@ struct _LIBCPP_TEMPLATE_VIS formatter, _CharT> : pu template struct _LIBCPP_TEMPLATE_VIS formatter, _CharT> : public __formatter_chrono<_CharT> { public: - using _Base = __formatter_chrono<_CharT>; + using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>; template _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { @@ -748,7 +763,7 @@ struct _LIBCPP_TEMPLATE_VIS formatter, _CharT> : p template struct formatter, _CharT> : public __formatter_chrono<_CharT> { public: - using _Base = __formatter_chrono<_CharT>; + using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>; template _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { @@ -770,7 +785,7 @@ struct formatter, _CharT> : public __formatter_c template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS formatter : public __formatter_chrono<_CharT> { public: - using _Base = __formatter_chrono<_CharT>; + using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>; template _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { @@ -781,7 +796,7 @@ struct _LIBCPP_TEMPLATE_VIS formatter : public __formatter_ template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS formatter : public __formatter_chrono<_CharT> { public: - using _Base = __formatter_chrono<_CharT>; + using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>; template _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { @@ -792,7 +807,7 @@ struct _LIBCPP_TEMPLATE_VIS formatter : public __formatte template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS formatter : public __formatter_chrono<_CharT> { public: - using _Base = __formatter_chrono<_CharT>; + using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>; template _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { @@ -803,7 +818,7 @@ struct _LIBCPP_TEMPLATE_VIS formatter : public __formatter template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS formatter : public __formatter_chrono<_CharT> { public: - using _Base = __formatter_chrono<_CharT>; + using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>; template _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { @@ -814,7 +829,7 @@ struct _LIBCPP_TEMPLATE_VIS formatter : public __format template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS formatter : public __formatter_chrono<_CharT> { public: - using _Base = __formatter_chrono<_CharT>; + using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>; template _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { @@ -825,7 +840,7 @@ struct _LIBCPP_TEMPLATE_VIS formatter : public template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS formatter : public __formatter_chrono<_CharT> { public: - using _Base = __formatter_chrono<_CharT>; + using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>; template _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { @@ -836,7 +851,7 @@ struct _LIBCPP_TEMPLATE_VIS formatter : public __f template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS formatter : public __formatter_chrono<_CharT> { public: - using _Base = __formatter_chrono<_CharT>; + using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>; template _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { @@ -847,7 +862,7 @@ struct _LIBCPP_TEMPLATE_VIS formatter : public __form template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS formatter : public __formatter_chrono<_CharT> { public: - using _Base = __formatter_chrono<_CharT>; + using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>; template _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { @@ -858,7 +873,7 @@ struct _LIBCPP_TEMPLATE_VIS formatter : public _ template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS formatter : public __formatter_chrono<_CharT> { public: - using _Base = __formatter_chrono<_CharT>; + using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>; template _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { @@ -869,7 +884,7 @@ struct _LIBCPP_TEMPLATE_VIS formatter : public __ template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS formatter : public __formatter_chrono<_CharT> { public: - using _Base = __formatter_chrono<_CharT>; + using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>; template _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { @@ -880,7 +895,7 @@ struct _LIBCPP_TEMPLATE_VIS formatter : publ template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS formatter : public __formatter_chrono<_CharT> { public: - using _Base = __formatter_chrono<_CharT>; + using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>; template _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { @@ -891,7 +906,7 @@ struct _LIBCPP_TEMPLATE_VIS formatter : public __for template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS formatter : public __formatter_chrono<_CharT> { public: - using _Base = __formatter_chrono<_CharT>; + using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>; template _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { @@ -902,7 +917,7 @@ struct _LIBCPP_TEMPLATE_VIS formatter : public _ template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS formatter : public __formatter_chrono<_CharT> { public: - using _Base = __formatter_chrono<_CharT>; + using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>; template _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { @@ -913,7 +928,7 @@ struct _LIBCPP_TEMPLATE_VIS formatter : pub template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS formatter : public __formatter_chrono<_CharT> { public: - using _Base = __formatter_chrono<_CharT>; + using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>; template _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { @@ -924,7 +939,7 @@ struct _LIBCPP_TEMPLATE_VIS formatter : publ template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS formatter : public __formatter_chrono<_CharT> { public: - using _Base = __formatter_chrono<_CharT>; + using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>; template _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { @@ -935,7 +950,7 @@ struct _LIBCPP_TEMPLATE_VIS formatter : template struct formatter, _CharT> : public __formatter_chrono<_CharT> { public: - using _Base = __formatter_chrono<_CharT>; + using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>; template _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { @@ -943,11 +958,11 @@ struct formatter, _CharT> : public __formatter_chron } }; -# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) +# if _LIBCPP_HAS_EXPERIMENTAL_TZDB template <__fmt_char_type _CharT> struct formatter : public __formatter_chrono<_CharT> { public: - using _Base = __formatter_chrono<_CharT>; + using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>; template _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { @@ -958,33 +973,33 @@ struct formatter : public __formatter_chrono<_CharT> { template <__fmt_char_type _CharT> struct formatter : public __formatter_chrono<_CharT> { public: - using _Base = __formatter_chrono<_CharT>; + using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>; template _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { return _Base::__parse(__ctx, __format_spec::__fields_chrono, __format_spec::__flags{}); } }; -# if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \ - !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# if _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM // Note due to how libc++'s formatters are implemented there is no need to add // the exposition only local-time-format-t abstraction. template struct formatter, _CharT> : public __formatter_chrono<_CharT> { public: - using _Base = __formatter_chrono<_CharT>; + using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>; template _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { return _Base::__parse(__ctx, __format_spec::__fields_chrono, __format_spec::__flags::__clock); } }; -# endif // !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && - // !defined(_LIBCPP_HAS_NO_LOCALIZATION) -# endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) +# endif // _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM +# endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB -#endif // if _LIBCPP_STD_VER >= 20 +# endif // if _LIBCPP_STD_VER >= 20 _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_HAS_LOCALIZATION + #endif // _LIBCPP___CHRONO_FORMATTER_H diff --git a/system/lib/libcxx/include/__chrono/hh_mm_ss.h b/system/lib/libcxx/include/__chrono/hh_mm_ss.h index 57d2247fe6a3c..6ea8a28ee0938 100644 --- a/system/lib/libcxx/include/__chrono/hh_mm_ss.h +++ b/system/lib/libcxx/include/__chrono/hh_mm_ss.h @@ -29,8 +29,8 @@ namespace chrono { template class hh_mm_ss { private: - static_assert(__is_duration<_Duration>::value, "template parameter of hh_mm_ss must be a std::chrono::duration"); - using __CommonType = common_type_t<_Duration, chrono::seconds>; + static_assert(__is_duration_v<_Duration>, "template parameter of hh_mm_ss must be a std::chrono::duration"); + using __CommonType _LIBCPP_NODEBUG = common_type_t<_Duration, chrono::seconds>; _LIBCPP_HIDE_FROM_ABI static constexpr uint64_t __pow10(unsigned __exp) { uint64_t __ret = 1; diff --git a/system/lib/libcxx/include/__chrono/high_resolution_clock.h b/system/lib/libcxx/include/__chrono/high_resolution_clock.h index 0697fd2de9b4d..d324c7f0283bf 100644 --- a/system/lib/libcxx/include/__chrono/high_resolution_clock.h +++ b/system/lib/libcxx/include/__chrono/high_resolution_clock.h @@ -22,7 +22,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD namespace chrono { -#ifndef _LIBCPP_HAS_NO_MONOTONIC_CLOCK +#if _LIBCPP_HAS_MONOTONIC_CLOCK typedef steady_clock high_resolution_clock; #else typedef system_clock high_resolution_clock; diff --git a/system/lib/libcxx/include/__chrono/leap_second.h b/system/lib/libcxx/include/__chrono/leap_second.h index 1a0e7f3107de8..1857bef80376e 100644 --- a/system/lib/libcxx/include/__chrono/leap_second.h +++ b/system/lib/libcxx/include/__chrono/leap_second.h @@ -14,7 +14,7 @@ #include // Enable the contents of the header only when libc++ was built with experimental features enabled. -#if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) +#if _LIBCPP_HAS_EXPERIMENTAL_TZDB # include <__chrono/duration.h> # include <__chrono/system_clock.h> @@ -43,84 +43,89 @@ class leap_second { _LIBCPP_HIDE_FROM_ABI leap_second(const leap_second&) = default; _LIBCPP_HIDE_FROM_ABI leap_second& operator=(const leap_second&) = default; - _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI constexpr sys_seconds date() const noexcept { return __date_; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr sys_seconds date() const noexcept { return __date_; } - _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI constexpr seconds value() const noexcept { return __value_; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr seconds value() const noexcept { return __value_; } private: sys_seconds __date_; seconds __value_; -}; -_LIBCPP_HIDE_FROM_ABI inline constexpr bool operator==(const leap_second& __x, const leap_second& __y) { - return __x.date() == __y.date(); -} - -_LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering operator<=>(const leap_second& __x, const leap_second& __y) { - return __x.date() <=> __y.date(); -} - -template -_LIBCPP_HIDE_FROM_ABI constexpr bool operator==(const leap_second& __x, const sys_time<_Duration>& __y) { - return __x.date() == __y; -} - -template -_LIBCPP_HIDE_FROM_ABI constexpr bool operator<(const leap_second& __x, const sys_time<_Duration>& __y) { - return __x.date() < __y; -} - -template -_LIBCPP_HIDE_FROM_ABI constexpr bool operator<(const sys_time<_Duration>& __x, const leap_second& __y) { - return __x < __y.date(); -} - -template -_LIBCPP_HIDE_FROM_ABI constexpr bool operator>(const leap_second& __x, const sys_time<_Duration>& __y) { - return __y < __x; -} - -template -_LIBCPP_HIDE_FROM_ABI constexpr bool operator>(const sys_time<_Duration>& __x, const leap_second& __y) { - return __y < __x; -} - -template -_LIBCPP_HIDE_FROM_ABI constexpr bool operator<=(const leap_second& __x, const sys_time<_Duration>& __y) { - return !(__y < __x); -} - -template -_LIBCPP_HIDE_FROM_ABI constexpr bool operator<=(const sys_time<_Duration>& __x, const leap_second& __y) { - return !(__y < __x); -} - -template -_LIBCPP_HIDE_FROM_ABI constexpr bool operator>=(const leap_second& __x, const sys_time<_Duration>& __y) { - return !(__x < __y); -} - -template -_LIBCPP_HIDE_FROM_ABI constexpr bool operator>=(const sys_time<_Duration>& __x, const leap_second& __y) { - return !(__x < __y); -} - -# ifndef _LIBCPP_COMPILER_GCC -// This requirement cause a compilation loop in GCC-13 and running out of memory. -// TODO TZDB Test whether GCC-14 fixes this. -template - requires three_way_comparable_with> -_LIBCPP_HIDE_FROM_ABI constexpr auto operator<=>(const leap_second& __x, const sys_time<_Duration>& __y) { - return __x.date() <=> __y; -} -# endif + // The function + // template + // requires three_way_comparable_with> + // constexpr auto operator<=>(const leap_second& x, const sys_time& y) noexcept; + // + // Has constraints that are recursive (LWG4139). The proposed resolution is + // to make the funcion a hidden friend. For consistency make this change for + // all comparison functions. + + _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const leap_second& __x, const leap_second& __y) { + return __x.date() == __y.date(); + } + + _LIBCPP_HIDE_FROM_ABI friend constexpr strong_ordering operator<=>(const leap_second& __x, const leap_second& __y) { + return __x.date() <=> __y.date(); + } + + template + _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const leap_second& __x, const sys_time<_Duration>& __y) { + return __x.date() == __y; + } + + template + _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<(const leap_second& __x, const sys_time<_Duration>& __y) { + return __x.date() < __y; + } + + template + _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<(const sys_time<_Duration>& __x, const leap_second& __y) { + return __x < __y.date(); + } + + template + _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>(const leap_second& __x, const sys_time<_Duration>& __y) { + return __y < __x; + } + + template + _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>(const sys_time<_Duration>& __x, const leap_second& __y) { + return __y < __x; + } + + template + _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<=(const leap_second& __x, const sys_time<_Duration>& __y) { + return !(__y < __x); + } + + template + _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<=(const sys_time<_Duration>& __x, const leap_second& __y) { + return !(__y < __x); + } + + template + _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>=(const leap_second& __x, const sys_time<_Duration>& __y) { + return !(__x < __y); + } + + template + _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>=(const sys_time<_Duration>& __x, const leap_second& __y) { + return !(__x < __y); + } + + template + requires three_way_comparable_with> + _LIBCPP_HIDE_FROM_ABI friend constexpr auto operator<=>(const leap_second& __x, const sys_time<_Duration>& __y) { + return __x.date() <=> __y; + } +}; } // namespace chrono -# endif //_LIBCPP_STD_VER >= 20 +# endif // _LIBCPP_STD_VER >= 20 _LIBCPP_END_NAMESPACE_STD -#endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) +#endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB #endif // _LIBCPP___CHRONO_LEAP_SECOND_H diff --git a/system/lib/libcxx/include/__chrono/local_info.h b/system/lib/libcxx/include/__chrono/local_info.h index cfe1448904d3f..31cf77761d6ae 100644 --- a/system/lib/libcxx/include/__chrono/local_info.h +++ b/system/lib/libcxx/include/__chrono/local_info.h @@ -14,7 +14,7 @@ #include // Enable the contents of the header only when libc++ was built with experimental features enabled. -#if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) +#if _LIBCPP_HAS_EXPERIMENTAL_TZDB # include <__chrono/sys_info.h> # include <__config> @@ -45,6 +45,6 @@ struct local_info { _LIBCPP_END_NAMESPACE_STD -#endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) +#endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB #endif // _LIBCPP___CHRONO_LOCAL_INFO_H diff --git a/system/lib/libcxx/include/__chrono/month.h b/system/lib/libcxx/include/__chrono/month.h index ce5cc21aab7d1..77c67d0954efa 100644 --- a/system/lib/libcxx/include/__chrono/month.h +++ b/system/lib/libcxx/include/__chrono/month.h @@ -11,8 +11,8 @@ #define _LIBCPP___CHRONO_MONTH_H #include <__chrono/duration.h> +#include <__compare/ordering.h> #include <__config> -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/system/lib/libcxx/include/__chrono/monthday.h b/system/lib/libcxx/include/__chrono/monthday.h index a89d16e518618..57712cf0b65a8 100644 --- a/system/lib/libcxx/include/__chrono/monthday.h +++ b/system/lib/libcxx/include/__chrono/monthday.h @@ -13,8 +13,8 @@ #include <__chrono/calendar.h> #include <__chrono/day.h> #include <__chrono/month.h> +#include <__compare/ordering.h> #include <__config> -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/system/lib/libcxx/include/__chrono/ostream.h b/system/lib/libcxx/include/__chrono/ostream.h index e6c43254eea15..ed9ad8e346ba9 100644 --- a/system/lib/libcxx/include/__chrono/ostream.h +++ b/system/lib/libcxx/include/__chrono/ostream.h @@ -10,37 +10,42 @@ #ifndef _LIBCPP___CHRONO_OSTREAM_H #define _LIBCPP___CHRONO_OSTREAM_H -#include <__chrono/calendar.h> -#include <__chrono/day.h> -#include <__chrono/duration.h> -#include <__chrono/file_clock.h> -#include <__chrono/hh_mm_ss.h> -#include <__chrono/local_info.h> -#include <__chrono/month.h> -#include <__chrono/month_weekday.h> -#include <__chrono/monthday.h> -#include <__chrono/statically_widen.h> -#include <__chrono/sys_info.h> -#include <__chrono/system_clock.h> -#include <__chrono/weekday.h> -#include <__chrono/year.h> -#include <__chrono/year_month.h> -#include <__chrono/year_month_day.h> -#include <__chrono/year_month_weekday.h> -#include <__chrono/zoned_time.h> -#include <__concepts/same_as.h> #include <__config> -#include <__format/format_functions.h> -#include <__fwd/ostream.h> -#include -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif +#if _LIBCPP_HAS_LOCALIZATION + +# include <__chrono/calendar.h> +# include <__chrono/day.h> +# include <__chrono/duration.h> +# include <__chrono/file_clock.h> +# include <__chrono/hh_mm_ss.h> +# include <__chrono/local_info.h> +# include <__chrono/month.h> +# include <__chrono/month_weekday.h> +# include <__chrono/monthday.h> +# include <__chrono/statically_widen.h> +# include <__chrono/sys_info.h> +# include <__chrono/system_clock.h> +# include <__chrono/utc_clock.h> +# include <__chrono/weekday.h> +# include <__chrono/year.h> +# include <__chrono/year_month.h> +# include <__chrono/year_month_day.h> +# include <__chrono/year_month_weekday.h> +# include <__chrono/zoned_time.h> +# include <__concepts/same_as.h> +# include <__format/format_functions.h> +# include <__fwd/ostream.h> +# include +# include + +# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +# endif _LIBCPP_BEGIN_NAMESPACE_STD -#if _LIBCPP_STD_VER >= 20 +# if _LIBCPP_STD_VER >= 20 namespace chrono { @@ -57,6 +62,18 @@ operator<<(basic_ostream<_CharT, _Traits>& __os, const sys_days& __dp) { return __os << year_month_day{__dp}; } +# if _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM +# if _LIBCPP_HAS_EXPERIMENTAL_TZDB + +template +_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, const utc_time<_Duration>& __tp) { + return __os << std::format(__os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L%F %T}"), __tp); +} + +# endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB +# endif // _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM + template _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const file_time<_Duration> __tp) { @@ -82,11 +99,11 @@ _LIBCPP_HIDE_FROM_ABI auto __units_suffix() { else if constexpr (same_as) return _LIBCPP_STATICALLY_WIDEN(_CharT, "ns"); else if constexpr (same_as) -# ifndef _LIBCPP_HAS_NO_UNICODE +# if _LIBCPP_HAS_UNICODE return _LIBCPP_STATICALLY_WIDEN(_CharT, "\u00b5s"); -# else +# else return _LIBCPP_STATICALLY_WIDEN(_CharT, "us"); -# endif +# endif else if constexpr (same_as) return _LIBCPP_STATICALLY_WIDEN(_CharT, "ms"); else if constexpr (same_as) @@ -265,7 +282,7 @@ operator<<(basic_ostream<_CharT, _Traits>& __os, const hh_mm_ss<_Duration> __hms return __os << std::format(__os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L%T}"), __hms); } -# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) +# if _LIBCPP_HAS_EXPERIMENTAL_TZDB template _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& @@ -303,20 +320,21 @@ operator<<(basic_ostream<_CharT, _Traits>& __os, const local_info& __info) { _LIBCPP_STATICALLY_WIDEN(_CharT, "{}: {{{}, {}}}"), __result(), __info.first, __info.second); } -# if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \ - !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# if _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM template _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const zoned_time<_Duration, _TimeZonePtr>& __tp) { return __os << std::format(__os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L%F %T %Z}"), __tp); } -# endif -# endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) +# endif +# endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB } // namespace chrono -#endif // if _LIBCPP_STD_VER >= 20 +# endif // if _LIBCPP_STD_VER >= 20 _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_HAS_LOCALIZATION + #endif // _LIBCPP___CHRONO_OSTREAM_H diff --git a/system/lib/libcxx/include/__chrono/parser_std_format_spec.h b/system/lib/libcxx/include/__chrono/parser_std_format_spec.h index 785bbae198e46..4df8e603c6bcf 100644 --- a/system/lib/libcxx/include/__chrono/parser_std_format_spec.h +++ b/system/lib/libcxx/include/__chrono/parser_std_format_spec.h @@ -11,20 +11,23 @@ #define _LIBCPP___CHRONO_PARSER_STD_FORMAT_SPEC_H #include <__config> -#include <__format/concepts.h> -#include <__format/format_error.h> -#include <__format/format_parse_context.h> -#include <__format/formatter_string.h> -#include <__format/parser_std_format_spec.h> -#include -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif +#if _LIBCPP_HAS_LOCALIZATION + +# include <__format/concepts.h> +# include <__format/format_error.h> +# include <__format/format_parse_context.h> +# include <__format/formatter_string.h> +# include <__format/parser_std_format_spec.h> +# include + +# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +# endif _LIBCPP_BEGIN_NAMESPACE_STD -#if _LIBCPP_STD_VER >= 20 +# if _LIBCPP_STD_VER >= 20 namespace __format_spec { @@ -137,7 +140,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr void __validate_time_zone(__flags __flags) { template class _LIBCPP_TEMPLATE_VIS __parser_chrono { - using _ConstIterator = typename basic_format_parse_context<_CharT>::const_iterator; + using _ConstIterator _LIBCPP_NODEBUG = typename basic_format_parse_context<_CharT>::const_iterator; public: template @@ -409,8 +412,10 @@ class _LIBCPP_TEMPLATE_VIS __parser_chrono { } // namespace __format_spec -#endif //_LIBCPP_STD_VER >= 20 +# endif // _LIBCPP_STD_VER >= 20 _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_HAS_LOCALIZATION + #endif // _LIBCPP___CHRONO_PARSER_STD_FORMAT_SPEC_H diff --git a/system/lib/libcxx/include/__chrono/statically_widen.h b/system/lib/libcxx/include/__chrono/statically_widen.h index a18c46f057a81..40e085633b8c1 100644 --- a/system/lib/libcxx/include/__chrono/statically_widen.h +++ b/system/lib/libcxx/include/__chrono/statically_widen.h @@ -24,7 +24,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD #if _LIBCPP_STD_VER >= 20 -# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +# if _LIBCPP_HAS_WIDE_CHARACTERS template <__fmt_char_type _CharT> _LIBCPP_HIDE_FROM_ABI constexpr const _CharT* __statically_widen(const char* __str, const wchar_t* __wstr) { if constexpr (same_as<_CharT, char>) @@ -33,7 +33,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr const _CharT* __statically_widen(const char* __s return __wstr; } # define _LIBCPP_STATICALLY_WIDEN(_CharT, __str) ::std::__statically_widen<_CharT>(__str, L##__str) -# else // _LIBCPP_HAS_NO_WIDE_CHARACTERS +# else // _LIBCPP_HAS_WIDE_CHARACTERS // Without this indirection the unit test test/libcxx/modules_include.sh.cpp // fails for the CI build "No wide characters". This seems like a bug. @@ -43,9 +43,9 @@ _LIBCPP_HIDE_FROM_ABI constexpr const _CharT* __statically_widen(const char* __s return __str; } # define _LIBCPP_STATICALLY_WIDEN(_CharT, __str) ::std::__statically_widen<_CharT>(__str) -# endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS +# endif // _LIBCPP_HAS_WIDE_CHARACTERS -#endif //_LIBCPP_STD_VER >= 20 +#endif // _LIBCPP_STD_VER >= 20 _LIBCPP_END_NAMESPACE_STD diff --git a/system/lib/libcxx/include/__chrono/steady_clock.h b/system/lib/libcxx/include/__chrono/steady_clock.h index 612a7f156e634..1b247b2c28609 100644 --- a/system/lib/libcxx/include/__chrono/steady_clock.h +++ b/system/lib/libcxx/include/__chrono/steady_clock.h @@ -22,7 +22,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD namespace chrono { -#ifndef _LIBCPP_HAS_NO_MONOTONIC_CLOCK +#if _LIBCPP_HAS_MONOTONIC_CLOCK class _LIBCPP_EXPORTED_FROM_ABI steady_clock { public: typedef nanoseconds duration; diff --git a/system/lib/libcxx/include/__chrono/sys_info.h b/system/lib/libcxx/include/__chrono/sys_info.h index 11536cbde3a37..81e37f2b803f2 100644 --- a/system/lib/libcxx/include/__chrono/sys_info.h +++ b/system/lib/libcxx/include/__chrono/sys_info.h @@ -14,7 +14,7 @@ #include // Enable the contents of the header only when libc++ was built with experimental features enabled. -#if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) +#if _LIBCPP_HAS_EXPERIMENTAL_TZDB # include <__chrono/duration.h> # include <__chrono/system_clock.h> @@ -46,6 +46,6 @@ struct sys_info { _LIBCPP_END_NAMESPACE_STD -#endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) +#endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB #endif // _LIBCPP___CHRONO_SYS_INFO_H diff --git a/system/lib/libcxx/include/__chrono/time_point.h b/system/lib/libcxx/include/__chrono/time_point.h index aaf0b098f280e..5e79fa5d257fa 100644 --- a/system/lib/libcxx/include/__chrono/time_point.h +++ b/system/lib/libcxx/include/__chrono/time_point.h @@ -32,8 +32,7 @@ namespace chrono { template class _LIBCPP_TEMPLATE_VIS time_point { - static_assert(__is_duration<_Duration>::value, - "Second template parameter of time_point must be a std::chrono::duration"); + static_assert(__is_duration_v<_Duration>, "Second template parameter of time_point must be a std::chrono::duration"); public: typedef _Clock clock; @@ -91,17 +90,17 @@ time_point_cast(const time_point<_Clock, _Duration>& __t) { } #if _LIBCPP_STD_VER >= 17 -template ::value, int> = 0> +template , int> = 0> inline _LIBCPP_HIDE_FROM_ABI constexpr time_point<_Clock, _ToDuration> floor(const time_point<_Clock, _Duration>& __t) { return time_point<_Clock, _ToDuration>{chrono::floor<_ToDuration>(__t.time_since_epoch())}; } -template ::value, int> = 0> +template , int> = 0> inline _LIBCPP_HIDE_FROM_ABI constexpr time_point<_Clock, _ToDuration> ceil(const time_point<_Clock, _Duration>& __t) { return time_point<_Clock, _ToDuration>{chrono::ceil<_ToDuration>(__t.time_since_epoch())}; } -template ::value, int> = 0> +template , int> = 0> inline _LIBCPP_HIDE_FROM_ABI constexpr time_point<_Clock, _ToDuration> round(const time_point<_Clock, _Duration>& __t) { return time_point<_Clock, _ToDuration>{chrono::round<_ToDuration>(__t.time_since_epoch())}; } diff --git a/system/lib/libcxx/include/__chrono/time_zone.h b/system/lib/libcxx/include/__chrono/time_zone.h index de11dac1eef0c..d18d59d2736bf 100644 --- a/system/lib/libcxx/include/__chrono/time_zone.h +++ b/system/lib/libcxx/include/__chrono/time_zone.h @@ -14,7 +14,7 @@ #include // Enable the contents of the header only when libc++ was built with experimental features enabled. -#if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) +#if _LIBCPP_HAS_EXPERIMENTAL_TZDB # include <__chrono/calendar.h> # include <__chrono/duration.h> @@ -37,8 +37,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD -# if _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \ - !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# if _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION namespace chrono { @@ -104,10 +103,14 @@ class _LIBCPP_AVAILABILITY_TZDB time_zone { to_sys(const local_time<_Duration>& __time, choose __z) const { local_info __info = get_info(__time); switch (__info.result) { - case local_info::unique: - case local_info::nonexistent: // first and second are the same + case local_info::unique: // first and second are the same return sys_time>{__time.time_since_epoch() - __info.first.offset}; + case local_info::nonexistent: + // first and second are the same + // All non-existing values are converted to the same time. + return sys_time>{__info.first.end}; + case local_info::ambiguous: switch (__z) { case choose::earliest: @@ -170,13 +173,13 @@ operator<=>(const time_zone& __x, const time_zone& __y) noexcept { } // namespace chrono -# endif // _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) - // && !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# endif // _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && + // _LIBCPP_HAS_LOCALIZATION _LIBCPP_END_NAMESPACE_STD _LIBCPP_POP_MACROS -#endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) +#endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB #endif // _LIBCPP___CHRONO_TIME_ZONE_H diff --git a/system/lib/libcxx/include/__chrono/time_zone_link.h b/system/lib/libcxx/include/__chrono/time_zone_link.h index b2d365c5fd082..cae40b07c2ca6 100644 --- a/system/lib/libcxx/include/__chrono/time_zone_link.h +++ b/system/lib/libcxx/include/__chrono/time_zone_link.h @@ -14,7 +14,7 @@ #include // Enable the contents of the header only when libc++ was built with experimental features enabled. -#if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) +#if _LIBCPP_HAS_EXPERIMENTAL_TZDB # include <__compare/strong_order.h> # include <__config> @@ -31,8 +31,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD -# if _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \ - !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# if _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION namespace chrono { @@ -68,12 +67,13 @@ operator<=>(const time_zone_link& __x, const time_zone_link& __y) noexcept { } // namespace chrono -# endif //_LIBCPP_STD_VER >= 20 +# endif // _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && + // _LIBCPP_HAS_LOCALIZATION _LIBCPP_END_NAMESPACE_STD _LIBCPP_POP_MACROS -#endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) +#endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB #endif // _LIBCPP___CHRONO_TIME_ZONE_LINK_H diff --git a/system/lib/libcxx/include/__chrono/tzdb.h b/system/lib/libcxx/include/__chrono/tzdb.h index f731f8c318be0..fb85f66b01968 100644 --- a/system/lib/libcxx/include/__chrono/tzdb.h +++ b/system/lib/libcxx/include/__chrono/tzdb.h @@ -14,15 +14,18 @@ #include // Enable the contents of the header only when libc++ was built with experimental features enabled. -#if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) +#if _LIBCPP_HAS_EXPERIMENTAL_TZDB # include <__algorithm/ranges_lower_bound.h> # include <__chrono/leap_second.h> # include <__chrono/time_zone.h> # include <__chrono/time_zone_link.h> # include <__config> +# include <__memory/addressof.h> +# include <__vector/vector.h> +# include # include -# include +# include # if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -33,8 +36,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD -# if _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \ - !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# if _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION namespace chrono { @@ -82,13 +84,13 @@ struct tzdb { } // namespace chrono -# endif // _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) - // && !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# endif // _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && + // _LIBCPP_HAS_LOCALIZATION _LIBCPP_END_NAMESPACE_STD _LIBCPP_POP_MACROS -#endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) +#endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB #endif // _LIBCPP___CHRONO_TZDB_H diff --git a/system/lib/libcxx/include/__chrono/tzdb_list.h b/system/lib/libcxx/include/__chrono/tzdb_list.h index aeef4fe1aba3c..2b83a6df1daf8 100644 --- a/system/lib/libcxx/include/__chrono/tzdb_list.h +++ b/system/lib/libcxx/include/__chrono/tzdb_list.h @@ -14,13 +14,14 @@ #include // Enable the contents of the header only when libc++ was built with experimental features enabled. -#if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) +#if _LIBCPP_HAS_EXPERIMENTAL_TZDB # include <__chrono/time_zone.h> # include <__chrono/tzdb.h> # include <__config> # include <__fwd/string.h> # include +# include # if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -28,8 +29,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD -# if _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \ - !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# if _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION namespace chrono { @@ -98,11 +98,11 @@ _LIBCPP_AVAILABILITY_TZDB _LIBCPP_EXPORTED_FROM_ABI const tzdb& reload_tzdb(); } // namespace chrono -# endif // _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) - // && !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# endif // _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && + // _LIBCPP_HAS_LOCALIZATION _LIBCPP_END_NAMESPACE_STD -#endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) +#endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB #endif // _LIBCPP___CHRONO_TZDB_LIST_H diff --git a/system/lib/libcxx/include/__chrono/utc_clock.h b/system/lib/libcxx/include/__chrono/utc_clock.h new file mode 100644 index 0000000000000..2207b89c92c59 --- /dev/null +++ b/system/lib/libcxx/include/__chrono/utc_clock.h @@ -0,0 +1,163 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___CHRONO_UTC_CLOCK_H +#define _LIBCPP___CHRONO_UTC_CLOCK_H + +#include +// Enable the contents of the header only when libc++ was built with experimental features enabled. +#if _LIBCPP_HAS_EXPERIMENTAL_TZDB + +# include <__chrono/duration.h> +# include <__chrono/leap_second.h> +# include <__chrono/system_clock.h> +# include <__chrono/time_point.h> +# include <__chrono/tzdb.h> +# include <__chrono/tzdb_list.h> +# include <__config> +# include <__type_traits/common_type.h> + +# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +# endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +# if _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION + +namespace chrono { + +class utc_clock; + +template +using utc_time = time_point; +using utc_seconds = utc_time; + +class utc_clock { +public: + using rep = system_clock::rep; + using period = system_clock::period; + using duration = chrono::duration; + using time_point = chrono::time_point; + static constexpr bool is_steady = false; // The system_clock is not steady. + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static time_point now() { return from_sys(system_clock::now()); } + + template + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static sys_time> + to_sys(const utc_time<_Duration>& __time); + + template + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static utc_time> + from_sys(const sys_time<_Duration>& __time) { + using _Rp = utc_time>; + // TODO TZDB investigate optimizations. + // + // The leap second database stores all transitions, this mean to calculate + // the current number of leap seconds the code needs to iterate over all + // leap seconds to accumulate the sum. Then the sum can be used to determine + // the sys_time. Accessing the database involves acquiring a mutex. + // + // The historic entries in the database are immutable. Hard-coding these + // values in a table would allow: + // - To store the sum, allowing a binary search on the data. + // - Avoid acquiring a mutex. + // The disadvantage are: + // - A slightly larger code size. + // + // There are two optimization directions + // - hard-code the database and do a linear search for future entries. This + // search can start at the back, and should probably contain very few + // entries. (Adding leap seconds is quite rare and new release of libc++ + // can add the new entries; they are announced half a year before they are + // added.) + // - During parsing the leap seconds store an additional database in the + // dylib with the list of the sum of the leap seconds. In that case there + // can be a private function __get_utc_to_sys_table that returns the + // table. + // + // Note for to_sys there are no optimizations to be done; it uses + // get_leap_second_info. The function get_leap_second_info could benefit + // from optimizations as described above; again both options apply. + + // Both UTC and the system clock use the same epoch. The Standard + // specifies from 1970-01-01 even when UTC starts at + // 1972-01-01 00:00:10 TAI. So when the sys_time is before epoch we can be + // sure there both clocks return the same value. + + const tzdb& __tzdb = chrono::get_tzdb(); + _Rp __result{__time.time_since_epoch()}; + for (const auto& __leap_second : __tzdb.leap_seconds) { + if (__leap_second > __time) + return __result; + + __result += __leap_second.value(); + } + return __result; + } +}; + +struct leap_second_info { + bool is_leap_second; + seconds elapsed; +}; + +template +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI leap_second_info get_leap_second_info(const utc_time<_Duration>& __time) { + const tzdb& __tzdb = chrono::get_tzdb(); + if (__tzdb.leap_seconds.empty()) [[unlikely]] + return {false, chrono::seconds{0}}; + + sys_seconds __sys{chrono::floor(__time).time_since_epoch()}; + seconds __elapsed{0}; + for (const auto& __leap_second : __tzdb.leap_seconds) { + if (__sys == __leap_second.date() + __elapsed) + // A time point may only be a leap second during a positive leap second + // insertion, since time points that occur during a (theoretical) + // negative leap second don't exist. + return {__leap_second.value() > 0s, __elapsed + __leap_second.value()}; + + if (__sys < __leap_second.date() + __elapsed) + return {false, __elapsed}; + + __elapsed += __leap_second.value(); + } + + return {false, __elapsed}; +} + +template +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI sys_time> +utc_clock::to_sys(const utc_time<_Duration>& __time) { + using _Dp = common_type_t<_Duration, seconds>; + leap_second_info __info = chrono::get_leap_second_info(__time); + + // [time.clock.utc.members]/2 + // Returns: A sys_time t, such that from_sys(t) == u if such a mapping + // exists. Otherwise u represents a time_point during a positive leap + // second insertion, the conversion counts that leap second as not + // inserted, and the last representable value of sys_time prior to the + // insertion of the leap second is returned. + sys_time> __result{__time.time_since_epoch() - __info.elapsed}; + if (__info.is_leap_second) + return chrono::floor(__result) + chrono::seconds{1} - _Dp{1}; + + return __result; +} + +} // namespace chrono + +# endif // _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && + // _LIBCPP_HAS_LOCALIZATION + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB + +#endif // _LIBCPP___CHRONO_UTC_CLOCK_H diff --git a/system/lib/libcxx/include/__chrono/weekday.h b/system/lib/libcxx/include/__chrono/weekday.h index 86c780cc71825..728cbb844633f 100644 --- a/system/lib/libcxx/include/__chrono/weekday.h +++ b/system/lib/libcxx/include/__chrono/weekday.h @@ -79,25 +79,6 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr bool operator==(const weekday& __lhs, con return __lhs.c_encoding() == __rhs.c_encoding(); } -// TODO(LLVM 20): Remove the escape hatch -# ifdef _LIBCPP_ENABLE_REMOVED_WEEKDAY_RELATIONAL_OPERATORS -_LIBCPP_HIDE_FROM_ABI inline constexpr bool operator<(const weekday& __lhs, const weekday& __rhs) noexcept { - return __lhs.c_encoding() < __rhs.c_encoding(); -} - -_LIBCPP_HIDE_FROM_ABI inline constexpr bool operator>(const weekday& __lhs, const weekday& __rhs) noexcept { - return __rhs < __lhs; -} - -_LIBCPP_HIDE_FROM_ABI inline constexpr bool operator<=(const weekday& __lhs, const weekday& __rhs) noexcept { - return !(__rhs < __lhs); -} - -_LIBCPP_HIDE_FROM_ABI inline constexpr bool operator>=(const weekday& __lhs, const weekday& __rhs) noexcept { - return !(__lhs < __rhs); -} -# endif // _LIBCPP_ENABLE_REMOVED_WEEKDAY_RELATIONAL_OPERATORS - _LIBCPP_HIDE_FROM_ABI inline constexpr weekday operator+(const weekday& __lhs, const days& __rhs) noexcept { auto const __mu = static_cast(__lhs.c_encoding()) + __rhs.count(); auto const __yr = (__mu >= 0 ? __mu : __mu - 6) / 7; diff --git a/system/lib/libcxx/include/__chrono/year.h b/system/lib/libcxx/include/__chrono/year.h index 1899d09f38dbd..2ae5180cb8fc9 100644 --- a/system/lib/libcxx/include/__chrono/year.h +++ b/system/lib/libcxx/include/__chrono/year.h @@ -11,8 +11,8 @@ #define _LIBCPP___CHRONO_YEAR_H #include <__chrono/duration.h> +#include <__compare/ordering.h> #include <__config> -#include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) diff --git a/system/lib/libcxx/include/__chrono/year_month.h b/system/lib/libcxx/include/__chrono/year_month.h index 369ea38f7560d..cf9234bdb4625 100644 --- a/system/lib/libcxx/include/__chrono/year_month.h +++ b/system/lib/libcxx/include/__chrono/year_month.h @@ -13,8 +13,8 @@ #include <__chrono/duration.h> #include <__chrono/month.h> #include <__chrono/year.h> +#include <__compare/ordering.h> #include <__config> -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/system/lib/libcxx/include/__chrono/year_month_day.h b/system/lib/libcxx/include/__chrono/year_month_day.h index b06c0be03e0de..a0510a14f4ede 100644 --- a/system/lib/libcxx/include/__chrono/year_month_day.h +++ b/system/lib/libcxx/include/__chrono/year_month_day.h @@ -19,8 +19,8 @@ #include <__chrono/time_point.h> #include <__chrono/year.h> #include <__chrono/year_month.h> +#include <__compare/ordering.h> #include <__config> -#include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) diff --git a/system/lib/libcxx/include/__chrono/zoned_time.h b/system/lib/libcxx/include/__chrono/zoned_time.h index 8cfa2122642c5..8db687a422ab1 100644 --- a/system/lib/libcxx/include/__chrono/zoned_time.h +++ b/system/lib/libcxx/include/__chrono/zoned_time.h @@ -14,7 +14,7 @@ #include // Enable the contents of the header only when libc++ was built with experimental features enabled. -#if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) +#if _LIBCPP_HAS_EXPERIMENTAL_TZDB # include <__chrono/calendar.h> # include <__chrono/duration.h> @@ -22,12 +22,14 @@ # include <__chrono/system_clock.h> # include <__chrono/time_zone.h> # include <__chrono/tzdb_list.h> +# include <__concepts/constructible.h> # include <__config> -# include <__fwd/string_view.h> # include <__type_traits/common_type.h> # include <__type_traits/conditional.h> # include <__type_traits/remove_cvref.h> +# include <__utility/declval.h> # include <__utility/move.h> +# include # if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -38,8 +40,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD -# if _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \ - !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# if _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION namespace chrono { @@ -57,7 +58,7 @@ struct zoned_traits { template class zoned_time { // [time.zone.zonedtime.ctor]/2 - static_assert(__is_duration<_Duration>::value, + static_assert(__is_duration_v<_Duration>, "the program is ill-formed since _Duration is not a specialization of std::chrono::duration"); // The wording uses the constraints like @@ -65,7 +66,7 @@ class zoned_time { // Using these constraints in the code causes the compiler to give an // error that the constraint depends on itself. To avoid that issue use // the fact it is possible to create this object from a _TimeZonePtr. - using __traits = zoned_traits<_TimeZonePtr>; + using __traits _LIBCPP_NODEBUG = zoned_traits<_TimeZonePtr>; public: using duration = common_type_t<_Duration, seconds>; @@ -185,7 +186,7 @@ template zoned_time(sys_time<_Duration>) -> zoned_time>; template -using __time_zone_representation = +using __time_zone_representation _LIBCPP_NODEBUG = conditional_t, const time_zone*, remove_cvref_t<_TimeZonePtrOrName>>; @@ -201,8 +202,8 @@ template zoned_time(_TimeZonePtrOrName&&, local_time<_Duration>, choose = choose::earliest) -> zoned_time, __time_zone_representation<_TimeZonePtrOrName>>; -template -zoned_time(_TimeZonePtrOrName&&, zoned_time<_Duration, TimeZonePtr2>, choose = choose::earliest) +template +zoned_time(_TimeZonePtrOrName&&, zoned_time<_Duration, _TimeZonePtr2>, choose = choose::earliest) -> zoned_time, __time_zone_representation<_TimeZonePtrOrName>>; using zoned_seconds = zoned_time; @@ -215,13 +216,13 @@ operator==(const zoned_time<_Duration1, _TimeZonePtr>& __lhs, const zoned_time<_ } // namespace chrono -# endif // _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) - // && !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# endif // _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && + // _LIBCPP_HAS_LOCALIZATION _LIBCPP_END_NAMESPACE_STD _LIBCPP_POP_MACROS -#endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) +#endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB #endif // _LIBCPP___CHRONO_ZONED_TIME_H diff --git a/system/lib/libcxx/include/__compare/common_comparison_category.h b/system/lib/libcxx/include/__compare/common_comparison_category.h index 7aeb3da03a4f4..215922abad6b0 100644 --- a/system/lib/libcxx/include/__compare/common_comparison_category.h +++ b/system/lib/libcxx/include/__compare/common_comparison_category.h @@ -11,8 +11,8 @@ #include <__compare/ordering.h> #include <__config> +#include <__cstddef/size_t.h> #include <__type_traits/is_same.h> -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/system/lib/libcxx/include/__compare/compare_partial_order_fallback.h b/system/lib/libcxx/include/__compare/compare_partial_order_fallback.h index e0efa3ccb88db..80f2aca661faa 100644 --- a/system/lib/libcxx/include/__compare/compare_partial_order_fallback.h +++ b/system/lib/libcxx/include/__compare/compare_partial_order_fallback.h @@ -11,6 +11,7 @@ #include <__compare/ordering.h> #include <__compare/partial_order.h> +#include <__concepts/boolean_testable.h> #include <__config> #include <__type_traits/decay.h> #include <__type_traits/is_same.h> @@ -37,18 +38,16 @@ struct __fn { } template - requires is_same_v, decay_t<_Up>> - _LIBCPP_HIDE_FROM_ABI static constexpr auto __go(_Tp&& __t, _Up&& __u, __priority_tag<0>) noexcept(noexcept( - std::forward<_Tp>(__t) == std::forward<_Up>(__u) ? partial_ordering::equivalent - : std::forward<_Tp>(__t) < std::forward<_Up>(__u) ? partial_ordering::less - : std::forward<_Up>(__u) < std::forward<_Tp>(__t) - ? partial_ordering::greater - : partial_ordering::unordered)) - -> decltype(std::forward<_Tp>(__t) == std::forward<_Up>(__u) ? partial_ordering::equivalent - : std::forward<_Tp>(__t) < std::forward<_Up>(__u) ? partial_ordering::less - : std::forward<_Up>(__u) < std::forward<_Tp>(__t) - ? partial_ordering::greater - : partial_ordering::unordered) { + requires is_same_v, decay_t<_Up>> && requires(_Tp&& __t, _Up&& __u) { + { std::forward<_Tp>(__t) == std::forward<_Up>(__u) } -> __boolean_testable; + { std::forward<_Tp>(__t) < std::forward<_Up>(__u) } -> __boolean_testable; + { std::forward<_Up>(__u) < std::forward<_Tp>(__t) } -> __boolean_testable; + } + _LIBCPP_HIDE_FROM_ABI static constexpr partial_ordering __go(_Tp&& __t, _Up&& __u, __priority_tag<0>) noexcept( + noexcept(std::forward<_Tp>(__t) == std::forward<_Up>(__u) ? partial_ordering::equivalent + : std::forward<_Tp>(__t) < std::forward<_Up>(__u) ? partial_ordering::less + : std::forward<_Up>(__u) < std::forward<_Tp>(__t) ? partial_ordering::greater + : partial_ordering::unordered)) { return std::forward<_Tp>(__t) == std::forward<_Up>(__u) ? partial_ordering::equivalent : std::forward<_Tp>(__t) < std::forward<_Up>(__u) ? partial_ordering::less : std::forward<_Up>(__u) < std::forward<_Tp>(__t) diff --git a/system/lib/libcxx/include/__compare/compare_strong_order_fallback.h b/system/lib/libcxx/include/__compare/compare_strong_order_fallback.h index a94d517ed30fc..c41a90c5afa82 100644 --- a/system/lib/libcxx/include/__compare/compare_strong_order_fallback.h +++ b/system/lib/libcxx/include/__compare/compare_strong_order_fallback.h @@ -11,6 +11,7 @@ #include <__compare/ordering.h> #include <__compare/strong_order.h> +#include <__concepts/boolean_testable.h> #include <__config> #include <__type_traits/decay.h> #include <__type_traits/is_same.h> @@ -37,16 +38,14 @@ struct __fn { } template - requires is_same_v, decay_t<_Up>> - _LIBCPP_HIDE_FROM_ABI static constexpr auto __go(_Tp&& __t, _Up&& __u, __priority_tag<0>) noexcept(noexcept( - std::forward<_Tp>(__t) == std::forward<_Up>(__u) ? strong_ordering::equal - : std::forward<_Tp>(__t) < std::forward<_Up>(__u) - ? strong_ordering::less - : strong_ordering::greater)) - -> decltype(std::forward<_Tp>(__t) == std::forward<_Up>(__u) ? strong_ordering::equal - : std::forward<_Tp>(__t) < std::forward<_Up>(__u) - ? strong_ordering::less - : strong_ordering::greater) { + requires is_same_v, decay_t<_Up>> && requires(_Tp&& __t, _Up&& __u) { + { std::forward<_Tp>(__t) == std::forward<_Up>(__u) } -> __boolean_testable; + { std::forward<_Tp>(__t) < std::forward<_Up>(__u) } -> __boolean_testable; + } + _LIBCPP_HIDE_FROM_ABI static constexpr strong_ordering __go(_Tp&& __t, _Up&& __u, __priority_tag<0>) noexcept( + noexcept(std::forward<_Tp>(__t) == std::forward<_Up>(__u) ? strong_ordering::equal + : std::forward<_Tp>(__t) < std::forward<_Up>(__u) ? strong_ordering::less + : strong_ordering::greater)) { return std::forward<_Tp>(__t) == std::forward<_Up>(__u) ? strong_ordering::equal : std::forward<_Tp>(__t) < std::forward<_Up>(__u) ? strong_ordering::less diff --git a/system/lib/libcxx/include/__compare/compare_three_way_result.h b/system/lib/libcxx/include/__compare/compare_three_way_result.h index d7508073433af..6ee2eff00302d 100644 --- a/system/lib/libcxx/include/__compare/compare_three_way_result.h +++ b/system/lib/libcxx/include/__compare/compare_three_way_result.h @@ -33,7 +33,8 @@ struct _LIBCPP_HIDE_FROM_ABI __compare_three_way_result< }; template -struct _LIBCPP_TEMPLATE_VIS compare_three_way_result : __compare_three_way_result<_Tp, _Up, void> {}; +struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS compare_three_way_result + : __compare_three_way_result<_Tp, _Up, void> {}; template using compare_three_way_result_t = typename compare_three_way_result<_Tp, _Up>::type; diff --git a/system/lib/libcxx/include/__compare/compare_weak_order_fallback.h b/system/lib/libcxx/include/__compare/compare_weak_order_fallback.h index 062b7b582cd7e..26689fbd9f445 100644 --- a/system/lib/libcxx/include/__compare/compare_weak_order_fallback.h +++ b/system/lib/libcxx/include/__compare/compare_weak_order_fallback.h @@ -11,6 +11,7 @@ #include <__compare/ordering.h> #include <__compare/weak_order.h> +#include <__concepts/boolean_testable.h> #include <__config> #include <__type_traits/decay.h> #include <__type_traits/is_same.h> @@ -37,16 +38,15 @@ struct __fn { } template - requires is_same_v, decay_t<_Up>> - _LIBCPP_HIDE_FROM_ABI static constexpr auto __go(_Tp&& __t, _Up&& __u, __priority_tag<0>) noexcept(noexcept( + requires is_same_v, decay_t<_Up>> && requires(_Tp&& __t, _Up&& __u) { + { std::forward<_Tp>(__t) == std::forward<_Up>(__u) } -> __boolean_testable; + { std::forward<_Tp>(__t) < std::forward<_Up>(__u) } -> __boolean_testable; + } + _LIBCPP_HIDE_FROM_ABI static constexpr weak_ordering __go(_Tp&& __t, _Up&& __u, __priority_tag<0>) noexcept(noexcept( std::forward<_Tp>(__t) == std::forward<_Up>(__u) ? weak_ordering::equivalent : std::forward<_Tp>(__t) < std::forward<_Up>(__u) ? weak_ordering::less - : weak_ordering::greater)) - -> decltype(std::forward<_Tp>(__t) == std::forward<_Up>(__u) ? weak_ordering::equivalent - : std::forward<_Tp>(__t) < std::forward<_Up>(__u) - ? weak_ordering::less - : weak_ordering::greater) { + : weak_ordering::greater)) { return std::forward<_Tp>(__t) == std::forward<_Up>(__u) ? weak_ordering::equivalent : std::forward<_Tp>(__t) < std::forward<_Up>(__u) ? weak_ordering::less diff --git a/system/lib/libcxx/include/__compare/ordering.h b/system/lib/libcxx/include/__compare/ordering.h index 2995d381304f0..902ef5329dd43 100644 --- a/system/lib/libcxx/include/__compare/ordering.h +++ b/system/lib/libcxx/include/__compare/ordering.h @@ -24,32 +24,35 @@ _LIBCPP_BEGIN_NAMESPACE_STD // exposition only enum class _OrdResult : signed char { __less = -1, __equiv = 0, __greater = 1 }; -enum class _NCmpResult : signed char { __unordered = -127 }; +enum class _PartialOrdResult : signed char { + __less = static_cast(_OrdResult::__less), + __equiv = static_cast(_OrdResult::__equiv), + __greater = static_cast(_OrdResult::__greater), + __unordered = -127, +}; class partial_ordering; class weak_ordering; class strong_ordering; -template -inline constexpr bool __one_of_v = (is_same_v<_Tp, _Args> || ...); - struct _CmpUnspecifiedParam { - _LIBCPP_HIDE_FROM_ABI constexpr _CmpUnspecifiedParam(int _CmpUnspecifiedParam::*) noexcept {} - - template >> - _CmpUnspecifiedParam(_Tp) = delete; + // If anything other than a literal 0 is provided, the behavior is undefined by the Standard. + // + // The alternative to the `__enable_if__` attribute would be to use the fact that a pointer + // can be constructed from literal 0, but this conflicts with `-Wzero-as-null-pointer-constant`. + template > > + _LIBCPP_HIDE_FROM_ABI consteval _CmpUnspecifiedParam(_Tp __zero) noexcept +# if __has_attribute(__enable_if__) + __attribute__((__enable_if__( + __zero == 0, "Only literal 0 is allowed as the operand of a comparison with one of the ordering types"))) +# endif + { + (void)__zero; + } }; class partial_ordering { - using _ValueT = signed char; - - _LIBCPP_HIDE_FROM_ABI explicit constexpr partial_ordering(_OrdResult __v) noexcept : __value_(_ValueT(__v)) {} - - _LIBCPP_HIDE_FROM_ABI explicit constexpr partial_ordering(_NCmpResult __v) noexcept : __value_(_ValueT(__v)) {} - - _LIBCPP_HIDE_FROM_ABI constexpr bool __is_ordered() const noexcept { - return __value_ != _ValueT(_NCmpResult::__unordered); - } + _LIBCPP_HIDE_FROM_ABI explicit constexpr partial_ordering(_PartialOrdResult __v) noexcept : __value_(__v) {} public: // valid values @@ -62,39 +65,39 @@ class partial_ordering { _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(partial_ordering, partial_ordering) noexcept = default; _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(partial_ordering __v, _CmpUnspecifiedParam) noexcept { - return __v.__is_ordered() && __v.__value_ == 0; + return __v.__value_ == _PartialOrdResult::__equiv; } _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<(partial_ordering __v, _CmpUnspecifiedParam) noexcept { - return __v.__is_ordered() && __v.__value_ < 0; + return __v.__value_ == _PartialOrdResult::__less; } _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<=(partial_ordering __v, _CmpUnspecifiedParam) noexcept { - return __v.__is_ordered() && __v.__value_ <= 0; + return __v.__value_ == _PartialOrdResult::__equiv || __v.__value_ == _PartialOrdResult::__less; } _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>(partial_ordering __v, _CmpUnspecifiedParam) noexcept { - return __v.__is_ordered() && __v.__value_ > 0; + return __v.__value_ == _PartialOrdResult::__greater; } _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>=(partial_ordering __v, _CmpUnspecifiedParam) noexcept { - return __v.__is_ordered() && __v.__value_ >= 0; + return __v.__value_ == _PartialOrdResult::__equiv || __v.__value_ == _PartialOrdResult::__greater; } _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<(_CmpUnspecifiedParam, partial_ordering __v) noexcept { - return __v.__is_ordered() && 0 < __v.__value_; + return __v.__value_ == _PartialOrdResult::__greater; } _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<=(_CmpUnspecifiedParam, partial_ordering __v) noexcept { - return __v.__is_ordered() && 0 <= __v.__value_; + return __v.__value_ == _PartialOrdResult::__equiv || __v.__value_ == _PartialOrdResult::__greater; } _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>(_CmpUnspecifiedParam, partial_ordering __v) noexcept { - return __v.__is_ordered() && 0 > __v.__value_; + return __v.__value_ == _PartialOrdResult::__less; } _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>=(_CmpUnspecifiedParam, partial_ordering __v) noexcept { - return __v.__is_ordered() && 0 >= __v.__value_; + return __v.__value_ == _PartialOrdResult::__equiv || __v.__value_ == _PartialOrdResult::__less; } _LIBCPP_HIDE_FROM_ABI friend constexpr partial_ordering @@ -108,16 +111,16 @@ class partial_ordering { } private: - _ValueT __value_; + _PartialOrdResult __value_; }; -inline constexpr partial_ordering partial_ordering::less(_OrdResult::__less); -inline constexpr partial_ordering partial_ordering::equivalent(_OrdResult::__equiv); -inline constexpr partial_ordering partial_ordering::greater(_OrdResult::__greater); -inline constexpr partial_ordering partial_ordering::unordered(_NCmpResult ::__unordered); +inline constexpr partial_ordering partial_ordering::less(_PartialOrdResult::__less); +inline constexpr partial_ordering partial_ordering::equivalent(_PartialOrdResult::__equiv); +inline constexpr partial_ordering partial_ordering::greater(_PartialOrdResult::__greater); +inline constexpr partial_ordering partial_ordering::unordered(_PartialOrdResult::__unordered); class weak_ordering { - using _ValueT = signed char; + using _ValueT _LIBCPP_NODEBUG = signed char; _LIBCPP_HIDE_FROM_ABI explicit constexpr weak_ordering(_OrdResult __v) noexcept : __value_(_ValueT(__v)) {} @@ -187,7 +190,7 @@ inline constexpr weak_ordering weak_ordering::equivalent(_OrdResult::__equiv); inline constexpr weak_ordering weak_ordering::greater(_OrdResult::__greater); class strong_ordering { - using _ValueT = signed char; + using _ValueT _LIBCPP_NODEBUG = signed char; _LIBCPP_HIDE_FROM_ABI explicit constexpr strong_ordering(_OrdResult __v) noexcept : __value_(_ValueT(__v)) {} @@ -269,7 +272,8 @@ inline constexpr strong_ordering strong_ordering::greater(_OrdResult::__greater) /// The types partial_ordering, weak_ordering, and strong_ordering are /// collectively termed the comparison category types. template -concept __comparison_category = __one_of_v<_Tp, partial_ordering, weak_ordering, strong_ordering>; +concept __comparison_category = + is_same_v<_Tp, partial_ordering> || is_same_v<_Tp, weak_ordering> || is_same_v<_Tp, strong_ordering>; #endif // _LIBCPP_STD_VER >= 20 diff --git a/system/lib/libcxx/include/__compare/synth_three_way.h b/system/lib/libcxx/include/__compare/synth_three_way.h index e48ce49799836..63bf56d0cf42b 100644 --- a/system/lib/libcxx/include/__compare/synth_three_way.h +++ b/system/lib/libcxx/include/__compare/synth_three_way.h @@ -43,7 +43,8 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr auto __synth_three_way = [] -using __synth_three_way_result = decltype(std::__synth_three_way(std::declval<_Tp&>(), std::declval<_Up&>())); +using __synth_three_way_result _LIBCPP_NODEBUG = + decltype(std::__synth_three_way(std::declval<_Tp&>(), std::declval<_Up&>())); #endif // _LIBCPP_STD_VER >= 20 diff --git a/system/lib/libcxx/include/__concepts/predicate.h b/system/lib/libcxx/include/__concepts/predicate.h index 00731efc8fcd9..e0263a878b065 100644 --- a/system/lib/libcxx/include/__concepts/predicate.h +++ b/system/lib/libcxx/include/__concepts/predicate.h @@ -12,7 +12,7 @@ #include <__concepts/boolean_testable.h> #include <__concepts/invocable.h> #include <__config> -#include <__functional/invoke.h> +#include <__type_traits/invoke.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/system/lib/libcxx/include/__concepts/swappable.h b/system/lib/libcxx/include/__concepts/swappable.h index d339488a087a5..985c733021a0d 100644 --- a/system/lib/libcxx/include/__concepts/swappable.h +++ b/system/lib/libcxx/include/__concepts/swappable.h @@ -14,6 +14,7 @@ #include <__concepts/common_reference_with.h> #include <__concepts/constructible.h> #include <__config> +#include <__cstddef/size_t.h> #include <__type_traits/extent.h> #include <__type_traits/is_nothrow_assignable.h> #include <__type_traits/is_nothrow_constructible.h> @@ -22,7 +23,6 @@ #include <__utility/forward.h> #include <__utility/move.h> #include <__utility/swap.h> -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/system/lib/libcxx/include/__condition_variable/condition_variable.h b/system/lib/libcxx/include/__condition_variable/condition_variable.h index de35aaca1070e..4521fe274614e 100644 --- a/system/lib/libcxx/include/__condition_variable/condition_variable.h +++ b/system/lib/libcxx/include/__condition_variable/condition_variable.h @@ -16,7 +16,7 @@ #include <__config> #include <__mutex/mutex.h> #include <__mutex/unique_lock.h> -#include <__system_error/system_error.h> +#include <__system_error/throw_system_error.h> #include <__thread/support.h> #include <__type_traits/enable_if.h> #include <__type_traits/is_floating_point.h> @@ -33,7 +33,7 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD -#ifndef _LIBCPP_HAS_NO_THREADS +#if _LIBCPP_HAS_THREADS // enum class cv_status _LIBCPP_DECLARE_STRONG_ENUM(cv_status){no_timeout, timeout}; @@ -45,7 +45,7 @@ class _LIBCPP_EXPORTED_FROM_ABI condition_variable { public: _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR condition_variable() _NOEXCEPT = default; -# ifdef _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION +# if _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION ~condition_variable() = default; # else ~condition_variable(); @@ -83,7 +83,7 @@ class _LIBCPP_EXPORTED_FROM_ABI condition_variable { private: void __do_timed_wait(unique_lock& __lk, chrono::time_point) _NOEXCEPT; -# if defined(_LIBCPP_HAS_COND_CLOCKWAIT) +# if _LIBCPP_HAS_COND_CLOCKWAIT _LIBCPP_HIDE_FROM_ABI void __do_timed_wait(unique_lock& __lk, chrono::time_point) _NOEXCEPT; # endif @@ -91,7 +91,7 @@ class _LIBCPP_EXPORTED_FROM_ABI condition_variable { _LIBCPP_HIDE_FROM_ABI void __do_timed_wait(unique_lock& __lk, chrono::time_point<_Clock, chrono::nanoseconds>) _NOEXCEPT; }; -#endif // !_LIBCPP_HAS_NO_THREADS +#endif // _LIBCPP_HAS_THREADS template ::value, int> = 0> inline _LIBCPP_HIDE_FROM_ABI chrono::nanoseconds __safe_nanosecond_cast(chrono::duration<_Rep, _Period> __d) { @@ -140,7 +140,7 @@ inline _LIBCPP_HIDE_FROM_ABI chrono::nanoseconds __safe_nanosecond_cast(chrono:: return nanoseconds(__result); } -#ifndef _LIBCPP_HAS_NO_THREADS +#if _LIBCPP_HAS_THREADS template void condition_variable::wait(unique_lock& __lk, _Predicate __pred) { while (!__pred()) @@ -180,7 +180,7 @@ cv_status condition_variable::wait_for(unique_lock& __lk, const chrono::d using __ns_rep = nanoseconds::rep; steady_clock::time_point __c_now = steady_clock::now(); -# if defined(_LIBCPP_HAS_COND_CLOCKWAIT) +# if _LIBCPP_HAS_COND_CLOCKWAIT using __clock_tp_ns = time_point; __ns_rep __now_count_ns = std::__safe_nanosecond_cast(__c_now.time_since_epoch()).count(); # else @@ -205,7 +205,7 @@ condition_variable::wait_for(unique_lock& __lk, const chrono::duration<_R return wait_until(__lk, chrono::steady_clock::now() + __d, std::move(__pred)); } -# if defined(_LIBCPP_HAS_COND_CLOCKWAIT) +# if _LIBCPP_HAS_COND_CLOCKWAIT inline void condition_variable::__do_timed_wait( unique_lock& __lk, chrono::time_point __tp) _NOEXCEPT { using namespace chrono; @@ -235,7 +235,7 @@ inline void condition_variable::__do_timed_wait(unique_lock& __lk, wait_for(__lk, __tp - _Clock::now()); } -#endif // _LIBCPP_HAS_NO_THREADS +#endif // _LIBCPP_HAS_THREADS _LIBCPP_END_NAMESPACE_STD diff --git a/system/lib/libcxx/include/__config b/system/lib/libcxx/include/__config index e97669bca411e..a866a7e651837 100644 --- a/system/lib/libcxx/include/__config +++ b/system/lib/libcxx/include/__config @@ -14,6 +14,7 @@ #include <__configuration/abi.h> #include <__configuration/availability.h> #include <__configuration/compiler.h> +#include <__configuration/language.h> #include <__configuration/platform.h> #ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER @@ -27,10 +28,11 @@ // _LIBCPP_VERSION represents the version of libc++, which matches the version of LLVM. // Given a LLVM release LLVM XX.YY.ZZ (e.g. LLVM 17.0.1 == 17.00.01), _LIBCPP_VERSION is // defined to XXYYZZ. -# define _LIBCPP_VERSION 190106 +# define _LIBCPP_VERSION 200100 # define _LIBCPP_CONCAT_IMPL(_X, _Y) _X##_Y # define _LIBCPP_CONCAT(_X, _Y) _LIBCPP_CONCAT_IMPL(_X, _Y) +# define _LIBCPP_CONCAT3(X, Y, Z) _LIBCPP_CONCAT(X, _LIBCPP_CONCAT(Y, Z)) # if __STDC_HOSTED__ == 0 # define _LIBCPP_FREESTANDING @@ -38,16 +40,9 @@ // HARDENING { -// This is for backward compatibility -- make enabling `_LIBCPP_ENABLE_ASSERTIONS` (which predates hardening modes) -// equivalent to setting the extensive mode. This is deprecated and will be removed in LLVM 20. +// TODO: Remove in LLVM 21. We're making this an error to catch folks who might not have migrated. # ifdef _LIBCPP_ENABLE_ASSERTIONS -# warning "_LIBCPP_ENABLE_ASSERTIONS is deprecated, please use _LIBCPP_HARDENING_MODE instead" -# if _LIBCPP_ENABLE_ASSERTIONS != 0 && _LIBCPP_ENABLE_ASSERTIONS != 1 -# error "_LIBCPP_ENABLE_ASSERTIONS must be set to 0 or 1" -# endif -# if _LIBCPP_ENABLE_ASSERTIONS -# define _LIBCPP_HARDENING_MODE _LIBCPP_HARDENING_MODE_EXTENSIVE -# endif +# error "_LIBCPP_ENABLE_ASSERTIONS has been removed, please use _LIBCPP_HARDENING_MODE instead" # endif // The library provides the macro `_LIBCPP_HARDENING_MODE` which can be set to one of the following values: @@ -191,25 +186,6 @@ _LIBCPP_HARDENING_MODE_DEBUG # error "libc++ only supports C++03 with Clang-based compilers. Please enable C++11" # endif -// FIXME: ABI detection should be done via compiler builtin macros. This -// is just a placeholder until Clang implements such macros. For now assume -// that Windows compilers pretending to be MSVC++ target the Microsoft ABI, -// and allow the user to explicitly specify the ABI to handle cases where this -// heuristic falls short. -# if defined(_LIBCPP_ABI_FORCE_ITANIUM) && defined(_LIBCPP_ABI_FORCE_MICROSOFT) -# error "Only one of _LIBCPP_ABI_FORCE_ITANIUM and _LIBCPP_ABI_FORCE_MICROSOFT can be defined" -# elif defined(_LIBCPP_ABI_FORCE_ITANIUM) -# define _LIBCPP_ABI_ITANIUM -# elif defined(_LIBCPP_ABI_FORCE_MICROSOFT) -# define _LIBCPP_ABI_MICROSOFT -# else -# if defined(_WIN32) && defined(_MSC_VER) -# define _LIBCPP_ABI_MICROSOFT -# else -# define _LIBCPP_ABI_ITANIUM -# endif -# endif - # if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME) # define _LIBCPP_ABI_VCRUNTIME # endif @@ -222,13 +198,16 @@ _LIBCPP_HARDENING_MODE_DEBUG // Incomplete features get their own specific disabling flags. This makes it // easier to grep for target specific flags once the feature is complete. -# if !defined(_LIBCPP_ENABLE_EXPERIMENTAL) && !defined(_LIBCPP_BUILDING_LIBRARY) -# define _LIBCPP_HAS_NO_INCOMPLETE_PSTL -# define _LIBCPP_HAS_NO_EXPERIMENTAL_STOP_TOKEN -# define _LIBCPP_HAS_NO_EXPERIMENTAL_TZDB -# define _LIBCPP_HAS_NO_EXPERIMENTAL_SYNCSTREAM +# if defined(_LIBCPP_ENABLE_EXPERIMENTAL) || defined(_LIBCPP_BUILDING_LIBRARY) +# define _LIBCPP_HAS_EXPERIMENTAL_LIBRARY 1 +# else +# define _LIBCPP_HAS_EXPERIMENTAL_LIBRARY 0 # endif +# define _LIBCPP_HAS_EXPERIMENTAL_PSTL _LIBCPP_HAS_EXPERIMENTAL_LIBRARY +# define _LIBCPP_HAS_EXPERIMENTAL_TZDB _LIBCPP_HAS_EXPERIMENTAL_LIBRARY +# define _LIBCPP_HAS_EXPERIMENTAL_SYNCSTREAM _LIBCPP_HAS_EXPERIMENTAL_LIBRARY + # if defined(__MVS__) # include // for __NATIVE_ASCII_F # endif @@ -244,9 +223,14 @@ _LIBCPP_HARDENING_MODE_DEBUG # define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library # endif # if (defined(_M_AMD64) || defined(__x86_64__)) || (defined(_M_ARM) || defined(__arm__)) -# define _LIBCPP_HAS_BITSCAN64 +# define _LIBCPP_HAS_BITSCAN64 1 +# else +# define _LIBCPP_HAS_BITSCAN64 0 # endif -# define _LIBCPP_HAS_OPEN_WITH_WCHAR +# define _LIBCPP_HAS_OPEN_WITH_WCHAR 1 +# else +# define _LIBCPP_HAS_OPEN_WITH_WCHAR 0 +# define _LIBCPP_HAS_BITSCAN64 0 # endif // defined(_WIN32) # if defined(_AIX) && !defined(__64BIT__) @@ -312,7 +296,6 @@ _LIBCPP_HARDENING_MODE_DEBUG # define _LIBCPP_ALIGNOF(_Tp) alignof(_Tp) # define _ALIGNAS_TYPE(x) alignas(x) # define _ALIGNAS(x) alignas(x) -# define _LIBCPP_NORETURN [[noreturn]] # define _NOEXCEPT noexcept # define _NOEXCEPT_(...) noexcept(__VA_ARGS__) # define _LIBCPP_CONSTEXPR constexpr @@ -322,8 +305,6 @@ _LIBCPP_HARDENING_MODE_DEBUG # define _LIBCPP_ALIGNOF(_Tp) _Alignof(_Tp) # define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x)))) # define _ALIGNAS(x) __attribute__((__aligned__(x))) -# define _LIBCPP_NORETURN __attribute__((__noreturn__)) -# define _LIBCPP_HAS_NO_NOEXCEPT # define nullptr __nullptr # define _NOEXCEPT throw() # define _NOEXCEPT_(...) @@ -340,23 +321,33 @@ typedef __char32_t char32_t; // Objective-C++ features (opt-in) # if __has_feature(objc_arc) -# define _LIBCPP_HAS_OBJC_ARC +# define _LIBCPP_HAS_OBJC_ARC 1 +# else +# define _LIBCPP_HAS_OBJC_ARC 0 # endif # if __has_feature(objc_arc_weak) -# define _LIBCPP_HAS_OBJC_ARC_WEAK +# define _LIBCPP_HAS_OBJC_ARC_WEAK 1 +# else +# define _LIBCPP_HAS_OBJC_ARC_WEAK 0 # endif # if __has_extension(blocks) -# define _LIBCPP_HAS_EXTENSION_BLOCKS +# define _LIBCPP_HAS_EXTENSION_BLOCKS 1 +# else +# define _LIBCPP_HAS_EXTENSION_BLOCKS 0 # endif -# if defined(_LIBCPP_HAS_EXTENSION_BLOCKS) && defined(__APPLE__) -# define _LIBCPP_HAS_BLOCKS_RUNTIME +# if _LIBCPP_HAS_EXTENSION_BLOCKS && defined(__APPLE__) +# define _LIBCPP_HAS_BLOCKS_RUNTIME 1 +# else +# define _LIBCPP_HAS_BLOCKS_RUNTIME 0 # endif -# if !__has_feature(address_sanitizer) -# define _LIBCPP_HAS_NO_ASAN +# if __has_feature(address_sanitizer) +# define _LIBCPP_HAS_ASAN 1 +# else +# define _LIBCPP_HAS_ASAN 0 # endif # define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__)) @@ -479,7 +470,7 @@ typedef __char32_t char32_t; # define _LIBCPP_HARDENING_SIG n // "none" # endif -# ifdef _LIBCPP_HAS_NO_EXCEPTIONS +# if !_LIBCPP_HAS_EXCEPTIONS # define _LIBCPP_EXCEPTIONS_SIG n # else # define _LIBCPP_EXCEPTIONS_SIG e @@ -593,6 +584,15 @@ typedef __char32_t char32_t; inline namespace _LIBCPP_ABI_NAMESPACE { # define _LIBCPP_END_NAMESPACE_STD }} _LIBCPP_POP_EXTENSION_DIAGNOSTICS +#define _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL namespace std { namespace experimental { +#define _LIBCPP_END_NAMESPACE_EXPERIMENTAL }} + +#define _LIBCPP_BEGIN_NAMESPACE_LFTS _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL inline namespace fundamentals_v1 { +#define _LIBCPP_END_NAMESPACE_LFTS } _LIBCPP_END_NAMESPACE_EXPERIMENTAL + +#define _LIBCPP_BEGIN_NAMESPACE_LFTS_V2 _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL inline namespace fundamentals_v2 { +#define _LIBCPP_END_NAMESPACE_LFTS_V2 } _LIBCPP_END_NAMESPACE_EXPERIMENTAL + #ifdef _LIBCPP_ABI_NO_FILESYSTEM_INLINE_NAMESPACE # define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_STD namespace filesystem { # define _LIBCPP_END_NAMESPACE_FILESYSTEM } _LIBCPP_END_NAMESPACE_STD @@ -610,7 +610,9 @@ typedef __char32_t char32_t; # endif # if !defined(__SIZEOF_INT128__) || defined(_MSC_VER) -# define _LIBCPP_HAS_NO_INT128 +# define _LIBCPP_HAS_INT128 0 +# else +# define _LIBCPP_HAS_INT128 1 # endif # ifdef _LIBCPP_CXX03_LANG @@ -631,10 +633,6 @@ typedef __char32_t char32_t; # define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) # endif // _LIBCPP_CXX03_LANG -# if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT_LIKE) || defined(__NetBSD__) -# define _LIBCPP_LOCALE__L_EXTENSIONS 1 -# endif - # ifdef __FreeBSD__ # define _DECLARE_C99_LDBL_MATH 1 # endif @@ -642,29 +640,39 @@ typedef __char32_t char32_t; // If we are getting operator new from the MSVC CRT, then allocation overloads // for align_val_t were added in 19.12, aka VS 2017 version 15.3. # if defined(_LIBCPP_MSVCRT) && defined(_MSC_VER) && _MSC_VER < 1912 -# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION +# define _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION 0 # elif defined(_LIBCPP_ABI_VCRUNTIME) && !defined(__cpp_aligned_new) // We're deferring to Microsoft's STL to provide aligned new et al. We don't // have it unless the language feature test macro is defined. -# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION +# define _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION 0 # elif defined(__MVS__) -# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION +# define _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION 0 +# else +# define _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION 1 # endif -# if defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION) || (!defined(__cpp_aligned_new) || __cpp_aligned_new < 201606) -# define _LIBCPP_HAS_NO_ALIGNED_ALLOCATION +# if !_LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION || (!defined(__cpp_aligned_new) || __cpp_aligned_new < 201606) +# define _LIBCPP_HAS_ALIGNED_ALLOCATION 0 +# else +# define _LIBCPP_HAS_ALIGNED_ALLOCATION 1 # endif // It is not yet possible to use aligned_alloc() on all Apple platforms since // 10.15 was the first version to ship an implementation of aligned_alloc(). # if defined(__APPLE__) # if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \ - __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500) -# define _LIBCPP_HAS_NO_C11_ALIGNED_ALLOC + __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500) || \ + (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && \ + __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 130000) +# define _LIBCPP_HAS_C11_ALIGNED_ALLOC 0 +# else +# define _LIBCPP_HAS_C11_ALIGNED_ALLOC 1 # endif # elif defined(__ANDROID__) && __ANDROID_API__ < 28 // Android only provides aligned_alloc when targeting API 28 or higher. -# define _LIBCPP_HAS_NO_C11_ALIGNED_ALLOC +# define _LIBCPP_HAS_C11_ALIGNED_ALLOC 0 +# else +# define _LIBCPP_HAS_C11_ALIGNED_ALLOC 1 # endif # if defined(__APPLE__) || defined(__FreeBSD__) @@ -676,7 +684,9 @@ typedef __char32_t char32_t; # endif # if _LIBCPP_STD_VER <= 17 || !defined(__cpp_char8_t) -# define _LIBCPP_HAS_NO_CHAR8_T +# define _LIBCPP_HAS_CHAR8_T 0 +# else +# define _LIBCPP_HAS_CHAR8_T 1 # endif // Deprecation macros. @@ -699,14 +709,6 @@ typedef __char32_t char32_t; # define _LIBCPP_DEPRECATED_(m) # endif -# if _LIBCPP_STD_VER < 20 -# define _LIBCPP_DEPRECATED_ATOMIC_SYNC \ - _LIBCPP_DEPRECATED_("The C++20 synchronization library has been deprecated prior to C++20. Please update to " \ - "using -std=c++20 if you need to use these facilities.") -# else -# define _LIBCPP_DEPRECATED_ATOMIC_SYNC /* nothing */ -# endif - # if !defined(_LIBCPP_CXX03_LANG) # define _LIBCPP_DEPRECATED_IN_CXX11 _LIBCPP_DEPRECATED # else @@ -743,7 +745,7 @@ typedef __char32_t char32_t; # define _LIBCPP_DEPRECATED_IN_CXX26 # endif -# if !defined(_LIBCPP_HAS_NO_CHAR8_T) +# if _LIBCPP_HAS_CHAR8_T # define _LIBCPP_DEPRECATED_WITH_CHAR8_T _LIBCPP_DEPRECATED # else # define _LIBCPP_DEPRECATED_WITH_CHAR8_T @@ -796,16 +798,22 @@ typedef __char32_t char32_t; # define _LIBCPP_CONSTEXPR_SINCE_CXX23 # endif +# if _LIBCPP_STD_VER >= 26 +# define _LIBCPP_CONSTEXPR_SINCE_CXX26 constexpr +# else +# define _LIBCPP_CONSTEXPR_SINCE_CXX26 +# endif + # ifndef _LIBCPP_WEAK # define _LIBCPP_WEAK __attribute__((__weak__)) # endif // Thread API // clang-format off -# if !defined(_LIBCPP_HAS_NO_THREADS) && \ - !defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && \ - !defined(_LIBCPP_HAS_THREAD_API_WIN32) && \ - !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) +# if _LIBCPP_HAS_THREADS && \ + !_LIBCPP_HAS_THREAD_API_PTHREAD && \ + !_LIBCPP_HAS_THREAD_API_WIN32 && \ + !_LIBCPP_HAS_THREAD_API_EXTERNAL # if defined(__FreeBSD__) || \ defined(__wasi__) || \ @@ -819,43 +827,49 @@ typedef __char32_t char32_t; defined(_AIX) || \ defined(__EMSCRIPTEN__) // clang-format on -# define _LIBCPP_HAS_THREAD_API_PTHREAD +# undef _LIBCPP_HAS_THREAD_API_PTHREAD +# define _LIBCPP_HAS_THREAD_API_PTHREAD 1 # elif defined(__Fuchsia__) // TODO(44575): Switch to C11 thread API when possible. -# define _LIBCPP_HAS_THREAD_API_PTHREAD +# undef _LIBCPP_HAS_THREAD_API_PTHREAD +# define _LIBCPP_HAS_THREAD_API_PTHREAD 1 # elif defined(_LIBCPP_WIN32API) -# define _LIBCPP_HAS_THREAD_API_WIN32 +# undef _LIBCPP_HAS_THREAD_API_WIN32 +# define _LIBCPP_HAS_THREAD_API_WIN32 1 # else # error "No thread API" # endif // _LIBCPP_HAS_THREAD_API -# endif // _LIBCPP_HAS_NO_THREADS +# endif // _LIBCPP_HAS_THREADS -# if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) +# if _LIBCPP_HAS_THREAD_API_PTHREAD # if defined(__ANDROID__) && __ANDROID_API__ >= 30 -# define _LIBCPP_HAS_COND_CLOCKWAIT +# define _LIBCPP_HAS_COND_CLOCKWAIT 1 # elif defined(_LIBCPP_GLIBC_PREREQ) # if _LIBCPP_GLIBC_PREREQ(2, 30) -# define _LIBCPP_HAS_COND_CLOCKWAIT +# define _LIBCPP_HAS_COND_CLOCKWAIT 1 +# else +# define _LIBCPP_HAS_COND_CLOCKWAIT 0 # endif +# else +# define _LIBCPP_HAS_COND_CLOCKWAIT 0 # endif +# else +# define _LIBCPP_HAS_COND_CLOCKWAIT 0 # endif -# if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_PTHREAD) -# error _LIBCPP_HAS_THREAD_API_PTHREAD may only be defined when \ - _LIBCPP_HAS_NO_THREADS is not defined. +# if !_LIBCPP_HAS_THREADS && _LIBCPP_HAS_THREAD_API_PTHREAD +# error _LIBCPP_HAS_THREAD_API_PTHREAD may only be true when _LIBCPP_HAS_THREADS is true. # endif -# if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) -# error _LIBCPP_HAS_THREAD_API_EXTERNAL may not be defined when \ - _LIBCPP_HAS_NO_THREADS is defined. +# if !_LIBCPP_HAS_THREADS && _LIBCPP_HAS_THREAD_API_EXTERNAL +# error _LIBCPP_HAS_THREAD_API_EXTERNAL may only be true when _LIBCPP_HAS_THREADS is true. # endif -# if defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK) && !defined(_LIBCPP_HAS_NO_THREADS) -# error _LIBCPP_HAS_NO_MONOTONIC_CLOCK may only be defined when \ - _LIBCPP_HAS_NO_THREADS is defined. +# if !_LIBCPP_HAS_MONOTONIC_CLOCK && _LIBCPP_HAS_THREADS +# error _LIBCPP_HAS_MONOTONIC_CLOCK may only be false when _LIBCPP_HAS_THREADS is false. # endif -# if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(__STDCPP_THREADS__) +# if _LIBCPP_HAS_THREADS && !defined(__STDCPP_THREADS__) # define __STDCPP_THREADS__ 1 # endif @@ -870,11 +884,13 @@ typedef __char32_t char32_t; // TODO(EricWF): Enable this optimization on Bionic after speaking to their // respective stakeholders. // clang-format off -# if (defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && defined(__GLIBC__)) || \ - (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) || \ - defined(_LIBCPP_HAS_THREAD_API_WIN32) +# if (_LIBCPP_HAS_THREAD_API_PTHREAD && defined(__GLIBC__)) || \ + (_LIBCPP_HAS_THREAD_API_C11 && defined(__Fuchsia__)) || \ + _LIBCPP_HAS_THREAD_API_WIN32 // clang-format on -# define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION +# define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION 1 +# else +# define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION 0 # endif // Destroying a condvar is a nop on Windows. @@ -885,25 +901,31 @@ typedef __char32_t char32_t; // // TODO(EricWF): This is potentially true for some pthread implementations // as well. -# if (defined(_LIBCPP_HAS_THREAD_API_C11) && defined(__Fuchsia__)) || defined(_LIBCPP_HAS_THREAD_API_WIN32) -# define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION +# if (_LIBCPP_HAS_THREAD_API_C11 && defined(__Fuchsia__)) || _LIBCPP_HAS_THREAD_API_WIN32 +# define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION 1 +# else +# define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION 0 # endif # if defined(__BIONIC__) || defined(__NuttX__) || defined(__Fuchsia__) || defined(__wasi__) || \ - defined(_LIBCPP_HAS_MUSL_LIBC) || defined(__OpenBSD__) + _LIBCPP_HAS_MUSL_LIBC || defined(__OpenBSD__) || defined(__LLVM_LIBC__) # define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE # endif # if __has_feature(cxx_atomic) || __has_extension(c_atomic) || __has_keyword(_Atomic) -# define _LIBCPP_HAS_C_ATOMIC_IMP +# define _LIBCPP_HAS_C_ATOMIC_IMP 1 +# define _LIBCPP_HAS_GCC_ATOMIC_IMP 0 +# define _LIBCPP_HAS_EXTERNAL_ATOMIC_IMP 0 # elif defined(_LIBCPP_COMPILER_GCC) -# define _LIBCPP_HAS_GCC_ATOMIC_IMP +# define _LIBCPP_HAS_C_ATOMIC_IMP 0 +# define _LIBCPP_HAS_GCC_ATOMIC_IMP 1 +# define _LIBCPP_HAS_EXTERNAL_ATOMIC_IMP 0 # endif -# if !defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) && \ - !defined(_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP) -# define _LIBCPP_HAS_NO_ATOMIC_HEADER +# if !_LIBCPP_HAS_C_ATOMIC_IMP && !_LIBCPP_HAS_GCC_ATOMIC_IMP && !_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP +# define _LIBCPP_HAS_ATOMIC_HEADER 0 # else +# define _LIBCPP_HAS_ATOMIC_HEADER 1 # ifndef _LIBCPP_ATOMIC_FLAG_TYPE # define _LIBCPP_ATOMIC_FLAG_TYPE bool # endif @@ -915,19 +937,18 @@ typedef __char32_t char32_t; # define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS # endif -# if defined(_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS) -# if defined(__clang__) && __has_attribute(acquire_capability) // Work around the attribute handling in clang. When both __declspec and // __attribute__ are present, the processing goes awry preventing the definition // of the types. In MinGW mode, __declspec evaluates to __attribute__, and thus // combining the two does work. -# if !defined(_MSC_VER) -# define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS -# endif -# endif +# if defined(_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS) && defined(__clang__) && \ + __has_attribute(acquire_capability) && !defined(_MSC_VER) +# define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS 1 +# else +# define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS 0 # endif -# ifdef _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS +# if _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS # define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) __attribute__((x)) # else # define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) @@ -962,7 +983,7 @@ typedef __char32_t char32_t; // When wide characters are disabled, it can be useful to have a quick way of // disabling it without having to resort to #if-#endif, which has a larger // impact on readability. -# if defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS) +# if !_LIBCPP_HAS_WIDE_CHARACTERS # define _LIBCPP_IF_WIDE_CHARACTERS(...) # else # define _LIBCPP_IF_WIDE_CHARACTERS(...) __VA_ARGS__ @@ -999,28 +1020,16 @@ typedef __char32_t char32_t; // (If/when MSVC breaks its C++ ABI, it will be changed to work as intended.) // However, MSVC implements [[msvc::no_unique_address]] which does what // [[no_unique_address]] is supposed to do, in general. - -// Clang-cl does not yet (14.0) implement either [[no_unique_address]] or -// [[msvc::no_unique_address]] though. If/when it does implement -// [[msvc::no_unique_address]], this should be preferred though. # define _LIBCPP_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]] -# elif __has_cpp_attribute(no_unique_address) -# define _LIBCPP_NO_UNIQUE_ADDRESS [[__no_unique_address__]] # else -# define _LIBCPP_NO_UNIQUE_ADDRESS /* nothing */ -// Note that this can be replaced by #error as soon as clang-cl -// implements msvc::no_unique_address, since there should be no C++20 -// compiler that doesn't support one of the two attributes at that point. -// We generally don't want to use this macro outside of C++20-only code, -// because using it conditionally in one language version only would make -// the ABI inconsistent. +# define _LIBCPP_NO_UNIQUE_ADDRESS [[__no_unique_address__]] # endif // c8rtomb() and mbrtoc8() were added in C++20 and C23. Support for these // functions is gradually being added to existing C libraries. The conditions // below check for known C library versions and conditions under which these // functions are declared by the C library. -# define _LIBCPP_HAS_NO_C8RTOMB_MBRTOC8 +// // GNU libc 2.36 and newer declare c8rtomb() and mbrtoc8() in C++ modes if // __cpp_char8_t is defined or if C2X extensions are enabled. Determining // the latter depends on internal GNU libc details that are not appropriate @@ -1028,8 +1037,12 @@ typedef __char32_t char32_t; // defined are ignored. # if defined(_LIBCPP_GLIBC_PREREQ) # if _LIBCPP_GLIBC_PREREQ(2, 36) && defined(__cpp_char8_t) -# undef _LIBCPP_HAS_NO_C8RTOMB_MBRTOC8 +# define _LIBCPP_HAS_C8RTOMB_MBRTOC8 1 +# else +# define _LIBCPP_HAS_C8RTOMB_MBRTOC8 0 # endif +# else +# define _LIBCPP_HAS_C8RTOMB_MBRTOC8 0 # endif // There are a handful of public standard library types that are intended to @@ -1124,15 +1137,6 @@ typedef __char32_t char32_t; # define _LIBCPP_USING_IF_EXISTS # endif -# if __has_cpp_attribute(__nodiscard__) -# define _LIBCPP_NODISCARD [[__nodiscard__]] -# else -// We can't use GCC's [[gnu::warn_unused_result]] and -// __attribute__((warn_unused_result)), because GCC does not silence them via -// (void) cast. -# define _LIBCPP_NODISCARD -# endif - # if __has_attribute(__no_destroy__) # define _LIBCPP_NO_DESTROY __attribute__((__no_destroy__)) # else @@ -1160,10 +1164,19 @@ typedef __char32_t char32_t; # define _LIBCPP_LIFETIMEBOUND # endif -# if __has_attribute(__nodebug__) -# define _LIBCPP_NODEBUG __attribute__((__nodebug__)) +# if __has_cpp_attribute(_Clang::__noescape__) +# define _LIBCPP_NOESCAPE [[_Clang::__noescape__]] +# else +# define _LIBCPP_NOESCAPE +# endif + +# define _LIBCPP_NODEBUG [[__gnu__::__nodebug__]] + +# if __has_cpp_attribute(_Clang::__no_specializations__) +# define _LIBCPP_NO_SPECIALIZATIONS \ + [[_Clang::__no_specializations__("Users are not allowed to specialize this standard library entity")]] # else -# define _LIBCPP_NODEBUG +# define _LIBCPP_NO_SPECIALIZATIONS # endif # if __has_attribute(__standalone_debug__) @@ -1220,7 +1233,9 @@ typedef __char32_t char32_t; // Clang-18 has support for deducing this, but it does not set the FTM. # if defined(__cpp_explicit_this_parameter) || (defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER >= 1800) -# define _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER +# define _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER 1 +# else +# define _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER 0 # endif #endif // __cplusplus diff --git a/system/lib/libcxx/include/__config_site b/system/lib/libcxx/include/__config_site index bcb529b9da57b..fed7b598d199a 100644 --- a/system/lib/libcxx/include/__config_site +++ b/system/lib/libcxx/include/__config_site @@ -1,10 +1,27 @@ // Set the LIBCPP ABI version 2 under emscripten so that we get nicely aligned string // data and other nice fixes. #define _LIBCPP_ABI_VERSION 2 -#define _LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS -#define _LIBCPP_HAS_MUSL_LIBC #define _LIBCPP_ABI_NAMESPACE __2 -// Emscripten doesn't use PSTL at the moment. +#define _LIBCPP_ABI_FORCE_ITANIUM 0 +#define _LIBCPP_ABI_FORCE_MICROSOFT 0 +#define _LIBCPP_HAS_THREADS 1 +#define _LIBCPP_HAS_MONOTONIC_CLOCK 1 +#define _LIBCPP_HAS_MUSL_LIBC 1 +#define _LIBCPP_HAS_THREAD_API_PTHREAD 1 +#define _LIBCPP_HAS_THREAD_API_EXTERNAL 0 +#define _LIBCPP_HAS_THREAD_API_WIN32 0 +#define _LIBCPP_HAS_THREAD_API_C11 0 +#define _LIBCPP_HAS_VENDOR_AVAILABILITY_ANNOTATIONS 0 +#define _LIBCPP_HAS_FILESYSTEM 1 +#define _LIBCPP_HAS_RANDOM_DEVICE 1 +#define _LIBCPP_HAS_LOCALIZATION 1 +#define _LIBCPP_HAS_UNICODE 1 +#define _LIBCPP_HAS_WIDE_CHARACTERS 1 +#define _LIBCPP_HAS_TIME_ZONE_DATABASE 0 +#define _LIBCPP_INSTRUMENTED_WITH_ASAN 0 + +// PSTL backends: Emscripten doesn't use PSTL at the moment. #define _LIBCPP_PSTL_BACKEND_SERIAL + +// Hardening #define _LIBCPP_HARDENING_MODE_DEFAULT _LIBCPP_HARDENING_MODE_NONE -#define _LIBCPP_HAS_NO_TIME_ZONE_DATABASE diff --git a/system/lib/libcxx/include/__config_site.in b/system/lib/libcxx/include/__config_site.in index 67022146c9082..fc01aaf2d8746 100644 --- a/system/lib/libcxx/include/__config_site.in +++ b/system/lib/libcxx/include/__config_site.in @@ -11,26 +11,28 @@ #cmakedefine _LIBCPP_ABI_VERSION @_LIBCPP_ABI_VERSION@ #cmakedefine _LIBCPP_ABI_NAMESPACE @_LIBCPP_ABI_NAMESPACE@ -#cmakedefine _LIBCPP_ABI_FORCE_ITANIUM -#cmakedefine _LIBCPP_ABI_FORCE_MICROSOFT -#cmakedefine _LIBCPP_HAS_NO_THREADS -#cmakedefine _LIBCPP_HAS_NO_MONOTONIC_CLOCK -#cmakedefine _LIBCPP_HAS_MUSL_LIBC -#cmakedefine _LIBCPP_HAS_THREAD_API_PTHREAD -#cmakedefine _LIBCPP_HAS_THREAD_API_EXTERNAL -#cmakedefine _LIBCPP_HAS_THREAD_API_WIN32 +#cmakedefine01 _LIBCPP_ABI_FORCE_ITANIUM +#cmakedefine01 _LIBCPP_ABI_FORCE_MICROSOFT +#cmakedefine01 _LIBCPP_HAS_THREADS +#cmakedefine01 _LIBCPP_HAS_MONOTONIC_CLOCK +#cmakedefine01 _LIBCPP_HAS_TERMINAL +#cmakedefine01 _LIBCPP_HAS_MUSL_LIBC +#cmakedefine01 _LIBCPP_HAS_THREAD_API_PTHREAD +#cmakedefine01 _LIBCPP_HAS_THREAD_API_EXTERNAL +#cmakedefine01 _LIBCPP_HAS_THREAD_API_WIN32 +#define _LIBCPP_HAS_THREAD_API_C11 0 // FIXME: Is this guarding dead code? #cmakedefine _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS -#cmakedefine _LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS +#cmakedefine01 _LIBCPP_HAS_VENDOR_AVAILABILITY_ANNOTATIONS #cmakedefine _LIBCPP_NO_VCRUNTIME #cmakedefine _LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION @_LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION@ -#cmakedefine _LIBCPP_HAS_NO_FILESYSTEM -#cmakedefine _LIBCPP_HAS_NO_RANDOM_DEVICE -#cmakedefine _LIBCPP_HAS_NO_LOCALIZATION -#cmakedefine _LIBCPP_HAS_NO_UNICODE -#cmakedefine _LIBCPP_HAS_NO_WIDE_CHARACTERS +#cmakedefine01 _LIBCPP_HAS_FILESYSTEM +#cmakedefine01 _LIBCPP_HAS_RANDOM_DEVICE +#cmakedefine01 _LIBCPP_HAS_LOCALIZATION +#cmakedefine01 _LIBCPP_HAS_UNICODE +#cmakedefine01 _LIBCPP_HAS_WIDE_CHARACTERS #cmakedefine _LIBCPP_HAS_NO_STD_MODULES -#cmakedefine _LIBCPP_HAS_NO_TIME_ZONE_DATABASE -#cmakedefine _LIBCPP_INSTRUMENTED_WITH_ASAN +#cmakedefine01 _LIBCPP_HAS_TIME_ZONE_DATABASE +#cmakedefine01 _LIBCPP_INSTRUMENTED_WITH_ASAN // PSTL backends #cmakedefine _LIBCPP_PSTL_BACKEND_SERIAL diff --git a/system/lib/libcxx/include/__configuration/abi.h b/system/lib/libcxx/include/__configuration/abi.h index df48f56383cad..0671bf7224294 100644 --- a/system/lib/libcxx/include/__configuration/abi.h +++ b/system/lib/libcxx/include/__configuration/abi.h @@ -18,6 +18,25 @@ # pragma GCC system_header #endif +// FIXME: ABI detection should be done via compiler builtin macros. This +// is just a placeholder until Clang implements such macros. For now assume +// that Windows compilers pretending to be MSVC++ target the Microsoft ABI, +// and allow the user to explicitly specify the ABI to handle cases where this +// heuristic falls short. +#if _LIBCPP_ABI_FORCE_ITANIUM && _LIBCPP_ABI_FORCE_MICROSOFT +# error "Only one of _LIBCPP_ABI_FORCE_ITANIUM and _LIBCPP_ABI_FORCE_MICROSOFT can be true" +#elif _LIBCPP_ABI_FORCE_ITANIUM +# define _LIBCPP_ABI_ITANIUM +#elif _LIBCPP_ABI_FORCE_MICROSOFT +# define _LIBCPP_ABI_MICROSOFT +#else +# if defined(_WIN32) && defined(_MSC_VER) +# define _LIBCPP_ABI_MICROSOFT +# else +# define _LIBCPP_ABI_ITANIUM +# endif +#endif + #if _LIBCPP_ABI_VERSION >= 2 // Change short string representation so that string data starts at offset 0, // improving its alignment in some cases. @@ -99,10 +118,13 @@ // and WCHAR_MAX. This ABI setting determines whether we should instead track whether the fill // value has been initialized using a separate boolean, which changes the ABI. # define _LIBCPP_ABI_IOS_ALLOW_ARBITRARY_FILL_VALUE -// Make a std::pair of trivially copyable types trivially copyable. -// While this technically doesn't change the layout of pair itself, other types may decide to programatically change -// their representation based on whether something is trivially copyable. -# define _LIBCPP_ABI_TRIVIALLY_COPYABLE_PAIR +// Historically, libc++ used a type called `__compressed_pair` to reduce storage needs in cases of empty types (e.g. an +// empty allocator in std::vector). We switched to using `[[no_unique_address]]`. However, for ABI compatibility reasons +// we had to add artificial padding in a few places. +// +// This setting disables the addition of such artificial padding, leading to a more optimal +// representation for several types. +# define _LIBCPP_ABI_NO_COMPRESSED_PAIR_PADDING #elif _LIBCPP_ABI_VERSION == 1 # if !(defined(_LIBCPP_OBJECT_FORMAT_COFF) || defined(_LIBCPP_OBJECT_FORMAT_XCOFF)) // Enable compiling copies of now inline methods into the dylib to support @@ -155,6 +177,26 @@ // ABI impact: changes the iterator type of `vector` (except `vector`). // #define _LIBCPP_ABI_BOUNDED_ITERATORS_IN_VECTOR +// Changes the iterator type of `array` to a bounded iterator that keeps track of whether it's within the bounds of the +// container and asserts it on every dereference and when performing iterator arithmetic. +// +// ABI impact: changes the iterator type of `array`, its size and its layout. +// #define _LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY + +// [[msvc::no_unique_address]] seems to mostly affect empty classes, so the padding scheme for Itanium doesn't work. +#if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_ABI_NO_COMPRESSED_PAIR_PADDING) +# define _LIBCPP_ABI_NO_COMPRESSED_PAIR_PADDING +#endif + +// Tracks the bounds of the array owned by std::unique_ptr, allowing it to trap when accessed out-of-bounds. +// Note that limited bounds checking is also available outside of this ABI configuration, but only some categories +// of types can be checked. +// +// ABI impact: This causes the layout of std::unique_ptr to change and its size to increase. +// This also affects the representation of a few library types that use std::unique_ptr +// internally, such as the unordered containers. +// #define _LIBCPP_ABI_BOUNDED_UNIQUE_PTR + #if defined(_LIBCPP_COMPILER_CLANG_BASED) # if defined(__APPLE__) # if defined(__i386__) || defined(__x86_64__) diff --git a/system/lib/libcxx/include/__configuration/availability.h b/system/lib/libcxx/include/__configuration/availability.h index ab483a07c9c13..f9e52a690c05c 100644 --- a/system/lib/libcxx/include/__configuration/availability.h +++ b/system/lib/libcxx/include/__configuration/availability.h @@ -67,25 +67,19 @@ // // [1]: https://clang.llvm.org/docs/AttributeReference.html#availability -// For backwards compatibility, allow users to define _LIBCPP_DISABLE_AVAILABILITY -// for a while. -#if defined(_LIBCPP_DISABLE_AVAILABILITY) -# if !defined(_LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS) -# define _LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS -# endif -#endif - // Availability markup is disabled when building the library, or when a non-Clang // compiler is used because only Clang supports the necessary attributes. #if defined(_LIBCPP_BUILDING_LIBRARY) || defined(_LIBCXXABI_BUILDING_LIBRARY) || !defined(_LIBCPP_COMPILER_CLANG_BASED) -# if !defined(_LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS) -# define _LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS -# endif +# undef _LIBCPP_HAS_VENDOR_AVAILABILITY_ANNOTATIONS +# define _LIBCPP_HAS_VENDOR_AVAILABILITY_ANNOTATIONS 0 #endif // When availability annotations are disabled, we take for granted that features introduced // in all versions of the library are available. -#if defined(_LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS) +#if !_LIBCPP_HAS_VENDOR_AVAILABILITY_ANNOTATIONS + +# define _LIBCPP_INTRODUCED_IN_LLVM_20 1 +# define _LIBCPP_INTRODUCED_IN_LLVM_20_ATTRIBUTE /* nothing */ # define _LIBCPP_INTRODUCED_IN_LLVM_19 1 # define _LIBCPP_INTRODUCED_IN_LLVM_19_ATTRIBUTE /* nothing */ @@ -93,9 +87,6 @@ # define _LIBCPP_INTRODUCED_IN_LLVM_18 1 # define _LIBCPP_INTRODUCED_IN_LLVM_18_ATTRIBUTE /* nothing */ -# define _LIBCPP_INTRODUCED_IN_LLVM_17 1 -# define _LIBCPP_INTRODUCED_IN_LLVM_17_ATTRIBUTE /* nothing */ - # define _LIBCPP_INTRODUCED_IN_LLVM_16 1 # define _LIBCPP_INTRODUCED_IN_LLVM_16_ATTRIBUTE /* nothing */ @@ -105,26 +96,17 @@ # define _LIBCPP_INTRODUCED_IN_LLVM_14 1 # define _LIBCPP_INTRODUCED_IN_LLVM_14_ATTRIBUTE /* nothing */ -# define _LIBCPP_INTRODUCED_IN_LLVM_13 1 -# define _LIBCPP_INTRODUCED_IN_LLVM_13_ATTRIBUTE /* nothing */ - # define _LIBCPP_INTRODUCED_IN_LLVM_12 1 # define _LIBCPP_INTRODUCED_IN_LLVM_12_ATTRIBUTE /* nothing */ # define _LIBCPP_INTRODUCED_IN_LLVM_11 1 # define _LIBCPP_INTRODUCED_IN_LLVM_11_ATTRIBUTE /* nothing */ -# define _LIBCPP_INTRODUCED_IN_LLVM_10 1 -# define _LIBCPP_INTRODUCED_IN_LLVM_10_ATTRIBUTE /* nothing */ - # define _LIBCPP_INTRODUCED_IN_LLVM_9 1 # define _LIBCPP_INTRODUCED_IN_LLVM_9_ATTRIBUTE /* nothing */ # define _LIBCPP_INTRODUCED_IN_LLVM_9_ATTRIBUTE_PUSH /* nothing */ # define _LIBCPP_INTRODUCED_IN_LLVM_9_ATTRIBUTE_POP /* nothing */ -# define _LIBCPP_INTRODUCED_IN_LLVM_8 1 -# define _LIBCPP_INTRODUCED_IN_LLVM_8_ATTRIBUTE /* nothing */ - # define _LIBCPP_INTRODUCED_IN_LLVM_4 1 # define _LIBCPP_INTRODUCED_IN_LLVM_4_ATTRIBUTE /* nothing */ @@ -132,36 +114,42 @@ // clang-format off +// LLVM 20 +// TODO: Fill this in +# define _LIBCPP_INTRODUCED_IN_LLVM_20 0 +# define _LIBCPP_INTRODUCED_IN_LLVM_20_ATTRIBUTE __attribute__((unavailable)) + // LLVM 19 // TODO: Fill this in # define _LIBCPP_INTRODUCED_IN_LLVM_19 0 # define _LIBCPP_INTRODUCED_IN_LLVM_19_ATTRIBUTE __attribute__((unavailable)) // LLVM 18 -// TODO: Fill this in -# define _LIBCPP_INTRODUCED_IN_LLVM_18 0 -# define _LIBCPP_INTRODUCED_IN_LLVM_18_ATTRIBUTE __attribute__((unavailable)) - -// LLVM 17 -# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 140400) || \ - (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 170400) || \ - (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 170400) || \ - (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 100400) -# define _LIBCPP_INTRODUCED_IN_LLVM_17 0 +# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 150000) || \ + (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 180000) || \ + (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 180000) || \ + (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 110000) || \ + (defined(__ENVIRONMENT_BRIDGE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_BRIDGE_OS_VERSION_MIN_REQUIRED__ < 90000) || \ + (defined(__ENVIRONMENT_DRIVERKIT_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_DRIVERKIT_VERSION_MIN_REQUIRED__ < 240000) +# define _LIBCPP_INTRODUCED_IN_LLVM_18 0 # else -# define _LIBCPP_INTRODUCED_IN_LLVM_17 1 +# define _LIBCPP_INTRODUCED_IN_LLVM_18 1 # endif -# define _LIBCPP_INTRODUCED_IN_LLVM_17_ATTRIBUTE \ - __attribute__((availability(macos, strict, introduced = 14.4))) \ - __attribute__((availability(ios, strict, introduced = 17.4))) \ - __attribute__((availability(tvos, strict, introduced = 17.4))) \ - __attribute__((availability(watchos, strict, introduced = 10.4))) +# define _LIBCPP_INTRODUCED_IN_LLVM_18_ATTRIBUTE \ + __attribute__((availability(macos, strict, introduced = 15.0))) \ + __attribute__((availability(ios, strict, introduced = 18.0))) \ + __attribute__((availability(tvos, strict, introduced = 18.0))) \ + __attribute__((availability(watchos, strict, introduced = 11.0))) \ + __attribute__((availability(bridgeos, strict, introduced = 9.0))) \ + __attribute__((availability(driverkit, strict, introduced = 24.0))) // LLVM 16 # if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 140000) || \ (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 170000) || \ (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 170000) || \ - (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 100000) + (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 100000) || \ + (defined(__ENVIRONMENT_BRIDGE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_BRIDGE_OS_VERSION_MIN_REQUIRED__ < 80000) || \ + (defined(__ENVIRONMENT_DRIVERKIT_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_DRIVERKIT_VERSION_MIN_REQUIRED__ < 230000) # define _LIBCPP_INTRODUCED_IN_LLVM_16 0 # else # define _LIBCPP_INTRODUCED_IN_LLVM_16 1 @@ -170,47 +158,40 @@ __attribute__((availability(macos, strict, introduced = 14.0))) \ __attribute__((availability(ios, strict, introduced = 17.0))) \ __attribute__((availability(tvos, strict, introduced = 17.0))) \ - __attribute__((availability(watchos, strict, introduced = 10.0))) + __attribute__((availability(watchos, strict, introduced = 10.0))) \ + __attribute__((availability(bridgeos, strict, introduced = 8.0))) \ + __attribute__((availability(driverkit, strict, introduced = 23.0))) // LLVM 15 -# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 130400) || \ - (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 160500) || \ - (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 160500) || \ - (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 90500) +# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 130300) || \ + (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 160300) || \ + (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 160300) || \ + (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 90300) || \ + (defined(__ENVIRONMENT_BRIDGE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_BRIDGE_OS_VERSION_MIN_REQUIRED__ < 70500) || \ + (defined(__ENVIRONMENT_DRIVERKIT_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_DRIVERKIT_VERSION_MIN_REQUIRED__ < 220400) # define _LIBCPP_INTRODUCED_IN_LLVM_15 0 # else # define _LIBCPP_INTRODUCED_IN_LLVM_15 1 # endif # define _LIBCPP_INTRODUCED_IN_LLVM_15_ATTRIBUTE \ - __attribute__((availability(macos, strict, introduced = 13.4))) \ - __attribute__((availability(ios, strict, introduced = 16.5))) \ - __attribute__((availability(tvos, strict, introduced = 16.5))) \ - __attribute__((availability(watchos, strict, introduced = 9.5))) + __attribute__((availability(macos, strict, introduced = 13.3))) \ + __attribute__((availability(ios, strict, introduced = 16.3))) \ + __attribute__((availability(tvos, strict, introduced = 16.3))) \ + __attribute__((availability(watchos, strict, introduced = 9.3))) \ + __attribute__((availability(bridgeos, strict, introduced = 7.5))) \ + __attribute__((availability(driverkit, strict, introduced = 22.4))) // LLVM 14 # define _LIBCPP_INTRODUCED_IN_LLVM_14 _LIBCPP_INTRODUCED_IN_LLVM_15 # define _LIBCPP_INTRODUCED_IN_LLVM_14_ATTRIBUTE _LIBCPP_INTRODUCED_IN_LLVM_15_ATTRIBUTE -// LLVM 13 -# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 130000) || \ - (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 160000) || \ - (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 160000) || \ - (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 90000) -# define _LIBCPP_INTRODUCED_IN_LLVM_13 0 -# else -# define _LIBCPP_INTRODUCED_IN_LLVM_13 1 -# endif -# define _LIBCPP_INTRODUCED_IN_LLVM_13_ATTRIBUTE \ - __attribute__((availability(macos, strict, introduced = 13.0))) \ - __attribute__((availability(ios, strict, introduced = 16.0))) \ - __attribute__((availability(tvos, strict, introduced = 16.0))) \ - __attribute__((availability(watchos, strict, introduced = 9.0))) - // LLVM 12 # if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 120300) || \ (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 150300) || \ (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 150300) || \ - (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 80300) + (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 80300) || \ + (defined(__ENVIRONMENT_BRIDGE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_BRIDGE_OS_VERSION_MIN_REQUIRED__ < 60000) || \ + (defined(__ENVIRONMENT_DRIVERKIT_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_DRIVERKIT_VERSION_MIN_REQUIRED__ < 210300) # define _LIBCPP_INTRODUCED_IN_LLVM_12 0 # else # define _LIBCPP_INTRODUCED_IN_LLVM_12 1 @@ -219,7 +200,9 @@ __attribute__((availability(macos, strict, introduced = 12.3))) \ __attribute__((availability(ios, strict, introduced = 15.3))) \ __attribute__((availability(tvos, strict, introduced = 15.3))) \ - __attribute__((availability(watchos, strict, introduced = 8.3))) + __attribute__((availability(watchos, strict, introduced = 8.3))) \ + __attribute__((availability(bridgeos, strict, introduced = 6.0))) \ + __attribute__((availability(driverkit, strict, introduced = 21.3))) // LLVM 11 # if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 110000) || \ @@ -236,10 +219,6 @@ __attribute__((availability(tvos, strict, introduced = 14.0))) \ __attribute__((availability(watchos, strict, introduced = 7.0))) -// LLVM 10 -# define _LIBCPP_INTRODUCED_IN_LLVM_10 _LIBCPP_INTRODUCED_IN_LLVM_11 -# define _LIBCPP_INTRODUCED_IN_LLVM_10_ATTRIBUTE _LIBCPP_INTRODUCED_IN_LLVM_11_ATTRIBUTE - // LLVM 9 # if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500) || \ (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 130000) || \ @@ -375,10 +354,15 @@ #define _LIBCPP_AVAILABILITY_HAS_BAD_EXPECTED_ACCESS_KEY_FUNCTION _LIBCPP_INTRODUCED_IN_LLVM_19 #define _LIBCPP_AVAILABILITY_BAD_EXPECTED_ACCESS_KEY_FUNCTION _LIBCPP_INTRODUCED_IN_LLVM_19_ATTRIBUTE -// Define availability attributes that depend on _LIBCPP_HAS_NO_EXCEPTIONS. +// This controls the availability of floating-point std::from_chars functions. +// These overloads were added later than the integer overloads. +#define _LIBCPP_AVAILABILITY_HAS_FROM_CHARS_FLOATING_POINT _LIBCPP_INTRODUCED_IN_LLVM_20 +#define _LIBCPP_AVAILABILITY_FROM_CHARS_FLOATING_POINT _LIBCPP_INTRODUCED_IN_LLVM_20_ATTRIBUTE + +// Define availability attributes that depend on _LIBCPP_HAS_EXCEPTIONS. // Those are defined in terms of the availability attributes above, and // should not be vendor-specific. -#if defined(_LIBCPP_HAS_NO_EXCEPTIONS) +#if !_LIBCPP_HAS_EXCEPTIONS # define _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST # define _LIBCPP_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS # define _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS @@ -389,8 +373,8 @@ #endif // Define availability attributes that depend on both -// _LIBCPP_HAS_NO_EXCEPTIONS and _LIBCPP_HAS_NO_RTTI. -#if defined(_LIBCPP_HAS_NO_EXCEPTIONS) || defined(_LIBCPP_HAS_NO_RTTI) +// _LIBCPP_HAS_EXCEPTIONS and _LIBCPP_HAS_RTTI. +#if !_LIBCPP_HAS_EXCEPTIONS || !_LIBCPP_HAS_RTTI # undef _LIBCPP_AVAILABILITY_HAS_INIT_PRIMARY_EXCEPTION # undef _LIBCPP_AVAILABILITY_INIT_PRIMARY_EXCEPTION # define _LIBCPP_AVAILABILITY_HAS_INIT_PRIMARY_EXCEPTION 0 diff --git a/system/lib/libcxx/include/__configuration/compiler.h b/system/lib/libcxx/include/__configuration/compiler.h index 80ece22bb50bd..cf459a0619b23 100644 --- a/system/lib/libcxx/include/__configuration/compiler.h +++ b/system/lib/libcxx/include/__configuration/compiler.h @@ -33,8 +33,8 @@ // Warn if a compiler version is used that is not supported anymore // LLVM RELEASE Update the minimum compiler versions # if defined(_LIBCPP_CLANG_VER) -# if _LIBCPP_CLANG_VER < 1700 -# warning "Libc++ only supports Clang 17 and later" +# if _LIBCPP_CLANG_VER < 1800 +# warning "Libc++ only supports Clang 18 and later" # endif # elif defined(_LIBCPP_APPLE_CLANG_VER) # if _LIBCPP_APPLE_CLANG_VER < 1500 diff --git a/system/lib/libcxx/include/__configuration/language.h b/system/lib/libcxx/include/__configuration/language.h index fa62a7b6f5c2a..9c224dfa76e40 100644 --- a/system/lib/libcxx/include/__configuration/language.h +++ b/system/lib/libcxx/include/__configuration/language.h @@ -35,12 +35,16 @@ #endif // __cplusplus // NOLINTEND(libcpp-cpp-version-check) -#if !defined(__cpp_rtti) || __cpp_rtti < 199711L -# define _LIBCPP_HAS_NO_RTTI +#if defined(__cpp_rtti) && __cpp_rtti >= 199711L +# define _LIBCPP_HAS_RTTI 1 +#else +# define _LIBCPP_HAS_RTTI 0 #endif -#if !defined(__cpp_exceptions) || __cpp_exceptions < 199711L -# define _LIBCPP_HAS_NO_EXCEPTIONS +#if defined(__cpp_exceptions) && __cpp_exceptions >= 199711L +# define _LIBCPP_HAS_EXCEPTIONS 1 +#else +# define _LIBCPP_HAS_EXCEPTIONS 0 #endif #endif // _LIBCPP___CONFIGURATION_LANGUAGE_H diff --git a/system/lib/libcxx/include/__configuration/platform.h b/system/lib/libcxx/include/__configuration/platform.h index 27f68d04e8a8d..f3c199dee172b 100644 --- a/system/lib/libcxx/include/__configuration/platform.h +++ b/system/lib/libcxx/include/__configuration/platform.h @@ -31,14 +31,23 @@ #endif // Need to detect which libc we're using if we're on Linux. -#if defined(__linux__) -# include -# if defined(__GLIBC_PREREQ) -# define _LIBCPP_GLIBC_PREREQ(a, b) __GLIBC_PREREQ(a, b) -# else -# define _LIBCPP_GLIBC_PREREQ(a, b) 0 -# endif // defined(__GLIBC_PREREQ) -#endif // defined(__linux__) +#if defined(__linux__) || defined(__AMDGPU__) || defined(__NVPTX__) +# if __has_include() +# include +# if defined(__GLIBC_PREREQ) +# define _LIBCPP_GLIBC_PREREQ(a, b) __GLIBC_PREREQ(a, b) +# else +# define _LIBCPP_GLIBC_PREREQ(a, b) 0 +# endif // defined(__GLIBC_PREREQ) +# endif +#endif + +// This is required in order for _NEWLIB_VERSION to be defined in places where we use it. +// TODO: We shouldn't be including arbitrarily-named headers from libc++ since this can break valid +// user code. Move code paths that need _NEWLIB_VERSION to another customization mechanism. +#if __has_include() +# include +#endif #ifndef __BYTE_ORDER__ # error \ diff --git a/system/lib/libcxx/include/__coroutine/coroutine_handle.h b/system/lib/libcxx/include/__coroutine/coroutine_handle.h index 4557a6643c239..e2cde20498d84 100644 --- a/system/lib/libcxx/include/__coroutine/coroutine_handle.h +++ b/system/lib/libcxx/include/__coroutine/coroutine_handle.h @@ -11,11 +11,12 @@ #include <__assert> #include <__config> +#include <__cstddef/nullptr_t.h> +#include <__cstddef/size_t.h> #include <__functional/hash.h> #include <__memory/addressof.h> #include <__type_traits/remove_cv.h> #include -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/system/lib/libcxx/include/__cstddef/byte.h b/system/lib/libcxx/include/__cstddef/byte.h new file mode 100644 index 0000000000000..09e1d75e0b41f --- /dev/null +++ b/system/lib/libcxx/include/__cstddef/byte.h @@ -0,0 +1,85 @@ +//===---------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===---------------------------------------------------------------------===// + +#ifndef _LIBCPP___CSTDDEF_BYTE_H +#define _LIBCPP___CSTDDEF_BYTE_H + +#include <__config> +#include <__fwd/byte.h> +#include <__type_traits/enable_if.h> +#include <__type_traits/is_integral.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#if _LIBCPP_STD_VER >= 17 +namespace std { // purposefully not versioned + +enum class byte : unsigned char {}; + +_LIBCPP_HIDE_FROM_ABI inline constexpr byte operator|(byte __lhs, byte __rhs) noexcept { + return static_cast( + static_cast(static_cast(__lhs) | static_cast(__rhs))); +} + +_LIBCPP_HIDE_FROM_ABI inline constexpr byte& operator|=(byte& __lhs, byte __rhs) noexcept { + return __lhs = __lhs | __rhs; +} + +_LIBCPP_HIDE_FROM_ABI inline constexpr byte operator&(byte __lhs, byte __rhs) noexcept { + return static_cast( + static_cast(static_cast(__lhs) & static_cast(__rhs))); +} + +_LIBCPP_HIDE_FROM_ABI inline constexpr byte& operator&=(byte& __lhs, byte __rhs) noexcept { + return __lhs = __lhs & __rhs; +} + +_LIBCPP_HIDE_FROM_ABI inline constexpr byte operator^(byte __lhs, byte __rhs) noexcept { + return static_cast( + static_cast(static_cast(__lhs) ^ static_cast(__rhs))); +} + +_LIBCPP_HIDE_FROM_ABI inline constexpr byte& operator^=(byte& __lhs, byte __rhs) noexcept { + return __lhs = __lhs ^ __rhs; +} + +_LIBCPP_HIDE_FROM_ABI inline constexpr byte operator~(byte __b) noexcept { + return static_cast(static_cast(~static_cast(__b))); +} + +template ::value, int> = 0> +_LIBCPP_HIDE_FROM_ABI constexpr byte& operator<<=(byte& __lhs, _Integer __shift) noexcept { + return __lhs = __lhs << __shift; +} + +template ::value, int> = 0> +_LIBCPP_HIDE_FROM_ABI constexpr byte operator<<(byte __lhs, _Integer __shift) noexcept { + return static_cast(static_cast(static_cast(__lhs) << __shift)); +} + +template ::value, int> = 0> +_LIBCPP_HIDE_FROM_ABI constexpr byte& operator>>=(byte& __lhs, _Integer __shift) noexcept { + return __lhs = __lhs >> __shift; +} + +template ::value, int> = 0> +_LIBCPP_HIDE_FROM_ABI constexpr byte operator>>(byte __lhs, _Integer __shift) noexcept { + return static_cast(static_cast(static_cast(__lhs) >> __shift)); +} + +template ::value, int> = 0> +[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Integer to_integer(byte __b) noexcept { + return static_cast<_Integer>(__b); +} + +} // namespace std +#endif // _LIBCPP_STD_VER >= 17 + +#endif // _LIBCPP___CSTDDEF_BYTE_H diff --git a/system/lib/libcxx/include/__cstddef/max_align_t.h b/system/lib/libcxx/include/__cstddef/max_align_t.h new file mode 100644 index 0000000000000..7c09c7e7f3017 --- /dev/null +++ b/system/lib/libcxx/include/__cstddef/max_align_t.h @@ -0,0 +1,27 @@ +//===---------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===---------------------------------------------------------------------===// + +#ifndef _LIBCPP___CSTDDEF_MAX_ALIGN_T_H +#define _LIBCPP___CSTDDEF_MAX_ALIGN_T_H + +#include <__config> +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if !defined(_LIBCPP_CXX03_LANG) +using ::max_align_t _LIBCPP_USING_IF_EXISTS; +#endif + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___CSTDDEF_MAX_ALIGN_T_H diff --git a/system/lib/libcxx/include/__cstddef/nullptr_t.h b/system/lib/libcxx/include/__cstddef/nullptr_t.h new file mode 100644 index 0000000000000..7eaae01753965 --- /dev/null +++ b/system/lib/libcxx/include/__cstddef/nullptr_t.h @@ -0,0 +1,24 @@ +//===---------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===---------------------------------------------------------------------===// + +#ifndef _LIBCPP___CSTDDEF_NULLPTR_T_H +#define _LIBCPP___CSTDDEF_NULLPTR_T_H + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +using nullptr_t = decltype(nullptr); + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___CSTDDEF_NULLPTR_T_H diff --git a/system/lib/libcxx/include/__cstddef/ptrdiff_t.h b/system/lib/libcxx/include/__cstddef/ptrdiff_t.h new file mode 100644 index 0000000000000..146f345a2c30c --- /dev/null +++ b/system/lib/libcxx/include/__cstddef/ptrdiff_t.h @@ -0,0 +1,24 @@ +//===---------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===---------------------------------------------------------------------===// + +#ifndef _LIBCPP___CSTDDEF_PTRDIFF_T_H +#define _LIBCPP___CSTDDEF_PTRDIFF_T_H + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +using ptrdiff_t = decltype(static_cast(nullptr) - static_cast(nullptr)); + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___CSTDDEF_PTRDIFF_T_H diff --git a/system/lib/libcxx/include/__cstddef/size_t.h b/system/lib/libcxx/include/__cstddef/size_t.h new file mode 100644 index 0000000000000..59bad93671983 --- /dev/null +++ b/system/lib/libcxx/include/__cstddef/size_t.h @@ -0,0 +1,24 @@ +//===---------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===---------------------------------------------------------------------===// + +#ifndef _LIBCPP___CSTDDEF_SIZE_T_H +#define _LIBCPP___CSTDDEF_SIZE_T_H + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +using size_t = decltype(sizeof(int)); + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___CSTDDEF_SIZE_T_H diff --git a/system/lib/libcxx/include/__debug_utils/sanitizers.h b/system/lib/libcxx/include/__debug_utils/sanitizers.h index d8547e3249330..73d192711eabb 100644 --- a/system/lib/libcxx/include/__debug_utils/sanitizers.h +++ b/system/lib/libcxx/include/__debug_utils/sanitizers.h @@ -17,7 +17,7 @@ # pragma GCC system_header #endif -#ifndef _LIBCPP_HAS_NO_ASAN +#if _LIBCPP_HAS_ASAN extern "C" { _LIBCPP_EXPORTED_FROM_ABI void @@ -28,12 +28,12 @@ _LIBCPP_EXPORTED_FROM_ABI int __sanitizer_verify_double_ended_contiguous_container(const void*, const void*, const void*, const void*); } -#endif // _LIBCPP_HAS_NO_ASAN +#endif // _LIBCPP_HAS_ASAN _LIBCPP_BEGIN_NAMESPACE_STD // ASan choices -#ifndef _LIBCPP_HAS_NO_ASAN +#if _LIBCPP_HAS_ASAN # define _LIBCPP_HAS_ASAN_CONTAINER_ANNOTATIONS_FOR_ALL_ALLOCATORS 1 #endif @@ -57,7 +57,7 @@ _LIBCPP_HIDE_FROM_ABI void __annotate_double_ended_contiguous_container( const void* __last_old_contained, const void* __first_new_contained, const void* __last_new_contained) { -#ifdef _LIBCPP_HAS_NO_ASAN +#if !_LIBCPP_HAS_ASAN (void)__first_storage; (void)__last_storage; (void)__first_old_contained; @@ -86,7 +86,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void __annotate_contiguous_c const void* __last_storage, const void* __old_last_contained, const void* __new_last_contained) { -#ifdef _LIBCPP_HAS_NO_ASAN +#if !_LIBCPP_HAS_ASAN (void)__first_storage; (void)__last_storage; (void)__old_last_contained; diff --git a/system/lib/libcxx/include/__exception/exception_ptr.h b/system/lib/libcxx/include/__exception/exception_ptr.h index beadd9212abd1..6257e6f729bf3 100644 --- a/system/lib/libcxx/include/__exception/exception_ptr.h +++ b/system/lib/libcxx/include/__exception/exception_ptr.h @@ -10,13 +10,12 @@ #define _LIBCPP___EXCEPTION_EXCEPTION_PTR_H #include <__config> +#include <__cstddef/nullptr_t.h> #include <__exception/operations.h> #include <__memory/addressof.h> #include <__memory/construct_at.h> #include <__type_traits/decay.h> -#include #include -#include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -67,7 +66,7 @@ class _LIBCPP_EXPORTED_FROM_ABI exception_ptr { public: // exception_ptr is basically a COW string. - using __trivially_relocatable = exception_ptr; + using __trivially_relocatable _LIBCPP_NODEBUG = exception_ptr; _LIBCPP_HIDE_FROM_ABI exception_ptr() _NOEXCEPT : __ptr_() {} _LIBCPP_HIDE_FROM_ABI exception_ptr(nullptr_t) _NOEXCEPT : __ptr_() {} @@ -92,7 +91,7 @@ class _LIBCPP_EXPORTED_FROM_ABI exception_ptr { template _LIBCPP_HIDE_FROM_ABI exception_ptr make_exception_ptr(_Ep __e) _NOEXCEPT { -# ifndef _LIBCPP_HAS_NO_EXCEPTIONS +# if _LIBCPP_HAS_EXCEPTIONS # if _LIBCPP_AVAILABILITY_HAS_INIT_PRIMARY_EXCEPTION && __cplusplus >= 201103L using _Ep2 = __decay_t<_Ep>; @@ -159,7 +158,7 @@ _LIBCPP_EXPORTED_FROM_ABI void swap(exception_ptr&, exception_ptr&) _NOEXCEPT; _LIBCPP_EXPORTED_FROM_ABI exception_ptr __copy_exception_ptr(void* __except, const void* __ptr); _LIBCPP_EXPORTED_FROM_ABI exception_ptr current_exception() _NOEXCEPT; -_LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void rethrow_exception(exception_ptr); +[[__noreturn__]] _LIBCPP_EXPORTED_FROM_ABI void rethrow_exception(exception_ptr); // This is a built-in template function which automagically extracts the required // information. diff --git a/system/lib/libcxx/include/__exception/nested_exception.h b/system/lib/libcxx/include/__exception/nested_exception.h index feb489f87f62f..d560b6bbc35a7 100644 --- a/system/lib/libcxx/include/__exception/nested_exception.h +++ b/system/lib/libcxx/include/__exception/nested_exception.h @@ -13,6 +13,8 @@ #include <__exception/exception_ptr.h> #include <__memory/addressof.h> #include <__type_traits/decay.h> +#include <__type_traits/enable_if.h> +#include <__type_traits/integral_constant.h> #include <__type_traits/is_base_of.h> #include <__type_traits/is_class.h> #include <__type_traits/is_constructible.h> @@ -20,7 +22,6 @@ #include <__type_traits/is_final.h> #include <__type_traits/is_polymorphic.h> #include <__utility/forward.h> -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -38,7 +39,7 @@ class _LIBCPP_EXPORTED_FROM_ABI nested_exception { virtual ~nested_exception() _NOEXCEPT; // access functions - _LIBCPP_NORETURN void rethrow_nested() const; + [[__noreturn__]] void rethrow_nested() const; _LIBCPP_HIDE_FROM_ABI exception_ptr nested_ptr() const _NOEXCEPT { return __ptr_; } }; @@ -47,26 +48,26 @@ struct __nested : public _Tp, public nested_exception { _LIBCPP_HIDE_FROM_ABI explicit __nested(const _Tp& __t) : _Tp(__t) {} }; -#ifndef _LIBCPP_HAS_NO_EXCEPTIONS +#if _LIBCPP_HAS_EXCEPTIONS template struct __throw_with_nested; template struct __throw_with_nested<_Tp, _Up, true> { - _LIBCPP_NORETURN static inline _LIBCPP_HIDE_FROM_ABI void __do_throw(_Tp&& __t) { + [[__noreturn__]] static inline _LIBCPP_HIDE_FROM_ABI void __do_throw(_Tp&& __t) { throw __nested<_Up>(std::forward<_Tp>(__t)); } }; template struct __throw_with_nested<_Tp, _Up, false> { - _LIBCPP_NORETURN static inline _LIBCPP_HIDE_FROM_ABI void __do_throw(_Tp&& __t) { throw std::forward<_Tp>(__t); } + [[__noreturn__]] static inline _LIBCPP_HIDE_FROM_ABI void __do_throw(_Tp&& __t) { throw std::forward<_Tp>(__t); } }; #endif template -_LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI void throw_with_nested(_Tp&& __t) { -#ifndef _LIBCPP_HAS_NO_EXCEPTIONS +[[__noreturn__]] _LIBCPP_HIDE_FROM_ABI void throw_with_nested(_Tp&& __t) { +#if _LIBCPP_HAS_EXCEPTIONS using _Up = __decay_t<_Tp>; static_assert(is_copy_constructible<_Up>::value, "type thrown must be CopyConstructible"); __throw_with_nested<_Tp, diff --git a/system/lib/libcxx/include/__exception/operations.h b/system/lib/libcxx/include/__exception/operations.h index 0a9c7a7c7f0d8..15520c558a0b4 100644 --- a/system/lib/libcxx/include/__exception/operations.h +++ b/system/lib/libcxx/include/__exception/operations.h @@ -10,7 +10,6 @@ #define _LIBCPP___EXCEPTION_OPERATIONS_H #include <__config> -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -22,20 +21,22 @@ namespace std { // purposefully not using versioning namespace using unexpected_handler = void (*)(); _LIBCPP_EXPORTED_FROM_ABI unexpected_handler set_unexpected(unexpected_handler) _NOEXCEPT; _LIBCPP_EXPORTED_FROM_ABI unexpected_handler get_unexpected() _NOEXCEPT; -_LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void unexpected(); +[[__noreturn__]] _LIBCPP_EXPORTED_FROM_ABI void unexpected(); #endif using terminate_handler = void (*)(); _LIBCPP_EXPORTED_FROM_ABI terminate_handler set_terminate(terminate_handler) _NOEXCEPT; _LIBCPP_EXPORTED_FROM_ABI terminate_handler get_terminate() _NOEXCEPT; -_LIBCPP_EXPORTED_FROM_ABI bool uncaught_exception() _NOEXCEPT; +#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_UNCAUGHT_EXCEPTION) +_LIBCPP_EXPORTED_FROM_ABI _LIBCPP_DEPRECATED_IN_CXX17 bool uncaught_exception() _NOEXCEPT; +#endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_UNCAUGHT_EXCEPTION) _LIBCPP_EXPORTED_FROM_ABI int uncaught_exceptions() _NOEXCEPT; class _LIBCPP_EXPORTED_FROM_ABI exception_ptr; _LIBCPP_EXPORTED_FROM_ABI exception_ptr current_exception() _NOEXCEPT; -_LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void rethrow_exception(exception_ptr); +[[__noreturn__]] _LIBCPP_EXPORTED_FROM_ABI void rethrow_exception(exception_ptr); } // namespace std #endif // _LIBCPP___EXCEPTION_OPERATIONS_H diff --git a/system/lib/libcxx/include/__exception/terminate.h b/system/lib/libcxx/include/__exception/terminate.h index e672471dc5263..0bfc3506d3791 100644 --- a/system/lib/libcxx/include/__exception/terminate.h +++ b/system/lib/libcxx/include/__exception/terminate.h @@ -16,7 +16,7 @@ #endif namespace std { // purposefully not using versioning namespace -_LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void terminate() _NOEXCEPT; +[[__noreturn__]] _LIBCPP_EXPORTED_FROM_ABI void terminate() _NOEXCEPT; } // namespace std #endif // _LIBCPP___EXCEPTION_TERMINATE_H diff --git a/system/lib/libcxx/include/__expected/expected.h b/system/lib/libcxx/include/__expected/expected.h index f618b20603e60..03bbd1623ed5c 100644 --- a/system/lib/libcxx/include/__expected/expected.h +++ b/system/lib/libcxx/include/__expected/expected.h @@ -17,9 +17,11 @@ #include <__functional/invoke.h> #include <__memory/addressof.h> #include <__memory/construct_at.h> +#include <__type_traits/conditional.h> #include <__type_traits/conjunction.h> #include <__type_traits/disjunction.h> #include <__type_traits/integral_constant.h> +#include <__type_traits/invoke.h> #include <__type_traits/is_assignable.h> #include <__type_traits/is_constructible.h> #include <__type_traits/is_convertible.h> @@ -71,7 +73,7 @@ struct __expected_construct_unexpected_from_invoke_tag {}; template _LIBCPP_HIDE_FROM_ABI void __throw_bad_expected_access(_Arg&& __arg) { -# ifndef _LIBCPP_HAS_NO_EXCEPTIONS +# if _LIBCPP_HAS_EXCEPTIONS throw bad_expected_access<_Err>(std::forward<_Arg>(__arg)); # else (void)__arg; @@ -457,14 +459,14 @@ class expected : private __expected_base<_Tp, _Err> { template friend class expected; - using __base = __expected_base<_Tp, _Err>; + using __base _LIBCPP_NODEBUG = __expected_base<_Tp, _Err>; public: using value_type = _Tp; using error_type = _Err; using unexpected_type = unexpected<_Err>; - using __trivially_relocatable = + using __trivially_relocatable _LIBCPP_NODEBUG = __conditional_t<__libcpp_is_trivially_relocatable<_Tp>::value && __libcpp_is_trivially_relocatable<_Err>::value, expected, void>; @@ -503,25 +505,24 @@ class expected : private __expected_base<_Tp, _Err> { private: template - using __can_convert = - _And< is_constructible<_Tp, _UfQual>, - is_constructible<_Err, _OtherErrQual>, - _If<_Not, bool>>::value, - _And< - _Not<_And, is_same<_Err, _OtherErr>>>, // use the copy constructor instead, see #92676 - _Not&>>, - _Not>>, - _Not&>>, - _Not>>, - _Not&, _Tp>>, - _Not&&, _Tp>>, - _Not&, _Tp>>, - _Not&&, _Tp>>>, - true_type>, - _Not, expected<_Up, _OtherErr>&>>, - _Not, expected<_Up, _OtherErr>>>, - _Not, const expected<_Up, _OtherErr>&>>, - _Not, const expected<_Up, _OtherErr>>> >; + using __can_convert _LIBCPP_NODEBUG = _And< + is_constructible<_Tp, _UfQual>, + is_constructible<_Err, _OtherErrQual>, + _If<_Not, bool>>::value, + _And< _Not<_And, is_same<_Err, _OtherErr>>>, // use the copy constructor instead, see #92676 + _Not&>>, + _Not>>, + _Not&>>, + _Not>>, + _Not&, _Tp>>, + _Not&&, _Tp>>, + _Not&, _Tp>>, + _Not&&, _Tp>>>, + true_type>, + _Not, expected<_Up, _OtherErr>&>>, + _Not, expected<_Up, _OtherErr>>>, + _Not, const expected<_Up, _OtherErr>&>>, + _Not, const expected<_Up, _OtherErr>>> >; template _LIBCPP_HIDE_FROM_ABI constexpr explicit expected( @@ -918,9 +919,9 @@ class expected : private __expected_base<_Tp, _Err> { requires is_constructible_v<_Err, _Err&> _LIBCPP_HIDE_FROM_ABI constexpr auto and_then(_Func&& __f) & { using _Up = remove_cvref_t>; - static_assert(__is_std_expected<_Up>::value, "The result of f(**this) must be a specialization of std::expected"); + static_assert(__is_std_expected<_Up>::value, "The result of f(value()) must be a specialization of std::expected"); static_assert(is_same_v, - "The result of f(**this) must have the same error_type as this expected"); + "The result of f(value()) must have the same error_type as this expected"); if (has_value()) { return std::invoke(std::forward<_Func>(__f), this->__val()); } @@ -931,9 +932,9 @@ class expected : private __expected_base<_Tp, _Err> { requires is_constructible_v<_Err, const _Err&> _LIBCPP_HIDE_FROM_ABI constexpr auto and_then(_Func&& __f) const& { using _Up = remove_cvref_t>; - static_assert(__is_std_expected<_Up>::value, "The result of f(**this) must be a specialization of std::expected"); + static_assert(__is_std_expected<_Up>::value, "The result of f(value()) must be a specialization of std::expected"); static_assert(is_same_v, - "The result of f(**this) must have the same error_type as this expected"); + "The result of f(value()) must have the same error_type as this expected"); if (has_value()) { return std::invoke(std::forward<_Func>(__f), this->__val()); } @@ -945,9 +946,9 @@ class expected : private __expected_base<_Tp, _Err> { _LIBCPP_HIDE_FROM_ABI constexpr auto and_then(_Func&& __f) && { using _Up = remove_cvref_t>; static_assert( - __is_std_expected<_Up>::value, "The result of f(std::move(**this)) must be a specialization of std::expected"); + __is_std_expected<_Up>::value, "The result of f(std::move(value())) must be a specialization of std::expected"); static_assert(is_same_v, - "The result of f(std::move(**this)) must have the same error_type as this expected"); + "The result of f(std::move(value())) must have the same error_type as this expected"); if (has_value()) { return std::invoke(std::forward<_Func>(__f), std::move(this->__val())); } @@ -959,9 +960,9 @@ class expected : private __expected_base<_Tp, _Err> { _LIBCPP_HIDE_FROM_ABI constexpr auto and_then(_Func&& __f) const&& { using _Up = remove_cvref_t>; static_assert( - __is_std_expected<_Up>::value, "The result of f(std::move(**this)) must be a specialization of std::expected"); + __is_std_expected<_Up>::value, "The result of f(std::move(value())) must be a specialization of std::expected"); static_assert(is_same_v, - "The result of f(std::move(**this)) must have the same error_type as this expected"); + "The result of f(std::move(value())) must have the same error_type as this expected"); if (has_value()) { return std::invoke(std::forward<_Func>(__f), std::move(this->__val())); } @@ -1362,7 +1363,7 @@ class expected<_Tp, _Err> : private __expected_void_base<_Err> { friend class expected; template - using __can_convert = + using __can_convert _LIBCPP_NODEBUG = _And< is_void<_Up>, is_constructible<_Err, _OtherErrQual>, _Not, expected<_Up, _OtherErr>&>>, @@ -1370,7 +1371,7 @@ class expected<_Tp, _Err> : private __expected_void_base<_Err> { _Not, const expected<_Up, _OtherErr>&>>, _Not, const expected<_Up, _OtherErr>>>>; - using __base = __expected_void_base<_Err>; + using __base _LIBCPP_NODEBUG = __expected_void_base<_Err>; public: using value_type = _Tp; @@ -1492,8 +1493,6 @@ class expected<_Tp, _Err> : private __expected_void_base<_Err> { return *this; } - _LIBCPP_HIDE_FROM_ABI constexpr expected& operator=(expected&&) = delete; - _LIBCPP_HIDE_FROM_ABI constexpr expected& operator=(expected&& __rhs) noexcept(is_nothrow_move_assignable_v<_Err> && is_nothrow_move_constructible_v<_Err>) requires(is_move_assignable_v<_Err> && is_move_constructible_v<_Err>) diff --git a/system/lib/libcxx/include/__expected/unexpected.h b/system/lib/libcxx/include/__expected/unexpected.h index c7fe3c52e4311..6904889b8c6b1 100644 --- a/system/lib/libcxx/include/__expected/unexpected.h +++ b/system/lib/libcxx/include/__expected/unexpected.h @@ -48,12 +48,12 @@ template struct __is_std_unexpected> : true_type {}; template -using __valid_std_unexpected = _BoolConstant< // - is_object_v<_Tp> && // - !is_array_v<_Tp> && // - !__is_std_unexpected<_Tp>::value && // - !is_const_v<_Tp> && // - !is_volatile_v<_Tp> // +using __valid_std_unexpected _LIBCPP_NODEBUG = _BoolConstant< // + is_object_v<_Tp> && // + !is_array_v<_Tp> && // + !__is_std_unexpected<_Tp>::value && // + !is_const_v<_Tp> && // + !is_volatile_v<_Tp> // >; template @@ -108,7 +108,7 @@ class unexpected { template _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const unexpected& __x, const unexpected<_Err2>& __y) { - return __x.__unex_ == __y.__unex_; + return __x.__unex_ == __y.error(); } private: diff --git a/system/lib/libcxx/include/__filesystem/directory_entry.h b/system/lib/libcxx/include/__filesystem/directory_entry.h index 96d88dcd90b4c..11e07acdbe00c 100644 --- a/system/lib/libcxx/include/__filesystem/directory_entry.h +++ b/system/lib/libcxx/include/__filesystem/directory_entry.h @@ -20,8 +20,11 @@ #include <__filesystem/operations.h> #include <__filesystem/path.h> #include <__filesystem/perms.h> +#include <__fwd/ostream.h> #include <__system_error/errc.h> +#include <__system_error/error_category.h> #include <__system_error/error_code.h> +#include <__system_error/error_condition.h> #include <__utility/move.h> #include <__utility/unreachable.h> #include @@ -33,7 +36,7 @@ _LIBCPP_PUSH_MACROS #include <__undef_macros> -#if _LIBCPP_STD_VER >= 17 && !defined(_LIBCPP_HAS_NO_FILESYSTEM) +#if _LIBCPP_STD_VER >= 17 && _LIBCPP_HAS_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM @@ -201,7 +204,9 @@ class directory_entry { _IterNonSymlink, _RefreshSymlink, _RefreshSymlinkUnresolved, - _RefreshNonSymlink + _RefreshNonSymlink, + _IterCachedSymlink, + _IterCachedNonSymlink }; struct __cached_data { @@ -240,6 +245,29 @@ class directory_entry { return __data; } + _LIBCPP_HIDE_FROM_ABI static __cached_data + __create_iter_cached_result(file_type __ft, uintmax_t __size, perms __perm, file_time_type __write_time) { + __cached_data __data; + __data.__type_ = __ft; + __data.__size_ = __size; + __data.__write_time_ = __write_time; + if (__ft == file_type::symlink) + __data.__sym_perms_ = __perm; + else + __data.__non_sym_perms_ = __perm; + __data.__cache_type_ = [&]() { + switch (__ft) { + case file_type::none: + return _Empty; + case file_type::symlink: + return _IterCachedSymlink; + default: + return _IterCachedNonSymlink; + } + }(); + return __data; + } + _LIBCPP_HIDE_FROM_ABI void __assign_iter_entry(_Path&& __p, __cached_data __dt) { __p_ = std::move(__p); __data_ = __dt; @@ -248,15 +276,7 @@ class directory_entry { _LIBCPP_EXPORTED_FROM_ABI error_code __do_refresh() noexcept; _LIBCPP_HIDE_FROM_ABI static bool __is_dne_error(error_code const& __ec) { - if (!__ec) - return true; - switch (static_cast(__ec.value())) { - case errc::no_such_file_or_directory: - case errc::not_a_directory: - return true; - default: - return false; - } + return !__ec || __ec == errc::no_such_file_or_directory || __ec == errc::not_a_directory; } _LIBCPP_HIDE_FROM_ABI void @@ -281,13 +301,15 @@ class directory_entry { case _Empty: return __symlink_status(__p_, __ec).type(); case _IterSymlink: + case _IterCachedSymlink: case _RefreshSymlink: case _RefreshSymlinkUnresolved: if (__ec) __ec->clear(); return file_type::symlink; + case _IterCachedNonSymlink: case _IterNonSymlink: - case _RefreshNonSymlink: + case _RefreshNonSymlink: { file_status __st(__data_.__type_); if (__ec && !filesystem::exists(__st)) *__ec = make_error_code(errc::no_such_file_or_directory); @@ -295,6 +317,7 @@ class directory_entry { __ec->clear(); return __data_.__type_; } + } __libcpp_unreachable(); } @@ -302,8 +325,10 @@ class directory_entry { switch (__data_.__cache_type_) { case _Empty: case _IterSymlink: + case _IterCachedSymlink: case _RefreshSymlinkUnresolved: return __status(__p_, __ec).type(); + case _IterCachedNonSymlink: case _IterNonSymlink: case _RefreshNonSymlink: case _RefreshSymlink: { @@ -323,8 +348,10 @@ class directory_entry { case _Empty: case _IterNonSymlink: case _IterSymlink: + case _IterCachedSymlink: case _RefreshSymlinkUnresolved: return __status(__p_, __ec); + case _IterCachedNonSymlink: case _RefreshNonSymlink: case _RefreshSymlink: return file_status(__get_ft(__ec), __data_.__non_sym_perms_); @@ -338,8 +365,10 @@ class directory_entry { case _IterNonSymlink: case _IterSymlink: return __symlink_status(__p_, __ec); + case _IterCachedNonSymlink: case _RefreshNonSymlink: return file_status(__get_sym_ft(__ec), __data_.__non_sym_perms_); + case _IterCachedSymlink: case _RefreshSymlink: case _RefreshSymlinkUnresolved: return file_status(__get_sym_ft(__ec), __data_.__sym_perms_); @@ -352,8 +381,10 @@ class directory_entry { case _Empty: case _IterNonSymlink: case _IterSymlink: + case _IterCachedSymlink: case _RefreshSymlinkUnresolved: return filesystem::__file_size(__p_, __ec); + case _IterCachedNonSymlink: case _RefreshSymlink: case _RefreshNonSymlink: { error_code __m_ec; @@ -374,6 +405,8 @@ class directory_entry { case _Empty: case _IterNonSymlink: case _IterSymlink: + case _IterCachedNonSymlink: + case _IterCachedSymlink: case _RefreshSymlinkUnresolved: return filesystem::__hard_link_count(__p_, __ec); case _RefreshSymlink: @@ -392,8 +425,10 @@ class directory_entry { case _Empty: case _IterNonSymlink: case _IterSymlink: + case _IterCachedSymlink: case _RefreshSymlinkUnresolved: return filesystem::__last_write_time(__p_, __ec); + case _IterCachedNonSymlink: case _RefreshSymlink: case _RefreshNonSymlink: { error_code __m_ec; @@ -428,7 +463,7 @@ _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY_POP _LIBCPP_END_NAMESPACE_FILESYSTEM -#endif // _LIBCPP_STD_VER >= 17 && !defined(_LIBCPP_HAS_NO_FILESYSTEM) +#endif // _LIBCPP_STD_VER >= 17 && _LIBCPP_HAS_FILESYSTEM _LIBCPP_POP_MACROS diff --git a/system/lib/libcxx/include/__filesystem/directory_iterator.h b/system/lib/libcxx/include/__filesystem/directory_iterator.h index e0246d8001e19..f5085b39ebf93 100644 --- a/system/lib/libcxx/include/__filesystem/directory_iterator.h +++ b/system/lib/libcxx/include/__filesystem/directory_iterator.h @@ -22,7 +22,6 @@ #include <__ranges/enable_view.h> #include <__system_error/error_code.h> #include <__utility/move.h> -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -31,7 +30,7 @@ _LIBCPP_PUSH_MACROS #include <__undef_macros> -#if _LIBCPP_STD_VER >= 17 && !defined(_LIBCPP_HAS_NO_FILESYSTEM) +#if _LIBCPP_STD_VER >= 17 && _LIBCPP_HAS_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM @@ -144,7 +143,7 @@ _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY inline constexpr bool # endif // _LIBCPP_STD_VER >= 20 -#endif // _LIBCPP_STD_VER >= 17 && !defined(_LIBCPP_HAS_NO_FILESYSTEM) +#endif // _LIBCPP_STD_VER >= 17 && _LIBCPP_HAS_FILESYSTEM _LIBCPP_POP_MACROS diff --git a/system/lib/libcxx/include/__filesystem/filesystem_error.h b/system/lib/libcxx/include/__filesystem/filesystem_error.h index 80a11e3b1932c..73592bba31da0 100644 --- a/system/lib/libcxx/include/__filesystem/filesystem_error.h +++ b/system/lib/libcxx/include/__filesystem/filesystem_error.h @@ -67,15 +67,15 @@ class _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY _LIBCPP_EXPORTED_FROM_ABI filesyst shared_ptr<_Storage> __storage_; }; -# ifndef _LIBCPP_HAS_NO_EXCEPTIONS +# if _LIBCPP_HAS_EXCEPTIONS template -_LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY void +[[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY void __throw_filesystem_error(_Args&&... __args) { throw filesystem_error(std::forward<_Args>(__args)...); } # else template -_LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY void +[[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY void __throw_filesystem_error(_Args&&...) { _LIBCPP_VERBOSE_ABORT("filesystem_error was thrown in -fno-exceptions mode"); } diff --git a/system/lib/libcxx/include/__filesystem/operations.h b/system/lib/libcxx/include/__filesystem/operations.h index f588189ed1d9d..904023d2fb332 100644 --- a/system/lib/libcxx/include/__filesystem/operations.h +++ b/system/lib/libcxx/include/__filesystem/operations.h @@ -27,7 +27,7 @@ # pragma GCC system_header #endif -#if _LIBCPP_STD_VER >= 17 && !defined(_LIBCPP_HAS_NO_FILESYSTEM) +#if _LIBCPP_STD_VER >= 17 && _LIBCPP_HAS_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM @@ -305,6 +305,6 @@ _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY_POP _LIBCPP_END_NAMESPACE_FILESYSTEM -#endif // _LIBCPP_STD_VER >= 17 && !defined(_LIBCPP_HAS_NO_FILESYSTEM) +#endif // _LIBCPP_STD_VER >= 17 && _LIBCPP_HAS_FILESYSTEM #endif // _LIBCPP___FILESYSTEM_OPERATIONS_H diff --git a/system/lib/libcxx/include/__filesystem/path.h b/system/lib/libcxx/include/__filesystem/path.h index ff468d517722f..0a751ba32954f 100644 --- a/system/lib/libcxx/include/__filesystem/path.h +++ b/system/lib/libcxx/include/__filesystem/path.h @@ -21,11 +21,11 @@ #include <__type_traits/is_pointer.h> #include <__type_traits/remove_const.h> #include <__type_traits/remove_pointer.h> -#include +#include <__utility/move.h> #include #include -#if !defined(_LIBCPP_HAS_NO_LOCALIZATION) +#if _LIBCPP_HAS_LOCALIZATION # include // for quoted # include #endif @@ -51,30 +51,30 @@ template struct __can_convert_char : public __can_convert_char<_Tp> {}; template <> struct __can_convert_char { - static const bool value = true; - using __char_type = char; + static const bool value = true; + using __char_type _LIBCPP_NODEBUG = char; }; template <> struct __can_convert_char { - static const bool value = true; - using __char_type = wchar_t; + static const bool value = true; + using __char_type _LIBCPP_NODEBUG = wchar_t; }; -# ifndef _LIBCPP_HAS_NO_CHAR8_T +# if _LIBCPP_HAS_CHAR8_T template <> struct __can_convert_char { - static const bool value = true; - using __char_type = char8_t; + static const bool value = true; + using __char_type _LIBCPP_NODEBUG = char8_t; }; # endif template <> struct __can_convert_char { - static const bool value = true; - using __char_type = char16_t; + static const bool value = true; + using __char_type _LIBCPP_NODEBUG = char16_t; }; template <> struct __can_convert_char { - static const bool value = true; - using __char_type = char32_t; + static const bool value = true; + using __char_type _LIBCPP_NODEBUG = char32_t; }; template ::value, int> = 0> @@ -86,7 +86,7 @@ _LIBCPP_HIDE_FROM_ABI bool __is_separator(_ECharT __e) { # endif } -# ifndef _LIBCPP_HAS_NO_CHAR8_T +# if _LIBCPP_HAS_CHAR8_T typedef u8string __u8_string; # else typedef string __u8_string; @@ -95,7 +95,7 @@ typedef string __u8_string; struct _NullSentinel {}; template -using _Void = void; +using _Void _LIBCPP_NODEBUG = void; template struct __is_pathable_string : public false_type {}; @@ -104,7 +104,7 @@ template struct __is_pathable_string< basic_string<_ECharT, _Traits, _Alloc>, _Void::__char_type> > : public __can_convert_char<_ECharT> { - using _Str = basic_string<_ECharT, _Traits, _Alloc>; + using _Str _LIBCPP_NODEBUG = basic_string<_ECharT, _Traits, _Alloc>; _LIBCPP_HIDE_FROM_ABI static _ECharT const* __range_begin(_Str const& __s) { return __s.data(); } @@ -117,7 +117,7 @@ template struct __is_pathable_string< basic_string_view<_ECharT, _Traits>, _Void::__char_type> > : public __can_convert_char<_ECharT> { - using _Str = basic_string_view<_ECharT, _Traits>; + using _Str _LIBCPP_NODEBUG = basic_string_view<_ECharT, _Traits>; _LIBCPP_HIDE_FROM_ABI static _ECharT const* __range_begin(_Str const& __s) { return __s.data(); } @@ -157,7 +157,7 @@ struct __is_pathable_iter< true, _Void::value_type>::__char_type> > : __can_convert_char::value_type> { - using _ECharT = typename iterator_traits<_Iter>::value_type; + using _ECharT _LIBCPP_NODEBUG = typename iterator_traits<_Iter>::value_type; _LIBCPP_HIDE_FROM_ABI static _Iter __range_begin(_Iter __b) { return __b; } @@ -199,7 +199,7 @@ _LIBCPP_EXPORTED_FROM_ABI size_t __char_to_wide(const string&, wchar_t*, size_t) template struct _PathCVT; -# if !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# if _LIBCPP_HAS_LOCALIZATION template struct _PathCVT { static_assert(__can_convert_char<_ECharT>::value, "Char type not convertible"); @@ -258,7 +258,7 @@ struct _PathCVT { __append_range(__dest, _Traits::__range_begin(__s), _Traits::__range_end(__s)); } }; -# endif // !_LIBCPP_HAS_NO_LOCALIZATION +# endif // _LIBCPP_HAS_LOCALIZATION template <> struct _PathCVT<__path_value> { @@ -365,7 +365,7 @@ struct _PathExport { } }; -# ifndef _LIBCPP_HAS_NO_CHAR8_T +# if _LIBCPP_HAS_CHAR8_T template <> struct _PathExport { typedef __narrow_to_utf8 _Narrower; @@ -375,18 +375,18 @@ struct _PathExport { _Narrower()(back_inserter(__dest), __src.data(), __src.data() + __src.size()); } }; -# endif /* !_LIBCPP_HAS_NO_CHAR8_T */ +# endif // _LIBCPP_HAS_CHAR8_T # endif /* _LIBCPP_WIN32API */ class _LIBCPP_EXPORTED_FROM_ABI path { template - using _EnableIfPathable = __enable_if_t<__is_pathable<_SourceOrIter>::value, _Tp>; + using _EnableIfPathable _LIBCPP_NODEBUG = __enable_if_t<__is_pathable<_SourceOrIter>::value, _Tp>; template - using _SourceChar = typename __is_pathable<_Tp>::__char_type; + using _SourceChar _LIBCPP_NODEBUG = typename __is_pathable<_Tp>::__char_type; template - using _SourceCVT = _PathCVT<_SourceChar<_Tp> >; + using _SourceCVT _LIBCPP_NODEBUG = _PathCVT<_SourceChar<_Tp> >; public: # if defined(_LIBCPP_WIN32API) @@ -420,7 +420,7 @@ class _LIBCPP_EXPORTED_FROM_ABI path { } /* - #if !defined(_LIBCPP_HAS_NO_LOCALIZATION) + #if _LIBCPP_HAS_LOCALIZATION // TODO Implement locale conversions. template > path(const _Source& __src, const locale& __loc, format = format::auto_format); @@ -682,7 +682,7 @@ class _LIBCPP_EXPORTED_FROM_ABI path { return __s; } -# if !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# if _LIBCPP_HAS_LOCALIZATION template , class _Allocator = allocator<_ECharT> > _LIBCPP_HIDE_FROM_ABI basic_string<_ECharT, _Traits, _Allocator> string(const _Allocator& __a = _Allocator()) const { using _Str = basic_string<_ECharT, _Traits, _Allocator>; @@ -725,17 +725,17 @@ class _LIBCPP_EXPORTED_FROM_ABI path { std::replace(__s.begin(), __s.end(), '\\', '/'); return __s; } -# endif /* !_LIBCPP_HAS_NO_LOCALIZATION */ +# endif // _LIBCPP_HAS_LOCALIZATION # else /* _LIBCPP_WIN32API */ _LIBCPP_HIDE_FROM_ABI std::string string() const { return __pn_; } -# ifndef _LIBCPP_HAS_NO_CHAR8_T +# if _LIBCPP_HAS_CHAR8_T _LIBCPP_HIDE_FROM_ABI std::u8string u8string() const { return std::u8string(__pn_.begin(), __pn_.end()); } # else _LIBCPP_HIDE_FROM_ABI std::string u8string() const { return __pn_; } # endif -# if !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# if _LIBCPP_HAS_LOCALIZATION template , class _Allocator = allocator<_ECharT> > _LIBCPP_HIDE_FROM_ABI basic_string<_ECharT, _Traits, _Allocator> string(const _Allocator& __a = _Allocator()) const { using _CVT = __widen_from_utf8; @@ -746,34 +746,34 @@ class _LIBCPP_EXPORTED_FROM_ABI path { return __s; } -# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +# if _LIBCPP_HAS_WIDE_CHARACTERS _LIBCPP_HIDE_FROM_ABI std::wstring wstring() const { return string(); } # endif _LIBCPP_HIDE_FROM_ABI std::u16string u16string() const { return string(); } _LIBCPP_HIDE_FROM_ABI std::u32string u32string() const { return string(); } -# endif /* !_LIBCPP_HAS_NO_LOCALIZATION */ +# endif // _LIBCPP_HAS_LOCALIZATION // generic format observers _LIBCPP_HIDE_FROM_ABI std::string generic_string() const { return __pn_; } -# ifndef _LIBCPP_HAS_NO_CHAR8_T +# if _LIBCPP_HAS_CHAR8_T _LIBCPP_HIDE_FROM_ABI std::u8string generic_u8string() const { return std::u8string(__pn_.begin(), __pn_.end()); } # else _LIBCPP_HIDE_FROM_ABI std::string generic_u8string() const { return __pn_; } # endif -# if !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# if _LIBCPP_HAS_LOCALIZATION template , class _Allocator = allocator<_ECharT> > _LIBCPP_HIDE_FROM_ABI basic_string<_ECharT, _Traits, _Allocator> generic_string(const _Allocator& __a = _Allocator()) const { return string<_ECharT, _Traits, _Allocator>(__a); } -# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +# if _LIBCPP_HAS_WIDE_CHARACTERS _LIBCPP_HIDE_FROM_ABI std::wstring generic_wstring() const { return string(); } # endif _LIBCPP_HIDE_FROM_ABI std::u16string generic_u16string() const { return string(); } _LIBCPP_HIDE_FROM_ABI std::u32string generic_u32string() const { return string(); } -# endif /* !_LIBCPP_HAS_NO_LOCALIZATION */ +# endif // _LIBCPP_HAS_LOCALIZATION # endif /* !_LIBCPP_WIN32API */ private: @@ -811,7 +811,7 @@ class _LIBCPP_EXPORTED_FROM_ABI path { _LIBCPP_HIDE_FROM_ABI path extension() const { return string_type(__extension()); } // query - _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI bool empty() const noexcept { return __pn_.empty(); } + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool empty() const noexcept { return __pn_.empty(); } _LIBCPP_HIDE_FROM_ABI bool has_root_name() const { return !__root_name().empty(); } _LIBCPP_HIDE_FROM_ABI bool has_root_directory() const { return !__root_directory().empty(); } @@ -866,7 +866,7 @@ class _LIBCPP_EXPORTED_FROM_ABI path { iterator begin() const; iterator end() const; -# if !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# if _LIBCPP_HAS_LOCALIZATION template < class _CharT, class _Traits, @@ -895,7 +895,7 @@ class _LIBCPP_EXPORTED_FROM_ABI path { __p = __tmp; return __is; } -# endif // !_LIBCPP_HAS_NO_LOCALIZATION +# endif // _LIBCPP_HAS_LOCALIZATION private: inline _LIBCPP_HIDE_FROM_ABI path& __assign_view(__string_view const& __s) { diff --git a/system/lib/libcxx/include/__filesystem/path_iterator.h b/system/lib/libcxx/include/__filesystem/path_iterator.h index f4d486d86cf38..e0f601662d462 100644 --- a/system/lib/libcxx/include/__filesystem/path_iterator.h +++ b/system/lib/libcxx/include/__filesystem/path_iterator.h @@ -14,9 +14,6 @@ #include <__config> #include <__filesystem/path.h> #include <__iterator/iterator_traits.h> -#include -#include -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/system/lib/libcxx/include/__filesystem/recursive_directory_iterator.h b/system/lib/libcxx/include/__filesystem/recursive_directory_iterator.h index caa1396eb301f..ad01a9982b690 100644 --- a/system/lib/libcxx/include/__filesystem/recursive_directory_iterator.h +++ b/system/lib/libcxx/include/__filesystem/recursive_directory_iterator.h @@ -21,7 +21,6 @@ #include <__ranges/enable_view.h> #include <__system_error/error_code.h> #include <__utility/move.h> -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -30,7 +29,7 @@ _LIBCPP_PUSH_MACROS #include <__undef_macros> -#if _LIBCPP_STD_VER >= 17 && !defined(_LIBCPP_HAS_NO_FILESYSTEM) +#if _LIBCPP_STD_VER >= 17 && _LIBCPP_HAS_FILESYSTEM _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM @@ -157,7 +156,7 @@ _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY inline constexpr bool # endif // _LIBCPP_STD_VER >= 20 -#endif // _LIBCPP_STD_VER >= 17 && !defined(_LIBCPP_HAS_NO_FILESYSTEM) +#endif // _LIBCPP_STD_VER >= 17 && _LIBCPP_HAS_FILESYSTEM _LIBCPP_POP_MACROS diff --git a/system/lib/libcxx/include/__filesystem/u8path.h b/system/lib/libcxx/include/__filesystem/u8path.h index dae5823128f02..e13980298d9e9 100644 --- a/system/lib/libcxx/include/__filesystem/u8path.h +++ b/system/lib/libcxx/include/__filesystem/u8path.h @@ -34,7 +34,7 @@ _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY_PUSH template ::value, int> = 0> _LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_WITH_CHAR8_T path u8path(_InputIt __f, _InputIt __l) { static_assert( -# ifndef _LIBCPP_HAS_NO_CHAR8_T +# if _LIBCPP_HAS_CHAR8_T is_same::__char_type, char8_t>::value || # endif is_same::__char_type, char>::value, @@ -56,7 +56,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_WITH_CHAR8_T path u8path(_InputIt __f, template ::value, int> = 0> _LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_WITH_CHAR8_T path u8path(_InputIt __f, _NullSentinel) { static_assert( -# ifndef _LIBCPP_HAS_NO_CHAR8_T +# if _LIBCPP_HAS_CHAR8_T is_same::__char_type, char8_t>::value || # endif is_same::__char_type, char>::value, @@ -77,7 +77,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_WITH_CHAR8_T path u8path(_InputIt __f, template ::value, int> = 0> _LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_WITH_CHAR8_T path u8path(const _Source& __s) { static_assert( -# ifndef _LIBCPP_HAS_NO_CHAR8_T +# if _LIBCPP_HAS_CHAR8_T is_same::__char_type, char8_t>::value || # endif is_same::__char_type, char>::value, diff --git a/system/lib/libcxx/include/__flat_map/flat_map.h b/system/lib/libcxx/include/__flat_map/flat_map.h new file mode 100644 index 0000000000000..a0594ed9dc411 --- /dev/null +++ b/system/lib/libcxx/include/__flat_map/flat_map.h @@ -0,0 +1,1199 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___FLAT_MAP_FLAT_MAP_H +#define _LIBCPP___FLAT_MAP_FLAT_MAP_H + +#include <__algorithm/lexicographical_compare_three_way.h> +#include <__algorithm/min.h> +#include <__algorithm/ranges_adjacent_find.h> +#include <__algorithm/ranges_equal.h> +#include <__algorithm/ranges_inplace_merge.h> +#include <__algorithm/ranges_lower_bound.h> +#include <__algorithm/ranges_partition_point.h> +#include <__algorithm/ranges_sort.h> +#include <__algorithm/ranges_unique.h> +#include <__algorithm/ranges_upper_bound.h> +#include <__algorithm/remove_if.h> +#include <__assert> +#include <__compare/synth_three_way.h> +#include <__concepts/swappable.h> +#include <__config> +#include <__cstddef/byte.h> +#include <__cstddef/ptrdiff_t.h> +#include <__flat_map/key_value_iterator.h> +#include <__flat_map/sorted_unique.h> +#include <__flat_map/utils.h> +#include <__functional/invoke.h> +#include <__functional/is_transparent.h> +#include <__functional/operations.h> +#include <__fwd/vector.h> +#include <__iterator/concepts.h> +#include <__iterator/distance.h> +#include <__iterator/iterator_traits.h> +#include <__iterator/next.h> +#include <__iterator/ranges_iterator_traits.h> +#include <__iterator/reverse_iterator.h> +#include <__memory/allocator_traits.h> +#include <__memory/uses_allocator.h> +#include <__memory/uses_allocator_construction.h> +#include <__ranges/access.h> +#include <__ranges/concepts.h> +#include <__ranges/container_compatible_range.h> +#include <__ranges/drop_view.h> +#include <__ranges/from_range.h> +#include <__ranges/ref_view.h> +#include <__ranges/size.h> +#include <__ranges/subrange.h> +#include <__ranges/zip_view.h> +#include <__type_traits/conjunction.h> +#include <__type_traits/container_traits.h> +#include <__type_traits/invoke.h> +#include <__type_traits/is_allocator.h> +#include <__type_traits/is_nothrow_constructible.h> +#include <__type_traits/is_same.h> +#include <__utility/exception_guard.h> +#include <__utility/move.h> +#include <__utility/pair.h> +#include <__utility/scope_guard.h> +#include <__vector/vector.h> +#include +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +#if _LIBCPP_STD_VER >= 23 + +_LIBCPP_BEGIN_NAMESPACE_STD + +template , + class _KeyContainer = vector<_Key>, + class _MappedContainer = vector<_Tp>> +class flat_map { + template + friend class flat_map; + + static_assert(is_same_v<_Key, typename _KeyContainer::value_type>); + static_assert(is_same_v<_Tp, typename _MappedContainer::value_type>); + static_assert(!is_same_v<_KeyContainer, std::vector>, "vector is not a sequence container"); + static_assert(!is_same_v<_MappedContainer, std::vector>, "vector is not a sequence container"); + + template + using __iterator _LIBCPP_NODEBUG = __key_value_iterator; + +public: + // types + using key_type = _Key; + using mapped_type = _Tp; + using value_type = pair; + using key_compare = __type_identity_t<_Compare>; + using reference = pair; + using const_reference = pair; + using size_type = size_t; + using difference_type = ptrdiff_t; + using iterator = __iterator; // see [container.requirements] + using const_iterator = __iterator; // see [container.requirements] + using reverse_iterator = std::reverse_iterator; + using const_reverse_iterator = std::reverse_iterator; + using key_container_type = _KeyContainer; + using mapped_container_type = _MappedContainer; + + class value_compare { + private: + key_compare __comp_; + _LIBCPP_HIDE_FROM_ABI value_compare(key_compare __c) : __comp_(__c) {} + friend flat_map; + + public: + _LIBCPP_HIDE_FROM_ABI bool operator()(const_reference __x, const_reference __y) const { + return __comp_(__x.first, __y.first); + } + }; + + struct containers { + key_container_type keys; + mapped_container_type values; + }; + +private: + template + _LIBCPP_HIDE_FROM_ABI static constexpr bool __allocator_ctor_constraint = + _And, uses_allocator>::value; + + _LIBCPP_HIDE_FROM_ABI static constexpr bool __is_compare_transparent = __is_transparent_v<_Compare>; + +public: + // [flat.map.cons], construct/copy/destroy + _LIBCPP_HIDE_FROM_ABI flat_map() noexcept( + is_nothrow_default_constructible_v<_KeyContainer> && is_nothrow_default_constructible_v<_MappedContainer> && + is_nothrow_default_constructible_v<_Compare>) + : __containers_(), __compare_() {} + + _LIBCPP_HIDE_FROM_ABI flat_map(const flat_map&) = default; + + _LIBCPP_HIDE_FROM_ABI flat_map(flat_map&& __other) noexcept( + is_nothrow_move_constructible_v<_KeyContainer> && is_nothrow_move_constructible_v<_MappedContainer> && + is_nothrow_move_constructible_v<_Compare>) +# if _LIBCPP_HAS_EXCEPTIONS + try +# endif // _LIBCPP_HAS_EXCEPTIONS + : __containers_(std::move(__other.__containers_)), __compare_(std::move(__other.__compare_)) { + __other.clear(); +# if _LIBCPP_HAS_EXCEPTIONS + } catch (...) { + __other.clear(); + // gcc does not like the `throw` keyword in a conditionally noexcept function + if constexpr (!(is_nothrow_move_constructible_v<_KeyContainer> && + is_nothrow_move_constructible_v<_MappedContainer> && is_nothrow_move_constructible_v<_Compare>)) { + throw; + } +# endif // _LIBCPP_HAS_EXCEPTIONS + } + + template + requires __allocator_ctor_constraint<_Allocator> + _LIBCPP_HIDE_FROM_ABI flat_map(const flat_map& __other, const _Allocator& __alloc) + : flat_map(__ctor_uses_allocator_tag{}, + __alloc, + __other.__containers_.keys, + __other.__containers_.values, + __other.__compare_) {} + + template + requires __allocator_ctor_constraint<_Allocator> + _LIBCPP_HIDE_FROM_ABI flat_map(flat_map&& __other, const _Allocator& __alloc) +# if _LIBCPP_HAS_EXCEPTIONS + try +# endif // _LIBCPP_HAS_EXCEPTIONS + : flat_map(__ctor_uses_allocator_tag{}, + __alloc, + std::move(__other.__containers_.keys), + std::move(__other.__containers_.values), + std::move(__other.__compare_)) { + __other.clear(); +# if _LIBCPP_HAS_EXCEPTIONS + } catch (...) { + __other.clear(); + throw; +# endif // _LIBCPP_HAS_EXCEPTIONS + } + + _LIBCPP_HIDE_FROM_ABI flat_map( + key_container_type __key_cont, mapped_container_type __mapped_cont, const key_compare& __comp = key_compare()) + : __containers_{.keys = std::move(__key_cont), .values = std::move(__mapped_cont)}, __compare_(__comp) { + _LIBCPP_ASSERT_VALID_INPUT_RANGE(__containers_.keys.size() == __containers_.values.size(), + "flat_map keys and mapped containers have different size"); + __sort_and_unique(); + } + + template + requires __allocator_ctor_constraint<_Allocator> + _LIBCPP_HIDE_FROM_ABI + flat_map(const key_container_type& __key_cont, const mapped_container_type& __mapped_cont, const _Allocator& __alloc) + : flat_map(__ctor_uses_allocator_tag{}, __alloc, __key_cont, __mapped_cont) { + _LIBCPP_ASSERT_VALID_INPUT_RANGE(__containers_.keys.size() == __containers_.values.size(), + "flat_map keys and mapped containers have different size"); + __sort_and_unique(); + } + + template + requires __allocator_ctor_constraint<_Allocator> + _LIBCPP_HIDE_FROM_ABI + flat_map(const key_container_type& __key_cont, + const mapped_container_type& __mapped_cont, + const key_compare& __comp, + const _Allocator& __alloc) + : flat_map(__ctor_uses_allocator_tag{}, __alloc, __key_cont, __mapped_cont, __comp) { + _LIBCPP_ASSERT_VALID_INPUT_RANGE(__containers_.keys.size() == __containers_.values.size(), + "flat_map keys and mapped containers have different size"); + __sort_and_unique(); + } + + _LIBCPP_HIDE_FROM_ABI + flat_map(sorted_unique_t, + key_container_type __key_cont, + mapped_container_type __mapped_cont, + const key_compare& __comp = key_compare()) + : __containers_{.keys = std::move(__key_cont), .values = std::move(__mapped_cont)}, __compare_(__comp) { + _LIBCPP_ASSERT_VALID_INPUT_RANGE(__containers_.keys.size() == __containers_.values.size(), + "flat_map keys and mapped containers have different size"); + _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT( + __is_sorted_and_unique(__containers_.keys), "Either the key container is not sorted or it contains duplicates"); + } + + template + requires __allocator_ctor_constraint<_Allocator> + _LIBCPP_HIDE_FROM_ABI + flat_map(sorted_unique_t, + const key_container_type& __key_cont, + const mapped_container_type& __mapped_cont, + const _Allocator& __alloc) + : flat_map(__ctor_uses_allocator_tag{}, __alloc, __key_cont, __mapped_cont) { + _LIBCPP_ASSERT_VALID_INPUT_RANGE(__containers_.keys.size() == __containers_.values.size(), + "flat_map keys and mapped containers have different size"); + _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT( + __is_sorted_and_unique(__containers_.keys), "Either the key container is not sorted or it contains duplicates"); + } + + template + requires __allocator_ctor_constraint<_Allocator> + _LIBCPP_HIDE_FROM_ABI + flat_map(sorted_unique_t, + const key_container_type& __key_cont, + const mapped_container_type& __mapped_cont, + const key_compare& __comp, + const _Allocator& __alloc) + : flat_map(__ctor_uses_allocator_tag{}, __alloc, __key_cont, __mapped_cont, __comp) { + _LIBCPP_ASSERT_VALID_INPUT_RANGE(__containers_.keys.size() == __containers_.values.size(), + "flat_map keys and mapped containers have different size"); + _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT( + __is_sorted_and_unique(__containers_.keys), "Either the key container is not sorted or it contains duplicates"); + } + + _LIBCPP_HIDE_FROM_ABI explicit flat_map(const key_compare& __comp) : __containers_(), __compare_(__comp) {} + + template + requires __allocator_ctor_constraint<_Allocator> + _LIBCPP_HIDE_FROM_ABI flat_map(const key_compare& __comp, const _Allocator& __alloc) + : flat_map(__ctor_uses_allocator_empty_tag{}, __alloc, __comp) {} + + template + requires __allocator_ctor_constraint<_Allocator> + _LIBCPP_HIDE_FROM_ABI explicit flat_map(const _Allocator& __alloc) + : flat_map(__ctor_uses_allocator_empty_tag{}, __alloc) {} + + template + requires __has_input_iterator_category<_InputIterator>::value + _LIBCPP_HIDE_FROM_ABI + flat_map(_InputIterator __first, _InputIterator __last, const key_compare& __comp = key_compare()) + : __containers_(), __compare_(__comp) { + insert(__first, __last); + } + + template + requires(__has_input_iterator_category<_InputIterator>::value && __allocator_ctor_constraint<_Allocator>) + _LIBCPP_HIDE_FROM_ABI + flat_map(_InputIterator __first, _InputIterator __last, const key_compare& __comp, const _Allocator& __alloc) + : flat_map(__ctor_uses_allocator_empty_tag{}, __alloc, __comp) { + insert(__first, __last); + } + + template + requires(__has_input_iterator_category<_InputIterator>::value && __allocator_ctor_constraint<_Allocator>) + _LIBCPP_HIDE_FROM_ABI flat_map(_InputIterator __first, _InputIterator __last, const _Allocator& __alloc) + : flat_map(__ctor_uses_allocator_empty_tag{}, __alloc) { + insert(__first, __last); + } + + template <_ContainerCompatibleRange _Range> + _LIBCPP_HIDE_FROM_ABI flat_map(from_range_t __fr, _Range&& __rg) + : flat_map(__fr, std::forward<_Range>(__rg), key_compare()) {} + + template <_ContainerCompatibleRange _Range, class _Allocator> + requires __allocator_ctor_constraint<_Allocator> + _LIBCPP_HIDE_FROM_ABI flat_map(from_range_t, _Range&& __rg, const _Allocator& __alloc) + : flat_map(__ctor_uses_allocator_empty_tag{}, __alloc) { + insert_range(std::forward<_Range>(__rg)); + } + + template <_ContainerCompatibleRange _Range> + _LIBCPP_HIDE_FROM_ABI flat_map(from_range_t, _Range&& __rg, const key_compare& __comp) : flat_map(__comp) { + insert_range(std::forward<_Range>(__rg)); + } + + template <_ContainerCompatibleRange _Range, class _Allocator> + requires __allocator_ctor_constraint<_Allocator> + _LIBCPP_HIDE_FROM_ABI flat_map(from_range_t, _Range&& __rg, const key_compare& __comp, const _Allocator& __alloc) + : flat_map(__ctor_uses_allocator_empty_tag{}, __alloc, __comp) { + insert_range(std::forward<_Range>(__rg)); + } + + template + requires __has_input_iterator_category<_InputIterator>::value + _LIBCPP_HIDE_FROM_ABI + flat_map(sorted_unique_t, _InputIterator __first, _InputIterator __last, const key_compare& __comp = key_compare()) + : __containers_(), __compare_(__comp) { + insert(sorted_unique, __first, __last); + } + template + requires(__has_input_iterator_category<_InputIterator>::value && __allocator_ctor_constraint<_Allocator>) + _LIBCPP_HIDE_FROM_ABI + flat_map(sorted_unique_t, + _InputIterator __first, + _InputIterator __last, + const key_compare& __comp, + const _Allocator& __alloc) + : flat_map(__ctor_uses_allocator_empty_tag{}, __alloc, __comp) { + insert(sorted_unique, __first, __last); + } + + template + requires(__has_input_iterator_category<_InputIterator>::value && __allocator_ctor_constraint<_Allocator>) + _LIBCPP_HIDE_FROM_ABI + flat_map(sorted_unique_t, _InputIterator __first, _InputIterator __last, const _Allocator& __alloc) + : flat_map(__ctor_uses_allocator_empty_tag{}, __alloc) { + insert(sorted_unique, __first, __last); + } + + _LIBCPP_HIDE_FROM_ABI flat_map(initializer_list __il, const key_compare& __comp = key_compare()) + : flat_map(__il.begin(), __il.end(), __comp) {} + + template + requires __allocator_ctor_constraint<_Allocator> + _LIBCPP_HIDE_FROM_ABI + flat_map(initializer_list __il, const key_compare& __comp, const _Allocator& __alloc) + : flat_map(__il.begin(), __il.end(), __comp, __alloc) {} + + template + requires __allocator_ctor_constraint<_Allocator> + _LIBCPP_HIDE_FROM_ABI flat_map(initializer_list __il, const _Allocator& __alloc) + : flat_map(__il.begin(), __il.end(), __alloc) {} + + _LIBCPP_HIDE_FROM_ABI + flat_map(sorted_unique_t, initializer_list __il, const key_compare& __comp = key_compare()) + : flat_map(sorted_unique, __il.begin(), __il.end(), __comp) {} + + template + requires __allocator_ctor_constraint<_Allocator> + _LIBCPP_HIDE_FROM_ABI + flat_map(sorted_unique_t, initializer_list __il, const key_compare& __comp, const _Allocator& __alloc) + : flat_map(sorted_unique, __il.begin(), __il.end(), __comp, __alloc) {} + + template + requires __allocator_ctor_constraint<_Allocator> + _LIBCPP_HIDE_FROM_ABI flat_map(sorted_unique_t, initializer_list __il, const _Allocator& __alloc) + : flat_map(sorted_unique, __il.begin(), __il.end(), __alloc) {} + + _LIBCPP_HIDE_FROM_ABI flat_map& operator=(initializer_list __il) { + clear(); + insert(__il); + return *this; + } + + _LIBCPP_HIDE_FROM_ABI flat_map& operator=(const flat_map&) = default; + + _LIBCPP_HIDE_FROM_ABI flat_map& operator=(flat_map&& __other) noexcept( + is_nothrow_move_assignable_v<_KeyContainer> && is_nothrow_move_assignable_v<_MappedContainer> && + is_nothrow_move_assignable_v<_Compare>) { + // No matter what happens, we always want to clear the other container before returning + // since we moved from it + auto __clear_other_guard = std::__make_scope_guard([&]() noexcept { __other.clear() /* noexcept */; }); + { + // If an exception is thrown, we have no choice but to clear *this to preserve invariants + auto __on_exception = std::__make_exception_guard([&]() noexcept { clear() /* noexcept */; }); + __containers_ = std::move(__other.__containers_); + __compare_ = std::move(__other.__compare_); + __on_exception.__complete(); + } + return *this; + } + + // iterators + _LIBCPP_HIDE_FROM_ABI iterator begin() noexcept { + return iterator(__containers_.keys.begin(), __containers_.values.begin()); + } + + _LIBCPP_HIDE_FROM_ABI const_iterator begin() const noexcept { + return const_iterator(__containers_.keys.begin(), __containers_.values.begin()); + } + + _LIBCPP_HIDE_FROM_ABI iterator end() noexcept { + return iterator(__containers_.keys.end(), __containers_.values.end()); + } + + _LIBCPP_HIDE_FROM_ABI const_iterator end() const noexcept { + return const_iterator(__containers_.keys.end(), __containers_.values.end()); + } + + _LIBCPP_HIDE_FROM_ABI reverse_iterator rbegin() noexcept { return reverse_iterator(end()); } + _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rbegin() const noexcept { return const_reverse_iterator(end()); } + _LIBCPP_HIDE_FROM_ABI reverse_iterator rend() noexcept { return reverse_iterator(begin()); } + _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rend() const noexcept { return const_reverse_iterator(begin()); } + + _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const noexcept { return begin(); } + _LIBCPP_HIDE_FROM_ABI const_iterator cend() const noexcept { return end(); } + _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(end()); } + _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crend() const noexcept { return const_reverse_iterator(begin()); } + + // [flat.map.capacity], capacity + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI bool empty() const noexcept { return __containers_.keys.empty(); } + + _LIBCPP_HIDE_FROM_ABI size_type size() const noexcept { return __containers_.keys.size(); } + + _LIBCPP_HIDE_FROM_ABI size_type max_size() const noexcept { + return std::min(__containers_.keys.max_size(), __containers_.values.max_size()); + } + + // [flat.map.access], element access + _LIBCPP_HIDE_FROM_ABI mapped_type& operator[](const key_type& __x) + requires is_constructible_v + { + return try_emplace(__x).first->second; + } + + _LIBCPP_HIDE_FROM_ABI mapped_type& operator[](key_type&& __x) + requires is_constructible_v + { + return try_emplace(std::move(__x)).first->second; + } + + template + requires(__is_compare_transparent && is_constructible_v && is_constructible_v && + !is_convertible_v<_Kp &&, const_iterator> && !is_convertible_v<_Kp &&, iterator>) + _LIBCPP_HIDE_FROM_ABI mapped_type& operator[](_Kp&& __x) { + return try_emplace(std::forward<_Kp>(__x)).first->second; + } + + _LIBCPP_HIDE_FROM_ABI mapped_type& at(const key_type& __x) { + auto __it = find(__x); + if (__it == end()) { + std::__throw_out_of_range("flat_map::at(const key_type&): Key does not exist"); + } + return __it->second; + } + + _LIBCPP_HIDE_FROM_ABI const mapped_type& at(const key_type& __x) const { + auto __it = find(__x); + if (__it == end()) { + std::__throw_out_of_range("flat_map::at(const key_type&) const: Key does not exist"); + } + return __it->second; + } + + template + requires __is_compare_transparent + _LIBCPP_HIDE_FROM_ABI mapped_type& at(const _Kp& __x) { + auto __it = find(__x); + if (__it == end()) { + std::__throw_out_of_range("flat_map::at(const K&): Key does not exist"); + } + return __it->second; + } + + template + requires __is_compare_transparent + _LIBCPP_HIDE_FROM_ABI const mapped_type& at(const _Kp& __x) const { + auto __it = find(__x); + if (__it == end()) { + std::__throw_out_of_range("flat_map::at(const K&) const: Key does not exist"); + } + return __it->second; + } + + // [flat.map.modifiers], modifiers + template + requires is_constructible_v, _Args...> + _LIBCPP_HIDE_FROM_ABI pair emplace(_Args&&... __args) { + std::pair __pair(std::forward<_Args>(__args)...); + return __try_emplace(std::move(__pair.first), std::move(__pair.second)); + } + + template + requires is_constructible_v, _Args...> + _LIBCPP_HIDE_FROM_ABI iterator emplace_hint(const_iterator __hint, _Args&&... __args) { + std::pair __pair(std::forward<_Args>(__args)...); + return __try_emplace_hint(__hint, std::move(__pair.first), std::move(__pair.second)).first; + } + + _LIBCPP_HIDE_FROM_ABI pair insert(const value_type& __x) { return emplace(__x); } + + _LIBCPP_HIDE_FROM_ABI pair insert(value_type&& __x) { return emplace(std::move(__x)); } + + _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __hint, const value_type& __x) { + return emplace_hint(__hint, __x); + } + + _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __hint, value_type&& __x) { + return emplace_hint(__hint, std::move(__x)); + } + + template + requires is_constructible_v, _PairLike> + _LIBCPP_HIDE_FROM_ABI pair insert(_PairLike&& __x) { + return emplace(std::forward<_PairLike>(__x)); + } + + template + requires is_constructible_v, _PairLike> + _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __hint, _PairLike&& __x) { + return emplace_hint(__hint, std::forward<_PairLike>(__x)); + } + + template + requires __has_input_iterator_category<_InputIterator>::value + _LIBCPP_HIDE_FROM_ABI void insert(_InputIterator __first, _InputIterator __last) { + if constexpr (sized_sentinel_for<_InputIterator, _InputIterator>) { + __reserve(__last - __first); + } + __append_sort_merge_unique(std::move(__first), std::move(__last)); + } + + template + requires __has_input_iterator_category<_InputIterator>::value + _LIBCPP_HIDE_FROM_ABI void insert(sorted_unique_t, _InputIterator __first, _InputIterator __last) { + if constexpr (sized_sentinel_for<_InputIterator, _InputIterator>) { + __reserve(__last - __first); + } + + __append_sort_merge_unique(std::move(__first), std::move(__last)); + } + + template <_ContainerCompatibleRange _Range> + _LIBCPP_HIDE_FROM_ABI void insert_range(_Range&& __range) { + if constexpr (ranges::sized_range<_Range>) { + __reserve(ranges::size(__range)); + } + + __append_sort_merge_unique(ranges::begin(__range), ranges::end(__range)); + } + + _LIBCPP_HIDE_FROM_ABI void insert(initializer_list __il) { insert(__il.begin(), __il.end()); } + + _LIBCPP_HIDE_FROM_ABI void insert(sorted_unique_t, initializer_list __il) { + insert(sorted_unique, __il.begin(), __il.end()); + } + + _LIBCPP_HIDE_FROM_ABI containers extract() && { + auto __guard = std::__make_scope_guard([&]() noexcept { clear() /* noexcept */; }); + auto __ret = std::move(__containers_); + return __ret; + } + + _LIBCPP_HIDE_FROM_ABI void replace(key_container_type&& __key_cont, mapped_container_type&& __mapped_cont) { + _LIBCPP_ASSERT_VALID_INPUT_RANGE( + __key_cont.size() == __mapped_cont.size(), "flat_map keys and mapped containers have different size"); + + _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT( + __is_sorted_and_unique(__key_cont), "Either the key container is not sorted or it contains duplicates"); + auto __guard = std::__make_exception_guard([&]() noexcept { clear() /* noexcept */; }); + __containers_.keys = std::move(__key_cont); + __containers_.values = std::move(__mapped_cont); + __guard.__complete(); + } + + template + requires is_constructible_v + _LIBCPP_HIDE_FROM_ABI pair try_emplace(const key_type& __key, _Args&&... __args) { + return __try_emplace(__key, std::forward<_Args>(__args)...); + } + + template + requires is_constructible_v + _LIBCPP_HIDE_FROM_ABI pair try_emplace(key_type&& __key, _Args&&... __args) { + return __try_emplace(std::move(__key), std::forward<_Args>(__args)...); + } + + template + requires(__is_compare_transparent && is_constructible_v && + is_constructible_v && !is_convertible_v<_Kp &&, const_iterator> && + !is_convertible_v<_Kp &&, iterator>) + _LIBCPP_HIDE_FROM_ABI pair try_emplace(_Kp&& __key, _Args&&... __args) { + return __try_emplace(std::forward<_Kp>(__key), std::forward<_Args>(__args)...); + } + + template + requires is_constructible_v + _LIBCPP_HIDE_FROM_ABI iterator try_emplace(const_iterator __hint, const key_type& __key, _Args&&... __args) { + return __try_emplace_hint(__hint, __key, std::forward<_Args>(__args)...).first; + } + + template + requires is_constructible_v + _LIBCPP_HIDE_FROM_ABI iterator try_emplace(const_iterator __hint, key_type&& __key, _Args&&... __args) { + return __try_emplace_hint(__hint, std::move(__key), std::forward<_Args>(__args)...).first; + } + + template + requires __is_compare_transparent && is_constructible_v && is_constructible_v + _LIBCPP_HIDE_FROM_ABI iterator try_emplace(const_iterator __hint, _Kp&& __key, _Args&&... __args) { + return __try_emplace_hint(__hint, std::forward<_Kp>(__key), std::forward<_Args>(__args)...).first; + } + + template + requires is_assignable_v && is_constructible_v + _LIBCPP_HIDE_FROM_ABI pair insert_or_assign(const key_type& __key, _Mapped&& __obj) { + return __insert_or_assign(__key, std::forward<_Mapped>(__obj)); + } + + template + requires is_assignable_v && is_constructible_v + _LIBCPP_HIDE_FROM_ABI pair insert_or_assign(key_type&& __key, _Mapped&& __obj) { + return __insert_or_assign(std::move(__key), std::forward<_Mapped>(__obj)); + } + + template + requires __is_compare_transparent && is_constructible_v && is_assignable_v && + is_constructible_v + _LIBCPP_HIDE_FROM_ABI pair insert_or_assign(_Kp&& __key, _Mapped&& __obj) { + return __insert_or_assign(std::forward<_Kp>(__key), std::forward<_Mapped>(__obj)); + } + + template + requires is_assignable_v && is_constructible_v + _LIBCPP_HIDE_FROM_ABI iterator insert_or_assign(const_iterator __hint, const key_type& __key, _Mapped&& __obj) { + return __insert_or_assign(__hint, __key, std::forward<_Mapped>(__obj)); + } + + template + requires is_assignable_v && is_constructible_v + _LIBCPP_HIDE_FROM_ABI iterator insert_or_assign(const_iterator __hint, key_type&& __key, _Mapped&& __obj) { + return __insert_or_assign(__hint, std::move(__key), std::forward<_Mapped>(__obj)); + } + + template + requires __is_compare_transparent && is_constructible_v && is_assignable_v && + is_constructible_v + _LIBCPP_HIDE_FROM_ABI iterator insert_or_assign(const_iterator __hint, _Kp&& __key, _Mapped&& __obj) { + return __insert_or_assign(__hint, std::forward<_Kp>(__key), std::forward<_Mapped>(__obj)); + } + + _LIBCPP_HIDE_FROM_ABI iterator erase(iterator __position) { + return __erase(__position.__key_iter_, __position.__mapped_iter_); + } + + _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __position) { + return __erase(__position.__key_iter_, __position.__mapped_iter_); + } + + _LIBCPP_HIDE_FROM_ABI size_type erase(const key_type& __x) { + auto __iter = find(__x); + if (__iter != end()) { + erase(__iter); + return 1; + } + return 0; + } + + template + requires(__is_compare_transparent && !is_convertible_v<_Kp &&, iterator> && + !is_convertible_v<_Kp &&, const_iterator>) + _LIBCPP_HIDE_FROM_ABI size_type erase(_Kp&& __x) { + auto [__first, __last] = equal_range(__x); + auto __res = __last - __first; + erase(__first, __last); + return __res; + } + + _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __first, const_iterator __last) { + auto __on_failure = std::__make_exception_guard([&]() noexcept { clear() /* noexcept */; }); + auto __key_it = __containers_.keys.erase(__first.__key_iter_, __last.__key_iter_); + auto __mapped_it = __containers_.values.erase(__first.__mapped_iter_, __last.__mapped_iter_); + __on_failure.__complete(); + return iterator(std::move(__key_it), std::move(__mapped_it)); + } + + _LIBCPP_HIDE_FROM_ABI void swap(flat_map& __y) noexcept { + // warning: The spec has unconditional noexcept, which means that + // if any of the following functions throw an exception, + // std::terminate will be called. + // This is discussed in P2767, which hasn't been voted on yet. + ranges::swap(__compare_, __y.__compare_); + ranges::swap(__containers_.keys, __y.__containers_.keys); + ranges::swap(__containers_.values, __y.__containers_.values); + } + + _LIBCPP_HIDE_FROM_ABI void clear() noexcept { + __containers_.keys.clear(); + __containers_.values.clear(); + } + + // observers + _LIBCPP_HIDE_FROM_ABI key_compare key_comp() const { return __compare_; } + _LIBCPP_HIDE_FROM_ABI value_compare value_comp() const { return value_compare(__compare_); } + + _LIBCPP_HIDE_FROM_ABI const key_container_type& keys() const noexcept { return __containers_.keys; } + _LIBCPP_HIDE_FROM_ABI const mapped_container_type& values() const noexcept { return __containers_.values; } + + // map operations + _LIBCPP_HIDE_FROM_ABI iterator find(const key_type& __x) { return __find_impl(*this, __x); } + + _LIBCPP_HIDE_FROM_ABI const_iterator find(const key_type& __x) const { return __find_impl(*this, __x); } + + template + requires __is_compare_transparent + _LIBCPP_HIDE_FROM_ABI iterator find(const _Kp& __x) { + return __find_impl(*this, __x); + } + + template + requires __is_compare_transparent + _LIBCPP_HIDE_FROM_ABI const_iterator find(const _Kp& __x) const { + return __find_impl(*this, __x); + } + + _LIBCPP_HIDE_FROM_ABI size_type count(const key_type& __x) const { return contains(__x) ? 1 : 0; } + + template + requires __is_compare_transparent + _LIBCPP_HIDE_FROM_ABI size_type count(const _Kp& __x) const { + return contains(__x) ? 1 : 0; + } + + _LIBCPP_HIDE_FROM_ABI bool contains(const key_type& __x) const { return find(__x) != end(); } + + template + requires __is_compare_transparent + _LIBCPP_HIDE_FROM_ABI bool contains(const _Kp& __x) const { + return find(__x) != end(); + } + + _LIBCPP_HIDE_FROM_ABI iterator lower_bound(const key_type& __x) { return __lower_bound(*this, __x); } + + _LIBCPP_HIDE_FROM_ABI const_iterator lower_bound(const key_type& __x) const { + return __lower_bound(*this, __x); + } + + template + requires __is_compare_transparent + _LIBCPP_HIDE_FROM_ABI iterator lower_bound(const _Kp& __x) { + return __lower_bound(*this, __x); + } + + template + requires __is_compare_transparent + _LIBCPP_HIDE_FROM_ABI const_iterator lower_bound(const _Kp& __x) const { + return __lower_bound(*this, __x); + } + + _LIBCPP_HIDE_FROM_ABI iterator upper_bound(const key_type& __x) { return __upper_bound(*this, __x); } + + _LIBCPP_HIDE_FROM_ABI const_iterator upper_bound(const key_type& __x) const { + return __upper_bound(*this, __x); + } + + template + requires __is_compare_transparent + _LIBCPP_HIDE_FROM_ABI iterator upper_bound(const _Kp& __x) { + return __upper_bound(*this, __x); + } + + template + requires __is_compare_transparent + _LIBCPP_HIDE_FROM_ABI const_iterator upper_bound(const _Kp& __x) const { + return __upper_bound(*this, __x); + } + + _LIBCPP_HIDE_FROM_ABI pair equal_range(const key_type& __x) { + return __equal_range_impl(*this, __x); + } + + _LIBCPP_HIDE_FROM_ABI pair equal_range(const key_type& __x) const { + return __equal_range_impl(*this, __x); + } + + template + requires __is_compare_transparent + _LIBCPP_HIDE_FROM_ABI pair equal_range(const _Kp& __x) { + return __equal_range_impl(*this, __x); + } + template + requires __is_compare_transparent + _LIBCPP_HIDE_FROM_ABI pair equal_range(const _Kp& __x) const { + return __equal_range_impl(*this, __x); + } + + friend _LIBCPP_HIDE_FROM_ABI bool operator==(const flat_map& __x, const flat_map& __y) { + return ranges::equal(__x, __y); + } + + friend _LIBCPP_HIDE_FROM_ABI auto operator<=>(const flat_map& __x, const flat_map& __y) { + return std::lexicographical_compare_three_way( + __x.begin(), __x.end(), __y.begin(), __y.end(), std::__synth_three_way); + } + + friend _LIBCPP_HIDE_FROM_ABI void swap(flat_map& __x, flat_map& __y) noexcept { __x.swap(__y); } + +private: + struct __ctor_uses_allocator_tag { + explicit _LIBCPP_HIDE_FROM_ABI __ctor_uses_allocator_tag() = default; + }; + struct __ctor_uses_allocator_empty_tag { + explicit _LIBCPP_HIDE_FROM_ABI __ctor_uses_allocator_empty_tag() = default; + }; + + template + requires __allocator_ctor_constraint<_Allocator> + _LIBCPP_HIDE_FROM_ABI + flat_map(__ctor_uses_allocator_tag, + const _Allocator& __alloc, + _KeyCont&& __key_cont, + _MappedCont&& __mapped_cont, + _CompArg&&... __comp) + : __containers_{.keys = std::make_obj_using_allocator( + __alloc, std::forward<_KeyCont>(__key_cont)), + .values = std::make_obj_using_allocator( + __alloc, std::forward<_MappedCont>(__mapped_cont))}, + __compare_(std::forward<_CompArg>(__comp)...) {} + + template + requires __allocator_ctor_constraint<_Allocator> + _LIBCPP_HIDE_FROM_ABI flat_map(__ctor_uses_allocator_empty_tag, const _Allocator& __alloc, _CompArg&&... __comp) + : __containers_{.keys = std::make_obj_using_allocator(__alloc), + .values = std::make_obj_using_allocator(__alloc)}, + __compare_(std::forward<_CompArg>(__comp)...) {} + + _LIBCPP_HIDE_FROM_ABI bool __is_sorted_and_unique(auto&& __key_container) const { + auto __greater_or_equal_to = [this](const auto& __x, const auto& __y) { return !__compare_(__x, __y); }; + return ranges::adjacent_find(__key_container, __greater_or_equal_to) == ranges::end(__key_container); + } + + // This function is only used in constructors. So there is not exception handling in this function. + // If the function exits via an exception, there will be no flat_map object constructed, thus, there + // is no invariant state to preserve + _LIBCPP_HIDE_FROM_ABI void __sort_and_unique() { + auto __zv = ranges::views::zip(__containers_.keys, __containers_.values); + ranges::sort(__zv, __compare_, [](const auto& __p) -> decltype(auto) { return std::get<0>(__p); }); + auto __dup_start = ranges::unique(__zv, __key_equiv(__compare_)).begin(); + auto __dist = ranges::distance(__zv.begin(), __dup_start); + __containers_.keys.erase(__containers_.keys.begin() + __dist, __containers_.keys.end()); + __containers_.values.erase(__containers_.values.begin() + __dist, __containers_.values.end()); + } + + template + _LIBCPP_HIDE_FROM_ABI void __append_sort_merge_unique(_InputIterator __first, _Sentinel __last) { + auto __on_failure = std::__make_exception_guard([&]() noexcept { clear() /* noexcept */; }); + size_t __num_of_appended = __flat_map_utils::__append(*this, std::move(__first), std::move(__last)); + if (__num_of_appended != 0) { + auto __zv = ranges::views::zip(__containers_.keys, __containers_.values); + auto __append_start_offset = __containers_.keys.size() - __num_of_appended; + auto __end = __zv.end(); + auto __compare_key = [this](const auto& __p1, const auto& __p2) { + return __compare_(std::get<0>(__p1), std::get<0>(__p2)); + }; + if constexpr (!_WasSorted) { + ranges::sort(__zv.begin() + __append_start_offset, __end, __compare_key); + } else { + _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT( + __is_sorted_and_unique(__containers_.keys | ranges::views::drop(__append_start_offset)), + "Either the key container is not sorted or it contains duplicates"); + } + ranges::inplace_merge(__zv.begin(), __zv.begin() + __append_start_offset, __end, __compare_key); + + auto __dup_start = ranges::unique(__zv, __key_equiv(__compare_)).begin(); + auto __dist = ranges::distance(__zv.begin(), __dup_start); + __containers_.keys.erase(__containers_.keys.begin() + __dist, __containers_.keys.end()); + __containers_.values.erase(__containers_.values.begin() + __dist, __containers_.values.end()); + } + __on_failure.__complete(); + } + + template + _LIBCPP_HIDE_FROM_ABI static auto __find_impl(_Self&& __self, const _Kp& __key) { + auto __it = __self.lower_bound(__key); + auto __last = __self.end(); + if (__it == __last || __self.__compare_(__key, __it->first)) { + return __last; + } + return __it; + } + + template + _LIBCPP_HIDE_FROM_ABI static auto __key_equal_range(_Self&& __self, const _Kp& __key) { + auto __it = ranges::lower_bound(__self.__containers_.keys, __key, __self.__compare_); + auto __last = __self.__containers_.keys.end(); + if (__it == __last || __self.__compare_(__key, *__it)) { + return std::make_pair(__it, __it); + } + return std::make_pair(__it, std::next(__it)); + } + + template + _LIBCPP_HIDE_FROM_ABI static auto __equal_range_impl(_Self&& __self, const _Kp& __key) { + auto [__key_first, __key_last] = __key_equal_range(__self, __key); + + const auto __make_mapped_iter = [&](const auto& __key_iter) { + return __self.__containers_.values.begin() + + static_cast>( + ranges::distance(__self.__containers_.keys.begin(), __key_iter)); + }; + + using __iterator_type = ranges::iterator_t; + return std::make_pair(__iterator_type(__key_first, __make_mapped_iter(__key_first)), + __iterator_type(__key_last, __make_mapped_iter(__key_last))); + } + + template + _LIBCPP_HIDE_FROM_ABI static _Res __lower_bound(_Self&& __self, _Kp& __x) { + return __binary_search<_Res>(__self, ranges::lower_bound, __x); + } + + template + _LIBCPP_HIDE_FROM_ABI static _Res __upper_bound(_Self&& __self, _Kp& __x) { + return __binary_search<_Res>(__self, ranges::upper_bound, __x); + } + + template + _LIBCPP_HIDE_FROM_ABI static _Res __binary_search(_Self&& __self, _Fn __search_fn, _Kp& __x) { + auto __key_iter = __search_fn(__self.__containers_.keys, __x, __self.__compare_); + auto __mapped_iter = + __self.__containers_.values.begin() + + static_cast>( + ranges::distance(__self.__containers_.keys.begin(), __key_iter)); + + return _Res(std::move(__key_iter), std::move(__mapped_iter)); + } + + template + _LIBCPP_HIDE_FROM_ABI pair __try_emplace(_KeyArg&& __key, _MArgs&&... __mapped_args) { + auto __key_it = ranges::lower_bound(__containers_.keys, __key, __compare_); + auto __mapped_it = __containers_.values.begin() + ranges::distance(__containers_.keys.begin(), __key_it); + + if (__key_it == __containers_.keys.end() || __compare_(__key, *__key_it)) { + return pair( + __flat_map_utils::__emplace_exact_pos( + *this, + std::move(__key_it), + std::move(__mapped_it), + std::forward<_KeyArg>(__key), + std::forward<_MArgs>(__mapped_args)...), + true); + } else { + return pair(iterator(std::move(__key_it), std::move(__mapped_it)), false); + } + } + + template + _LIBCPP_HIDE_FROM_ABI bool __is_hint_correct(const_iterator __hint, _Kp&& __key) { + if (__hint != cbegin() && !__compare_((__hint - 1)->first, __key)) { + return false; + } + if (__hint != cend() && __compare_(__hint->first, __key)) { + return false; + } + return true; + } + + template + _LIBCPP_HIDE_FROM_ABI pair __try_emplace_hint(const_iterator __hint, _Kp&& __key, _Args&&... __args) { + if (__is_hint_correct(__hint, __key)) { + if (__hint == cend() || __compare_(__key, __hint->first)) { + return {__flat_map_utils::__emplace_exact_pos( + *this, + __hint.__key_iter_, + __hint.__mapped_iter_, + std::forward<_Kp>(__key), + std::forward<_Args>(__args)...), + true}; + } else { + // key equals + auto __dist = __hint - cbegin(); + return {iterator(__containers_.keys.begin() + __dist, __containers_.values.begin() + __dist), false}; + } + } else { + return __try_emplace(std::forward<_Kp>(__key), std::forward<_Args>(__args)...); + } + } + + template + _LIBCPP_HIDE_FROM_ABI pair __insert_or_assign(_Kp&& __key, _Mapped&& __mapped) { + auto __r = try_emplace(std::forward<_Kp>(__key), std::forward<_Mapped>(__mapped)); + if (!__r.second) { + __r.first->second = std::forward<_Mapped>(__mapped); + } + return __r; + } + + template + _LIBCPP_HIDE_FROM_ABI iterator __insert_or_assign(const_iterator __hint, _Kp&& __key, _Mapped&& __mapped) { + auto __r = __try_emplace_hint(__hint, std::forward<_Kp>(__key), std::forward<_Mapped>(__mapped)); + if (!__r.second) { + __r.first->second = std::forward<_Mapped>(__mapped); + } + return __r.first; + } + + _LIBCPP_HIDE_FROM_ABI void __reserve(size_t __size) { + if constexpr (requires { __containers_.keys.reserve(__size); }) { + __containers_.keys.reserve(__size); + } + + if constexpr (requires { __containers_.values.reserve(__size); }) { + __containers_.values.reserve(__size); + } + } + + template + _LIBCPP_HIDE_FROM_ABI iterator __erase(_KIter __key_iter_to_remove, _MIter __mapped_iter_to_remove) { + auto __on_failure = std::__make_exception_guard([&]() noexcept { clear() /* noexcept */; }); + auto __key_iter = __containers_.keys.erase(__key_iter_to_remove); + auto __mapped_iter = __containers_.values.erase(__mapped_iter_to_remove); + __on_failure.__complete(); + return iterator(std::move(__key_iter), std::move(__mapped_iter)); + } + + template + friend typename flat_map<_Key2, _Tp2, _Compare2, _KeyContainer2, _MappedContainer2>::size_type + erase_if(flat_map<_Key2, _Tp2, _Compare2, _KeyContainer2, _MappedContainer2>&, _Predicate); + + friend __flat_map_utils; + + containers __containers_; + _LIBCPP_NO_UNIQUE_ADDRESS key_compare __compare_; + + struct __key_equiv { + _LIBCPP_HIDE_FROM_ABI __key_equiv(key_compare __c) : __comp_(__c) {} + _LIBCPP_HIDE_FROM_ABI bool operator()(const_reference __x, const_reference __y) const { + return !__comp_(std::get<0>(__x), std::get<0>(__y)) && !__comp_(std::get<0>(__y), std::get<0>(__x)); + } + key_compare __comp_; + }; +}; + +template > + requires(!__is_allocator<_Compare>::value && !__is_allocator<_KeyContainer>::value && + !__is_allocator<_MappedContainer>::value && + is_invocable_v) +flat_map(_KeyContainer, _MappedContainer, _Compare = _Compare()) + -> flat_map; + +template + requires(uses_allocator_v<_KeyContainer, _Allocator> && uses_allocator_v<_MappedContainer, _Allocator> && + !__is_allocator<_KeyContainer>::value && !__is_allocator<_MappedContainer>::value) +flat_map(_KeyContainer, _MappedContainer, _Allocator) + -> flat_map, + _KeyContainer, + _MappedContainer>; + +template + requires(!__is_allocator<_Compare>::value && !__is_allocator<_KeyContainer>::value && + !__is_allocator<_MappedContainer>::value && uses_allocator_v<_KeyContainer, _Allocator> && + uses_allocator_v<_MappedContainer, _Allocator> && + is_invocable_v) +flat_map(_KeyContainer, _MappedContainer, _Compare, _Allocator) + -> flat_map; + +template > + requires(!__is_allocator<_Compare>::value && !__is_allocator<_KeyContainer>::value && + !__is_allocator<_MappedContainer>::value && + is_invocable_v) +flat_map(sorted_unique_t, _KeyContainer, _MappedContainer, _Compare = _Compare()) + -> flat_map; + +template + requires(uses_allocator_v<_KeyContainer, _Allocator> && uses_allocator_v<_MappedContainer, _Allocator> && + !__is_allocator<_KeyContainer>::value && !__is_allocator<_MappedContainer>::value) +flat_map(sorted_unique_t, _KeyContainer, _MappedContainer, _Allocator) + -> flat_map, + _KeyContainer, + _MappedContainer>; + +template + requires(!__is_allocator<_Compare>::value && !__is_allocator<_KeyContainer>::value && + !__is_allocator<_MappedContainer>::value && uses_allocator_v<_KeyContainer, _Allocator> && + uses_allocator_v<_MappedContainer, _Allocator> && + is_invocable_v) +flat_map(sorted_unique_t, _KeyContainer, _MappedContainer, _Compare, _Allocator) + -> flat_map; + +template >> + requires(__has_input_iterator_category<_InputIterator>::value && !__is_allocator<_Compare>::value) +flat_map(_InputIterator, _InputIterator, _Compare = _Compare()) + -> flat_map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Compare>; + +template >> + requires(__has_input_iterator_category<_InputIterator>::value && !__is_allocator<_Compare>::value) +flat_map(sorted_unique_t, _InputIterator, _InputIterator, _Compare = _Compare()) + -> flat_map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Compare>; + +template >, + class _Allocator = allocator, + class = __enable_if_t::value && __is_allocator<_Allocator>::value>> +flat_map(from_range_t, _Range&&, _Compare = _Compare(), _Allocator = _Allocator()) -> flat_map< + __range_key_type<_Range>, + __range_mapped_type<_Range>, + _Compare, + vector<__range_key_type<_Range>, __allocator_traits_rebind_t<_Allocator, __range_key_type<_Range>>>, + vector<__range_mapped_type<_Range>, __allocator_traits_rebind_t<_Allocator, __range_mapped_type<_Range>>>>; + +template ::value>> +flat_map(from_range_t, _Range&&, _Allocator) -> flat_map< + __range_key_type<_Range>, + __range_mapped_type<_Range>, + less<__range_key_type<_Range>>, + vector<__range_key_type<_Range>, __allocator_traits_rebind_t<_Allocator, __range_key_type<_Range>>>, + vector<__range_mapped_type<_Range>, __allocator_traits_rebind_t<_Allocator, __range_mapped_type<_Range>>>>; + +template > + requires(!__is_allocator<_Compare>::value) +flat_map(initializer_list>, _Compare = _Compare()) -> flat_map<_Key, _Tp, _Compare>; + +template > + requires(!__is_allocator<_Compare>::value) +flat_map(sorted_unique_t, initializer_list>, _Compare = _Compare()) -> flat_map<_Key, _Tp, _Compare>; + +template +struct uses_allocator, _Allocator> + : bool_constant && uses_allocator_v<_MappedContainer, _Allocator>> {}; + +template +_LIBCPP_HIDE_FROM_ABI typename flat_map<_Key, _Tp, _Compare, _KeyContainer, _MappedContainer>::size_type +erase_if(flat_map<_Key, _Tp, _Compare, _KeyContainer, _MappedContainer>& __flat_map, _Predicate __pred) { + auto __zv = ranges::views::zip(__flat_map.__containers_.keys, __flat_map.__containers_.values); + auto __first = __zv.begin(); + auto __last = __zv.end(); + auto __guard = std::__make_exception_guard([&] { __flat_map.clear(); }); + auto __it = std::remove_if(__first, __last, [&](auto&& __zipped) -> bool { + using _Ref = typename flat_map<_Key, _Tp, _Compare, _KeyContainer, _MappedContainer>::const_reference; + return __pred(_Ref(std::get<0>(__zipped), std::get<1>(__zipped))); + }); + auto __res = __last - __it; + auto __offset = __it - __first; + + const auto __erase_container = [&](auto& __cont) { __cont.erase(__cont.begin() + __offset, __cont.end()); }; + + __erase_container(__flat_map.__containers_.keys); + __erase_container(__flat_map.__containers_.values); + + __guard.__complete(); + return __res; +} + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_STD_VER >= 23 + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___FLAT_MAP_FLAT_MAP_H diff --git a/system/lib/libcxx/include/__flat_map/flat_multimap.h b/system/lib/libcxx/include/__flat_map/flat_multimap.h new file mode 100644 index 0000000000000..ea77fb5d79bd2 --- /dev/null +++ b/system/lib/libcxx/include/__flat_map/flat_multimap.h @@ -0,0 +1,1010 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___FLAT_MAP_FLAT_MULTIMAP_H +#define _LIBCPP___FLAT_MAP_FLAT_MULTIMAP_H + +#include <__algorithm/lexicographical_compare_three_way.h> +#include <__algorithm/min.h> +#include <__algorithm/ranges_equal.h> +#include <__algorithm/ranges_equal_range.h> +#include <__algorithm/ranges_inplace_merge.h> +#include <__algorithm/ranges_is_sorted.h> +#include <__algorithm/ranges_lower_bound.h> +#include <__algorithm/ranges_partition_point.h> +#include <__algorithm/ranges_sort.h> +#include <__algorithm/ranges_unique.h> +#include <__algorithm/ranges_upper_bound.h> +#include <__algorithm/remove_if.h> +#include <__assert> +#include <__compare/synth_three_way.h> +#include <__concepts/convertible_to.h> +#include <__concepts/swappable.h> +#include <__config> +#include <__cstddef/byte.h> +#include <__cstddef/ptrdiff_t.h> +#include <__flat_map/key_value_iterator.h> +#include <__flat_map/sorted_equivalent.h> +#include <__flat_map/utils.h> +#include <__functional/invoke.h> +#include <__functional/is_transparent.h> +#include <__functional/operations.h> +#include <__fwd/vector.h> +#include <__iterator/concepts.h> +#include <__iterator/distance.h> +#include <__iterator/iterator_traits.h> +#include <__iterator/ranges_iterator_traits.h> +#include <__iterator/reverse_iterator.h> +#include <__memory/allocator_traits.h> +#include <__memory/uses_allocator.h> +#include <__memory/uses_allocator_construction.h> +#include <__ranges/access.h> +#include <__ranges/concepts.h> +#include <__ranges/container_compatible_range.h> +#include <__ranges/drop_view.h> +#include <__ranges/from_range.h> +#include <__ranges/ref_view.h> +#include <__ranges/size.h> +#include <__ranges/subrange.h> +#include <__ranges/zip_view.h> +#include <__type_traits/conjunction.h> +#include <__type_traits/container_traits.h> +#include <__type_traits/invoke.h> +#include <__type_traits/is_allocator.h> +#include <__type_traits/is_nothrow_constructible.h> +#include <__type_traits/is_same.h> +#include <__type_traits/maybe_const.h> +#include <__utility/exception_guard.h> +#include <__utility/move.h> +#include <__utility/pair.h> +#include <__utility/scope_guard.h> +#include <__vector/vector.h> +#include +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +#if _LIBCPP_STD_VER >= 23 + +_LIBCPP_BEGIN_NAMESPACE_STD + +template , + class _KeyContainer = vector<_Key>, + class _MappedContainer = vector<_Tp>> +class flat_multimap { + template + friend class flat_multimap; + + static_assert(is_same_v<_Key, typename _KeyContainer::value_type>); + static_assert(is_same_v<_Tp, typename _MappedContainer::value_type>); + static_assert(!is_same_v<_KeyContainer, std::vector>, "vector is not a sequence container"); + static_assert(!is_same_v<_MappedContainer, std::vector>, "vector is not a sequence container"); + + template + using __iterator _LIBCPP_NODEBUG = __key_value_iterator; + +public: + // types + using key_type = _Key; + using mapped_type = _Tp; + using value_type = pair; + using key_compare = __type_identity_t<_Compare>; + using reference = pair; + using const_reference = pair; + using size_type = size_t; + using difference_type = ptrdiff_t; + using iterator = __iterator; // see [container.requirements] + using const_iterator = __iterator; // see [container.requirements] + using reverse_iterator = std::reverse_iterator; + using const_reverse_iterator = std::reverse_iterator; + using key_container_type = _KeyContainer; + using mapped_container_type = _MappedContainer; + + class value_compare { + private: + key_compare __comp_; + _LIBCPP_HIDE_FROM_ABI value_compare(key_compare __c) : __comp_(__c) {} + friend flat_multimap; + + public: + _LIBCPP_HIDE_FROM_ABI bool operator()(const_reference __x, const_reference __y) const { + return __comp_(__x.first, __y.first); + } + }; + + struct containers { + key_container_type keys; + mapped_container_type values; + }; + +private: + template + _LIBCPP_HIDE_FROM_ABI static constexpr bool __allocator_ctor_constraint = + _And, uses_allocator>::value; + + _LIBCPP_HIDE_FROM_ABI static constexpr bool __is_compare_transparent = __is_transparent_v<_Compare>; + +public: + // [flat.map.cons], construct/copy/destroy + _LIBCPP_HIDE_FROM_ABI flat_multimap() noexcept( + is_nothrow_default_constructible_v<_KeyContainer> && is_nothrow_default_constructible_v<_MappedContainer> && + is_nothrow_default_constructible_v<_Compare>) + : __containers_(), __compare_() {} + + _LIBCPP_HIDE_FROM_ABI flat_multimap(const flat_multimap&) = default; + + // The copy/move constructors are not specified in the spec, which means they should be defaulted. + // However, the move constructor can potentially leave a moved-from object in an inconsistent + // state if an exception is thrown. + _LIBCPP_HIDE_FROM_ABI flat_multimap(flat_multimap&& __other) noexcept( + is_nothrow_move_constructible_v<_KeyContainer> && is_nothrow_move_constructible_v<_MappedContainer> && + is_nothrow_move_constructible_v<_Compare>) +# if _LIBCPP_HAS_EXCEPTIONS + try +# endif // _LIBCPP_HAS_EXCEPTIONS + : __containers_(std::move(__other.__containers_)), __compare_(std::move(__other.__compare_)) { + __other.clear(); +# if _LIBCPP_HAS_EXCEPTIONS + } catch (...) { + __other.clear(); + // gcc does not like the `throw` keyword in a conditionally noexcept function + if constexpr (!(is_nothrow_move_constructible_v<_KeyContainer> && + is_nothrow_move_constructible_v<_MappedContainer> && is_nothrow_move_constructible_v<_Compare>)) { + throw; + } +# endif // _LIBCPP_HAS_EXCEPTIONS + } + + template + requires __allocator_ctor_constraint<_Allocator> + _LIBCPP_HIDE_FROM_ABI flat_multimap(const flat_multimap& __other, const _Allocator& __alloc) + : flat_multimap(__ctor_uses_allocator_tag{}, + __alloc, + __other.__containers_.keys, + __other.__containers_.values, + __other.__compare_) {} + + template + requires __allocator_ctor_constraint<_Allocator> + _LIBCPP_HIDE_FROM_ABI flat_multimap(flat_multimap&& __other, const _Allocator& __alloc) +# if _LIBCPP_HAS_EXCEPTIONS + try +# endif // _LIBCPP_HAS_EXCEPTIONS + : flat_multimap(__ctor_uses_allocator_tag{}, + __alloc, + std::move(__other.__containers_.keys), + std::move(__other.__containers_.values), + std::move(__other.__compare_)) { + __other.clear(); +# if _LIBCPP_HAS_EXCEPTIONS + } catch (...) { + __other.clear(); + throw; +# endif // _LIBCPP_HAS_EXCEPTIONS + } + + _LIBCPP_HIDE_FROM_ABI flat_multimap( + key_container_type __key_cont, mapped_container_type __mapped_cont, const key_compare& __comp = key_compare()) + : __containers_{.keys = std::move(__key_cont), .values = std::move(__mapped_cont)}, __compare_(__comp) { + _LIBCPP_ASSERT_VALID_INPUT_RANGE(__containers_.keys.size() == __containers_.values.size(), + "flat_multimap keys and mapped containers have different size"); + __sort(); + } + + template + requires __allocator_ctor_constraint<_Allocator> + _LIBCPP_HIDE_FROM_ABI flat_multimap( + const key_container_type& __key_cont, const mapped_container_type& __mapped_cont, const _Allocator& __alloc) + : flat_multimap(__ctor_uses_allocator_tag{}, __alloc, __key_cont, __mapped_cont) { + _LIBCPP_ASSERT_VALID_INPUT_RANGE(__containers_.keys.size() == __containers_.values.size(), + "flat_multimap keys and mapped containers have different size"); + __sort(); + } + + template + requires __allocator_ctor_constraint<_Allocator> + _LIBCPP_HIDE_FROM_ABI + flat_multimap(const key_container_type& __key_cont, + const mapped_container_type& __mapped_cont, + const key_compare& __comp, + const _Allocator& __alloc) + : flat_multimap(__ctor_uses_allocator_tag{}, __alloc, __key_cont, __mapped_cont, __comp) { + _LIBCPP_ASSERT_VALID_INPUT_RANGE(__containers_.keys.size() == __containers_.values.size(), + "flat_multimap keys and mapped containers have different size"); + __sort(); + } + + _LIBCPP_HIDE_FROM_ABI + flat_multimap(sorted_equivalent_t, + key_container_type __key_cont, + mapped_container_type __mapped_cont, + const key_compare& __comp = key_compare()) + : __containers_{.keys = std::move(__key_cont), .values = std::move(__mapped_cont)}, __compare_(__comp) { + _LIBCPP_ASSERT_VALID_INPUT_RANGE(__containers_.keys.size() == __containers_.values.size(), + "flat_multimap keys and mapped containers have different size"); + _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(__is_sorted(__containers_.keys), "Key container is not sorted"); + } + + template + requires __allocator_ctor_constraint<_Allocator> + _LIBCPP_HIDE_FROM_ABI + flat_multimap(sorted_equivalent_t, + const key_container_type& __key_cont, + const mapped_container_type& __mapped_cont, + const _Allocator& __alloc) + : flat_multimap(__ctor_uses_allocator_tag{}, __alloc, __key_cont, __mapped_cont) { + _LIBCPP_ASSERT_VALID_INPUT_RANGE(__containers_.keys.size() == __containers_.values.size(), + "flat_multimap keys and mapped containers have different size"); + _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(__is_sorted(__containers_.keys), "Key container is not sorted"); + } + + template + requires __allocator_ctor_constraint<_Allocator> + _LIBCPP_HIDE_FROM_ABI + flat_multimap(sorted_equivalent_t, + const key_container_type& __key_cont, + const mapped_container_type& __mapped_cont, + const key_compare& __comp, + const _Allocator& __alloc) + : flat_multimap(__ctor_uses_allocator_tag{}, __alloc, __key_cont, __mapped_cont, __comp) { + _LIBCPP_ASSERT_VALID_INPUT_RANGE(__containers_.keys.size() == __containers_.values.size(), + "flat_multimap keys and mapped containers have different size"); + _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(__is_sorted(__containers_.keys), "Key container is not sorted"); + } + + _LIBCPP_HIDE_FROM_ABI explicit flat_multimap(const key_compare& __comp) : __containers_(), __compare_(__comp) {} + + template + requires __allocator_ctor_constraint<_Allocator> + _LIBCPP_HIDE_FROM_ABI flat_multimap(const key_compare& __comp, const _Allocator& __alloc) + : flat_multimap(__ctor_uses_allocator_empty_tag{}, __alloc, __comp) {} + + template + requires __allocator_ctor_constraint<_Allocator> + _LIBCPP_HIDE_FROM_ABI explicit flat_multimap(const _Allocator& __alloc) + : flat_multimap(__ctor_uses_allocator_empty_tag{}, __alloc) {} + + template + requires __has_input_iterator_category<_InputIterator>::value + _LIBCPP_HIDE_FROM_ABI + flat_multimap(_InputIterator __first, _InputIterator __last, const key_compare& __comp = key_compare()) + : __containers_(), __compare_(__comp) { + insert(__first, __last); + } + + template + requires(__has_input_iterator_category<_InputIterator>::value && __allocator_ctor_constraint<_Allocator>) + _LIBCPP_HIDE_FROM_ABI + flat_multimap(_InputIterator __first, _InputIterator __last, const key_compare& __comp, const _Allocator& __alloc) + : flat_multimap(__ctor_uses_allocator_empty_tag{}, __alloc, __comp) { + insert(__first, __last); + } + + template + requires(__has_input_iterator_category<_InputIterator>::value && __allocator_ctor_constraint<_Allocator>) + _LIBCPP_HIDE_FROM_ABI flat_multimap(_InputIterator __first, _InputIterator __last, const _Allocator& __alloc) + : flat_multimap(__ctor_uses_allocator_empty_tag{}, __alloc) { + insert(__first, __last); + } + + template <_ContainerCompatibleRange _Range> + _LIBCPP_HIDE_FROM_ABI flat_multimap(from_range_t __fr, _Range&& __rg) + : flat_multimap(__fr, std::forward<_Range>(__rg), key_compare()) {} + + template <_ContainerCompatibleRange _Range, class _Allocator> + requires __allocator_ctor_constraint<_Allocator> + _LIBCPP_HIDE_FROM_ABI flat_multimap(from_range_t, _Range&& __rg, const _Allocator& __alloc) + : flat_multimap(__ctor_uses_allocator_empty_tag{}, __alloc) { + insert_range(std::forward<_Range>(__rg)); + } + + template <_ContainerCompatibleRange _Range> + _LIBCPP_HIDE_FROM_ABI flat_multimap(from_range_t, _Range&& __rg, const key_compare& __comp) : flat_multimap(__comp) { + insert_range(std::forward<_Range>(__rg)); + } + + template <_ContainerCompatibleRange _Range, class _Allocator> + requires __allocator_ctor_constraint<_Allocator> + _LIBCPP_HIDE_FROM_ABI flat_multimap(from_range_t, _Range&& __rg, const key_compare& __comp, const _Allocator& __alloc) + : flat_multimap(__ctor_uses_allocator_empty_tag{}, __alloc, __comp) { + insert_range(std::forward<_Range>(__rg)); + } + + template + requires __has_input_iterator_category<_InputIterator>::value + _LIBCPP_HIDE_FROM_ABI flat_multimap( + sorted_equivalent_t, _InputIterator __first, _InputIterator __last, const key_compare& __comp = key_compare()) + : __containers_(), __compare_(__comp) { + insert(sorted_equivalent, __first, __last); + } + template + requires(__has_input_iterator_category<_InputIterator>::value && __allocator_ctor_constraint<_Allocator>) + _LIBCPP_HIDE_FROM_ABI + flat_multimap(sorted_equivalent_t, + _InputIterator __first, + _InputIterator __last, + const key_compare& __comp, + const _Allocator& __alloc) + : flat_multimap(__ctor_uses_allocator_empty_tag{}, __alloc, __comp) { + insert(sorted_equivalent, __first, __last); + } + + template + requires(__has_input_iterator_category<_InputIterator>::value && __allocator_ctor_constraint<_Allocator>) + _LIBCPP_HIDE_FROM_ABI + flat_multimap(sorted_equivalent_t, _InputIterator __first, _InputIterator __last, const _Allocator& __alloc) + : flat_multimap(__ctor_uses_allocator_empty_tag{}, __alloc) { + insert(sorted_equivalent, __first, __last); + } + + _LIBCPP_HIDE_FROM_ABI flat_multimap(initializer_list __il, const key_compare& __comp = key_compare()) + : flat_multimap(__il.begin(), __il.end(), __comp) {} + + template + requires __allocator_ctor_constraint<_Allocator> + _LIBCPP_HIDE_FROM_ABI + flat_multimap(initializer_list __il, const key_compare& __comp, const _Allocator& __alloc) + : flat_multimap(__il.begin(), __il.end(), __comp, __alloc) {} + + template + requires __allocator_ctor_constraint<_Allocator> + _LIBCPP_HIDE_FROM_ABI flat_multimap(initializer_list __il, const _Allocator& __alloc) + : flat_multimap(__il.begin(), __il.end(), __alloc) {} + + _LIBCPP_HIDE_FROM_ABI + flat_multimap(sorted_equivalent_t, initializer_list __il, const key_compare& __comp = key_compare()) + : flat_multimap(sorted_equivalent, __il.begin(), __il.end(), __comp) {} + + template + requires __allocator_ctor_constraint<_Allocator> + _LIBCPP_HIDE_FROM_ABI flat_multimap( + sorted_equivalent_t, initializer_list __il, const key_compare& __comp, const _Allocator& __alloc) + : flat_multimap(sorted_equivalent, __il.begin(), __il.end(), __comp, __alloc) {} + + template + requires __allocator_ctor_constraint<_Allocator> + _LIBCPP_HIDE_FROM_ABI flat_multimap(sorted_equivalent_t, initializer_list __il, const _Allocator& __alloc) + : flat_multimap(sorted_equivalent, __il.begin(), __il.end(), __alloc) {} + + _LIBCPP_HIDE_FROM_ABI flat_multimap& operator=(initializer_list __il) { + clear(); + insert(__il); + return *this; + } + + // copy/move assignment are not specified in the spec (defaulted) + // but move assignment can potentially leave moved from object in an inconsistent + // state if an exception is thrown + _LIBCPP_HIDE_FROM_ABI flat_multimap& operator=(const flat_multimap&) = default; + + _LIBCPP_HIDE_FROM_ABI flat_multimap& operator=(flat_multimap&& __other) noexcept( + is_nothrow_move_assignable_v<_KeyContainer> && is_nothrow_move_assignable_v<_MappedContainer> && + is_nothrow_move_assignable_v<_Compare>) { + auto __clear_other_guard = std::__make_scope_guard([&]() noexcept { __other.clear() /* noexcept */; }); + auto __clear_self_guard = std::__make_exception_guard([&]() noexcept { clear() /* noexcept */; }); + __containers_ = std::move(__other.__containers_); + __compare_ = std::move(__other.__compare_); + __clear_self_guard.__complete(); + return *this; + } + + // iterators + _LIBCPP_HIDE_FROM_ABI iterator begin() noexcept { + return iterator(__containers_.keys.begin(), __containers_.values.begin()); + } + + _LIBCPP_HIDE_FROM_ABI const_iterator begin() const noexcept { + return const_iterator(__containers_.keys.begin(), __containers_.values.begin()); + } + + _LIBCPP_HIDE_FROM_ABI iterator end() noexcept { + return iterator(__containers_.keys.end(), __containers_.values.end()); + } + + _LIBCPP_HIDE_FROM_ABI const_iterator end() const noexcept { + return const_iterator(__containers_.keys.end(), __containers_.values.end()); + } + + _LIBCPP_HIDE_FROM_ABI reverse_iterator rbegin() noexcept { return reverse_iterator(end()); } + _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rbegin() const noexcept { return const_reverse_iterator(end()); } + _LIBCPP_HIDE_FROM_ABI reverse_iterator rend() noexcept { return reverse_iterator(begin()); } + _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rend() const noexcept { return const_reverse_iterator(begin()); } + + _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const noexcept { return begin(); } + _LIBCPP_HIDE_FROM_ABI const_iterator cend() const noexcept { return end(); } + _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(end()); } + _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crend() const noexcept { return const_reverse_iterator(begin()); } + + // [flat.map.capacity], capacity + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI bool empty() const noexcept { return __containers_.keys.empty(); } + + _LIBCPP_HIDE_FROM_ABI size_type size() const noexcept { return __containers_.keys.size(); } + + _LIBCPP_HIDE_FROM_ABI size_type max_size() const noexcept { + return std::min(__containers_.keys.max_size(), __containers_.values.max_size()); + } + + // [flat.map.modifiers], modifiers + template + requires is_constructible_v, _Args...> && is_move_constructible_v && + is_move_constructible_v + _LIBCPP_HIDE_FROM_ABI iterator emplace(_Args&&... __args) { + std::pair __pair(std::forward<_Args>(__args)...); + auto __key_it = ranges::upper_bound(__containers_.keys, __pair.first, __compare_); + auto __mapped_it = __corresponding_mapped_it(*this, __key_it); + + return __flat_map_utils::__emplace_exact_pos( + *this, std::move(__key_it), std::move(__mapped_it), std::move(__pair.first), std::move(__pair.second)); + } + + template + requires is_constructible_v, _Args...> + _LIBCPP_HIDE_FROM_ABI iterator emplace_hint(const_iterator __hint, _Args&&... __args) { + std::pair __pair(std::forward<_Args>(__args)...); + + auto __prev_larger = __hint != cbegin() && __compare_(__pair.first, (__hint - 1)->first); + auto __next_smaller = __hint != cend() && __compare_(__hint->first, __pair.first); + + auto __hint_distance = __hint.__key_iter_ - __containers_.keys.cbegin(); + auto __key_iter = __containers_.keys.begin() + __hint_distance; + auto __mapped_iter = __containers_.values.begin() + __hint_distance; + + if (!__prev_larger && !__next_smaller) [[likely]] { + // hint correct, just use exact hint iterators + } else if (__prev_larger && !__next_smaller) { + // the hint position is more to the right than the key should have been. + // we want to emplace the element to a position as right as possible + // e.g. Insert new element "2" in the following range + // 1, 1, 2, 2, 2, 3, 4, 6 + // ^ + // | + // hint + // We want to insert "2" after the last existing "2" + __key_iter = ranges::upper_bound(__containers_.keys.begin(), __key_iter, __pair.first, __compare_); + __mapped_iter = __corresponding_mapped_it(*this, __key_iter); + } else { + _LIBCPP_ASSERT_INTERNAL(!__prev_larger && __next_smaller, "this means that the multimap is not sorted"); + + // the hint position is more to the left than the key should have been. + // we want to emplace the element to a position as left as possible + // 1, 1, 2, 2, 2, 3, 4, 6 + // ^ + // | + // hint + // We want to insert "2" before the first existing "2" + __key_iter = ranges::lower_bound(__key_iter, __containers_.keys.end(), __pair.first, __compare_); + __mapped_iter = __corresponding_mapped_it(*this, __key_iter); + } + return __flat_map_utils::__emplace_exact_pos( + *this, __key_iter, __mapped_iter, std::move(__pair.first), std::move(__pair.second)); + } + + _LIBCPP_HIDE_FROM_ABI iterator insert(const value_type& __x) { return emplace(__x); } + + _LIBCPP_HIDE_FROM_ABI iterator insert(value_type&& __x) { return emplace(std::move(__x)); } + + _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __hint, const value_type& __x) { + return emplace_hint(__hint, __x); + } + + _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __hint, value_type&& __x) { + return emplace_hint(__hint, std::move(__x)); + } + + template + requires is_constructible_v, _PairLike> + _LIBCPP_HIDE_FROM_ABI iterator insert(_PairLike&& __x) { + return emplace(std::forward<_PairLike>(__x)); + } + + template + requires is_constructible_v, _PairLike> + _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __hint, _PairLike&& __x) { + return emplace_hint(__hint, std::forward<_PairLike>(__x)); + } + + template + requires __has_input_iterator_category<_InputIterator>::value + _LIBCPP_HIDE_FROM_ABI void insert(_InputIterator __first, _InputIterator __last) { + if constexpr (sized_sentinel_for<_InputIterator, _InputIterator>) { + __reserve(__last - __first); + } + __append_sort_merge(std::move(__first), std::move(__last)); + } + + template + requires __has_input_iterator_category<_InputIterator>::value + _LIBCPP_HIDE_FROM_ABI void insert(sorted_equivalent_t, _InputIterator __first, _InputIterator __last) { + if constexpr (sized_sentinel_for<_InputIterator, _InputIterator>) { + __reserve(__last - __first); + } + + __append_sort_merge(std::move(__first), std::move(__last)); + } + + template <_ContainerCompatibleRange _Range> + _LIBCPP_HIDE_FROM_ABI void insert_range(_Range&& __range) { + if constexpr (ranges::sized_range<_Range>) { + __reserve(ranges::size(__range)); + } + + __append_sort_merge(ranges::begin(__range), ranges::end(__range)); + } + + _LIBCPP_HIDE_FROM_ABI void insert(initializer_list __il) { insert(__il.begin(), __il.end()); } + + _LIBCPP_HIDE_FROM_ABI void insert(sorted_equivalent_t, initializer_list __il) { + insert(sorted_equivalent, __il.begin(), __il.end()); + } + + _LIBCPP_HIDE_FROM_ABI containers extract() && { + auto __guard = std::__make_scope_guard([&]() noexcept { clear() /* noexcept */; }); + auto __ret = std::move(__containers_); + return __ret; + } + + _LIBCPP_HIDE_FROM_ABI void replace(key_container_type&& __key_cont, mapped_container_type&& __mapped_cont) { + _LIBCPP_ASSERT_VALID_INPUT_RANGE( + __key_cont.size() == __mapped_cont.size(), "flat_multimap keys and mapped containers have different size"); + + _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(__is_sorted(__key_cont), "Key container is not sorted"); + auto __guard = std::__make_exception_guard([&]() noexcept { clear() /* noexcept */; }); + __containers_.keys = std::move(__key_cont); + __containers_.values = std::move(__mapped_cont); + __guard.__complete(); + } + + _LIBCPP_HIDE_FROM_ABI iterator erase(iterator __position) { + return __erase(__position.__key_iter_, __position.__mapped_iter_); + } + + _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __position) { + return __erase(__position.__key_iter_, __position.__mapped_iter_); + } + + _LIBCPP_HIDE_FROM_ABI size_type erase(const key_type& __x) { + auto [__first, __last] = equal_range(__x); + auto __res = __last - __first; + erase(__first, __last); + return __res; + } + + template + requires(__is_compare_transparent && !is_convertible_v<_Kp &&, iterator> && + !is_convertible_v<_Kp &&, const_iterator>) + _LIBCPP_HIDE_FROM_ABI size_type erase(_Kp&& __x) { + auto [__first, __last] = equal_range(__x); + auto __res = __last - __first; + erase(__first, __last); + return __res; + } + + _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __first, const_iterator __last) { + auto __on_failure = std::__make_exception_guard([&]() noexcept { clear() /* noexcept */; }); + auto __key_it = __containers_.keys.erase(__first.__key_iter_, __last.__key_iter_); + auto __mapped_it = __containers_.values.erase(__first.__mapped_iter_, __last.__mapped_iter_); + __on_failure.__complete(); + return iterator(std::move(__key_it), std::move(__mapped_it)); + } + + _LIBCPP_HIDE_FROM_ABI void swap(flat_multimap& __y) noexcept { + // warning: The spec has unconditional noexcept, which means that + // if any of the following functions throw an exception, + // std::terminate will be called + ranges::swap(__compare_, __y.__compare_); + ranges::swap(__containers_.keys, __y.__containers_.keys); + ranges::swap(__containers_.values, __y.__containers_.values); + } + + _LIBCPP_HIDE_FROM_ABI void clear() noexcept { + __containers_.keys.clear(); + __containers_.values.clear(); + } + + // observers + _LIBCPP_HIDE_FROM_ABI key_compare key_comp() const { return __compare_; } + _LIBCPP_HIDE_FROM_ABI value_compare value_comp() const { return value_compare(__compare_); } + + _LIBCPP_HIDE_FROM_ABI const key_container_type& keys() const noexcept { return __containers_.keys; } + _LIBCPP_HIDE_FROM_ABI const mapped_container_type& values() const noexcept { return __containers_.values; } + + // map operations + _LIBCPP_HIDE_FROM_ABI iterator find(const key_type& __x) { return __find_impl(*this, __x); } + + _LIBCPP_HIDE_FROM_ABI const_iterator find(const key_type& __x) const { return __find_impl(*this, __x); } + + template + requires __is_compare_transparent + _LIBCPP_HIDE_FROM_ABI iterator find(const _Kp& __x) { + return __find_impl(*this, __x); + } + + template + requires __is_compare_transparent + _LIBCPP_HIDE_FROM_ABI const_iterator find(const _Kp& __x) const { + return __find_impl(*this, __x); + } + + _LIBCPP_HIDE_FROM_ABI size_type count(const key_type& __x) const { + auto [__first, __last] = equal_range(__x); + return __last - __first; + } + + template + requires __is_compare_transparent + _LIBCPP_HIDE_FROM_ABI size_type count(const _Kp& __x) const { + auto [__first, __last] = equal_range(__x); + return __last - __first; + } + + _LIBCPP_HIDE_FROM_ABI bool contains(const key_type& __x) const { return find(__x) != end(); } + + template + requires __is_compare_transparent + _LIBCPP_HIDE_FROM_ABI bool contains(const _Kp& __x) const { + return find(__x) != end(); + } + + _LIBCPP_HIDE_FROM_ABI iterator lower_bound(const key_type& __x) { return __lower_bound(*this, __x); } + + _LIBCPP_HIDE_FROM_ABI const_iterator lower_bound(const key_type& __x) const { + return __lower_bound(*this, __x); + } + + template + requires __is_compare_transparent + _LIBCPP_HIDE_FROM_ABI iterator lower_bound(const _Kp& __x) { + return __lower_bound(*this, __x); + } + + template + requires __is_compare_transparent + _LIBCPP_HIDE_FROM_ABI const_iterator lower_bound(const _Kp& __x) const { + return __lower_bound(*this, __x); + } + + _LIBCPP_HIDE_FROM_ABI iterator upper_bound(const key_type& __x) { return __upper_bound(*this, __x); } + + _LIBCPP_HIDE_FROM_ABI const_iterator upper_bound(const key_type& __x) const { + return __upper_bound(*this, __x); + } + + template + requires __is_compare_transparent + _LIBCPP_HIDE_FROM_ABI iterator upper_bound(const _Kp& __x) { + return __upper_bound(*this, __x); + } + + template + requires __is_compare_transparent + _LIBCPP_HIDE_FROM_ABI const_iterator upper_bound(const _Kp& __x) const { + return __upper_bound(*this, __x); + } + + _LIBCPP_HIDE_FROM_ABI pair equal_range(const key_type& __x) { + return __equal_range_impl(*this, __x); + } + + _LIBCPP_HIDE_FROM_ABI pair equal_range(const key_type& __x) const { + return __equal_range_impl(*this, __x); + } + + template + requires __is_compare_transparent + _LIBCPP_HIDE_FROM_ABI pair equal_range(const _Kp& __x) { + return __equal_range_impl(*this, __x); + } + template + requires __is_compare_transparent + _LIBCPP_HIDE_FROM_ABI pair equal_range(const _Kp& __x) const { + return __equal_range_impl(*this, __x); + } + + friend _LIBCPP_HIDE_FROM_ABI bool operator==(const flat_multimap& __x, const flat_multimap& __y) { + return ranges::equal(__x, __y); + } + + friend _LIBCPP_HIDE_FROM_ABI auto operator<=>(const flat_multimap& __x, const flat_multimap& __y) { + return std::lexicographical_compare_three_way( + __x.begin(), __x.end(), __y.begin(), __y.end(), std::__synth_three_way); + } + + friend _LIBCPP_HIDE_FROM_ABI void swap(flat_multimap& __x, flat_multimap& __y) noexcept { __x.swap(__y); } + +private: + struct __ctor_uses_allocator_tag { + explicit _LIBCPP_HIDE_FROM_ABI __ctor_uses_allocator_tag() = default; + }; + struct __ctor_uses_allocator_empty_tag { + explicit _LIBCPP_HIDE_FROM_ABI __ctor_uses_allocator_empty_tag() = default; + }; + + template + requires __allocator_ctor_constraint<_Allocator> + _LIBCPP_HIDE_FROM_ABI + flat_multimap(__ctor_uses_allocator_tag, + const _Allocator& __alloc, + _KeyCont&& __key_cont, + _MappedCont&& __mapped_cont, + _CompArg&&... __comp) + : __containers_{.keys = std::make_obj_using_allocator( + __alloc, std::forward<_KeyCont>(__key_cont)), + .values = std::make_obj_using_allocator( + __alloc, std::forward<_MappedCont>(__mapped_cont))}, + __compare_(std::forward<_CompArg>(__comp)...) {} + + template + requires __allocator_ctor_constraint<_Allocator> + _LIBCPP_HIDE_FROM_ABI flat_multimap(__ctor_uses_allocator_empty_tag, const _Allocator& __alloc, _CompArg&&... __comp) + : __containers_{.keys = std::make_obj_using_allocator(__alloc), + .values = std::make_obj_using_allocator(__alloc)}, + __compare_(std::forward<_CompArg>(__comp)...) {} + + _LIBCPP_HIDE_FROM_ABI bool __is_sorted(auto&& __key_container) const { + return ranges::is_sorted(__key_container, __compare_); + } + + _LIBCPP_HIDE_FROM_ABI void __sort() { + auto __zv = ranges::views::zip(__containers_.keys, __containers_.values); + ranges::sort(__zv, __compare_, [](const auto& __p) -> decltype(auto) { return std::get<0>(__p); }); + } + + template + _LIBCPP_HIDE_FROM_ABI static auto __corresponding_mapped_it(_Self&& __self, _KeyIter&& __key_iter) { + return __self.__containers_.values.begin() + + static_cast>( + ranges::distance(__self.__containers_.keys.begin(), __key_iter)); + } + + template + _LIBCPP_HIDE_FROM_ABI void __append_sort_merge(_InputIterator __first, _Sentinel __last) { + auto __on_failure = std::__make_exception_guard([&]() noexcept { clear() /* noexcept */; }); + size_t __num_appended = __flat_map_utils::__append(*this, std::move(__first), std::move(__last)); + if (__num_appended != 0) { + auto __zv = ranges::views::zip(__containers_.keys, __containers_.values); + auto __append_start_offset = __containers_.keys.size() - __num_appended; + auto __end = __zv.end(); + auto __compare_key = [this](const auto& __p1, const auto& __p2) { + return __compare_(std::get<0>(__p1), std::get<0>(__p2)); + }; + if constexpr (!_WasSorted) { + ranges::sort(__zv.begin() + __append_start_offset, __end, __compare_key); + } else { + _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT( + __is_sorted(__containers_.keys | ranges::views::drop(__append_start_offset)), + "Key container is not sorted"); + } + ranges::inplace_merge(__zv.begin(), __zv.begin() + __append_start_offset, __end, __compare_key); + } + __on_failure.__complete(); + } + + template + _LIBCPP_HIDE_FROM_ABI static auto __find_impl(_Self&& __self, const _Kp& __key) { + auto __it = __self.lower_bound(__key); + auto __last = __self.end(); + if (__it == __last || __self.__compare_(__key, __it->first)) { + return __last; + } + return __it; + } + + template + _LIBCPP_HIDE_FROM_ABI static auto __equal_range_impl(_Self&& __self, const _Kp& __key) { + auto [__key_first, __key_last] = ranges::equal_range(__self.__containers_.keys, __key, __self.__compare_); + + using __iterator_type = ranges::iterator_t; + return std::make_pair(__iterator_type(__key_first, __corresponding_mapped_it(__self, __key_first)), + __iterator_type(__key_last, __corresponding_mapped_it(__self, __key_last))); + } + + template + _LIBCPP_HIDE_FROM_ABI static _Res __lower_bound(_Self&& __self, _Kp& __x) { + auto __key_iter = ranges::lower_bound(__self.__containers_.keys, __x, __self.__compare_); + auto __mapped_iter = __corresponding_mapped_it(__self, __key_iter); + return _Res(std::move(__key_iter), std::move(__mapped_iter)); + } + + template + _LIBCPP_HIDE_FROM_ABI static _Res __upper_bound(_Self&& __self, _Kp& __x) { + auto __key_iter = ranges::upper_bound(__self.__containers_.keys, __x, __self.__compare_); + auto __mapped_iter = __corresponding_mapped_it(__self, __key_iter); + return _Res(std::move(__key_iter), std::move(__mapped_iter)); + } + + _LIBCPP_HIDE_FROM_ABI void __reserve(size_t __size) { + if constexpr (requires { __containers_.keys.reserve(__size); }) { + __containers_.keys.reserve(__size); + } + + if constexpr (requires { __containers_.values.reserve(__size); }) { + __containers_.values.reserve(__size); + } + } + + template + _LIBCPP_HIDE_FROM_ABI iterator __erase(_KIter __key_iter_to_remove, _MIter __mapped_iter_to_remove) { + auto __on_failure = std::__make_exception_guard([&]() noexcept { clear() /* noexcept */; }); + auto __key_iter = __containers_.keys.erase(__key_iter_to_remove); + auto __mapped_iter = __containers_.values.erase(__mapped_iter_to_remove); + __on_failure.__complete(); + return iterator(std::move(__key_iter), std::move(__mapped_iter)); + } + + template + friend typename flat_multimap<_Key2, _Tp2, _Compare2, _KeyContainer2, _MappedContainer2>::size_type + erase_if(flat_multimap<_Key2, _Tp2, _Compare2, _KeyContainer2, _MappedContainer2>&, _Predicate); + + friend __flat_map_utils; + + containers __containers_; + _LIBCPP_NO_UNIQUE_ADDRESS key_compare __compare_; + + struct __key_equiv { + _LIBCPP_HIDE_FROM_ABI __key_equiv(key_compare __c) : __comp_(__c) {} + _LIBCPP_HIDE_FROM_ABI bool operator()(const_reference __x, const_reference __y) const { + return !__comp_(std::get<0>(__x), std::get<0>(__y)) && !__comp_(std::get<0>(__y), std::get<0>(__x)); + } + key_compare __comp_; + }; +}; + +template > + requires(!__is_allocator<_Compare>::value && !__is_allocator<_KeyContainer>::value && + !__is_allocator<_MappedContainer>::value && + is_invocable_v) +flat_multimap(_KeyContainer, _MappedContainer, _Compare = _Compare()) + -> flat_multimap; + +template + requires(uses_allocator_v<_KeyContainer, _Allocator> && uses_allocator_v<_MappedContainer, _Allocator> && + !__is_allocator<_KeyContainer>::value && !__is_allocator<_MappedContainer>::value) +flat_multimap(_KeyContainer, _MappedContainer, _Allocator) + -> flat_multimap, + _KeyContainer, + _MappedContainer>; + +template + requires(!__is_allocator<_Compare>::value && !__is_allocator<_KeyContainer>::value && + !__is_allocator<_MappedContainer>::value && uses_allocator_v<_KeyContainer, _Allocator> && + uses_allocator_v<_MappedContainer, _Allocator> && + is_invocable_v) +flat_multimap(_KeyContainer, _MappedContainer, _Compare, _Allocator) + -> flat_multimap; + +template > + requires(!__is_allocator<_Compare>::value && !__is_allocator<_KeyContainer>::value && + !__is_allocator<_MappedContainer>::value && + is_invocable_v) +flat_multimap(sorted_equivalent_t, _KeyContainer, _MappedContainer, _Compare = _Compare()) + -> flat_multimap; + +template + requires(uses_allocator_v<_KeyContainer, _Allocator> && uses_allocator_v<_MappedContainer, _Allocator> && + !__is_allocator<_KeyContainer>::value && !__is_allocator<_MappedContainer>::value) +flat_multimap(sorted_equivalent_t, _KeyContainer, _MappedContainer, _Allocator) + -> flat_multimap, + _KeyContainer, + _MappedContainer>; + +template + requires(!__is_allocator<_Compare>::value && !__is_allocator<_KeyContainer>::value && + !__is_allocator<_MappedContainer>::value && uses_allocator_v<_KeyContainer, _Allocator> && + uses_allocator_v<_MappedContainer, _Allocator> && + is_invocable_v) +flat_multimap(sorted_equivalent_t, _KeyContainer, _MappedContainer, _Compare, _Allocator) + -> flat_multimap; + +template >> + requires(__has_input_iterator_category<_InputIterator>::value && !__is_allocator<_Compare>::value) +flat_multimap(_InputIterator, _InputIterator, _Compare = _Compare()) + -> flat_multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Compare>; + +template >> + requires(__has_input_iterator_category<_InputIterator>::value && !__is_allocator<_Compare>::value) +flat_multimap(sorted_equivalent_t, _InputIterator, _InputIterator, _Compare = _Compare()) + -> flat_multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Compare>; + +template >, + class _Allocator = allocator, + class = __enable_if_t::value && __is_allocator<_Allocator>::value>> +flat_multimap(from_range_t, _Range&&, _Compare = _Compare(), _Allocator = _Allocator()) -> flat_multimap< + __range_key_type<_Range>, + __range_mapped_type<_Range>, + _Compare, + vector<__range_key_type<_Range>, __allocator_traits_rebind_t<_Allocator, __range_key_type<_Range>>>, + vector<__range_mapped_type<_Range>, __allocator_traits_rebind_t<_Allocator, __range_mapped_type<_Range>>>>; + +template ::value>> +flat_multimap(from_range_t, _Range&&, _Allocator) -> flat_multimap< + __range_key_type<_Range>, + __range_mapped_type<_Range>, + less<__range_key_type<_Range>>, + vector<__range_key_type<_Range>, __allocator_traits_rebind_t<_Allocator, __range_key_type<_Range>>>, + vector<__range_mapped_type<_Range>, __allocator_traits_rebind_t<_Allocator, __range_mapped_type<_Range>>>>; + +template > + requires(!__is_allocator<_Compare>::value) +flat_multimap(initializer_list>, _Compare = _Compare()) -> flat_multimap<_Key, _Tp, _Compare>; + +template > + requires(!__is_allocator<_Compare>::value) +flat_multimap(sorted_equivalent_t, initializer_list>, _Compare = _Compare()) + -> flat_multimap<_Key, _Tp, _Compare>; + +template +struct uses_allocator, _Allocator> + : bool_constant && uses_allocator_v<_MappedContainer, _Allocator>> {}; + +template +_LIBCPP_HIDE_FROM_ABI typename flat_multimap<_Key, _Tp, _Compare, _KeyContainer, _MappedContainer>::size_type +erase_if(flat_multimap<_Key, _Tp, _Compare, _KeyContainer, _MappedContainer>& __flat_multimap, _Predicate __pred) { + auto __zv = ranges::views::zip(__flat_multimap.__containers_.keys, __flat_multimap.__containers_.values); + auto __first = __zv.begin(); + auto __last = __zv.end(); + auto __guard = std::__make_exception_guard([&] { __flat_multimap.clear(); }); + auto __it = std::remove_if(__first, __last, [&](auto&& __zipped) -> bool { + using _Ref = typename flat_multimap<_Key, _Tp, _Compare, _KeyContainer, _MappedContainer>::const_reference; + return __pred(_Ref(std::get<0>(__zipped), std::get<1>(__zipped))); + }); + auto __res = __last - __it; + auto __offset = __it - __first; + + const auto __erase_container = [&](auto& __cont) { __cont.erase(__cont.begin() + __offset, __cont.end()); }; + + __erase_container(__flat_multimap.__containers_.keys); + __erase_container(__flat_multimap.__containers_.values); + + __guard.__complete(); + return __res; +} + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_STD_VER >= 23 + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___FLAT_MAP_FLAT_MULTIMAP_H diff --git a/system/lib/libcxx/include/__flat_map/key_value_iterator.h b/system/lib/libcxx/include/__flat_map/key_value_iterator.h new file mode 100644 index 0000000000000..3ebb653deb197 --- /dev/null +++ b/system/lib/libcxx/include/__flat_map/key_value_iterator.h @@ -0,0 +1,176 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___FLAT_MAP_KEY_VALUE_ITERATOR_H +#define _LIBCPP___FLAT_MAP_KEY_VALUE_ITERATOR_H + +#include <__compare/three_way_comparable.h> +#include <__concepts/convertible_to.h> +#include <__config> +#include <__iterator/iterator_traits.h> +#include <__memory/addressof.h> +#include <__type_traits/conditional.h> +#include <__utility/move.h> +#include <__utility/pair.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +#if _LIBCPP_STD_VER >= 23 + +_LIBCPP_BEGIN_NAMESPACE_STD + +/** + * __key_value_iterator is a proxy iterator which zips the underlying + * _KeyContainer::iterator and the underlying _MappedContainer::iterator. + * The two underlying iterators will be incremented/decremented together. + * And the reference is a pair of the const key reference and the value reference. + */ +template +struct __key_value_iterator { +private: + using __key_iterator _LIBCPP_NODEBUG = typename _KeyContainer::const_iterator; + using __mapped_iterator _LIBCPP_NODEBUG = + _If<_Const, typename _MappedContainer::const_iterator, typename _MappedContainer::iterator>; + using __reference _LIBCPP_NODEBUG = _If<_Const, typename _Owner::const_reference, typename _Owner::reference>; + + struct __arrow_proxy { + __reference __ref_; + _LIBCPP_HIDE_FROM_ABI __reference* operator->() { return std::addressof(__ref_); } + }; + + __key_iterator __key_iter_; + __mapped_iterator __mapped_iter_; + + friend _Owner; + + template + friend struct __key_value_iterator; + +public: + using iterator_concept = random_access_iterator_tag; + // `__key_value_iterator` only satisfy "Cpp17InputIterator" named requirements, because + // its `reference` is not a reference type. + // However, to avoid surprising runtime behaviour when it is used with the + // Cpp17 algorithms or operations, iterator_category is set to random_access_iterator_tag. + using iterator_category = random_access_iterator_tag; + using value_type = typename _Owner::value_type; + using difference_type = typename _Owner::difference_type; + + _LIBCPP_HIDE_FROM_ABI __key_value_iterator() = default; + + _LIBCPP_HIDE_FROM_ABI __key_value_iterator(__key_value_iterator<_Owner, _KeyContainer, _MappedContainer, !_Const> __i) + requires _Const && convertible_to && + convertible_to + : __key_iter_(std::move(__i.__key_iter_)), __mapped_iter_(std::move(__i.__mapped_iter_)) {} + + _LIBCPP_HIDE_FROM_ABI __key_value_iterator(__key_iterator __key_iter, __mapped_iterator __mapped_iter) + : __key_iter_(std::move(__key_iter)), __mapped_iter_(std::move(__mapped_iter)) {} + + _LIBCPP_HIDE_FROM_ABI __reference operator*() const { return __reference(*__key_iter_, *__mapped_iter_); } + _LIBCPP_HIDE_FROM_ABI __arrow_proxy operator->() const { return __arrow_proxy{**this}; } + + _LIBCPP_HIDE_FROM_ABI __key_value_iterator& operator++() { + ++__key_iter_; + ++__mapped_iter_; + return *this; + } + + _LIBCPP_HIDE_FROM_ABI __key_value_iterator operator++(int) { + __key_value_iterator __tmp(*this); + ++*this; + return __tmp; + } + + _LIBCPP_HIDE_FROM_ABI __key_value_iterator& operator--() { + --__key_iter_; + --__mapped_iter_; + return *this; + } + + _LIBCPP_HIDE_FROM_ABI __key_value_iterator operator--(int) { + __key_value_iterator __tmp(*this); + --*this; + return __tmp; + } + + _LIBCPP_HIDE_FROM_ABI __key_value_iterator& operator+=(difference_type __x) { + __key_iter_ += __x; + __mapped_iter_ += __x; + return *this; + } + + _LIBCPP_HIDE_FROM_ABI __key_value_iterator& operator-=(difference_type __x) { + __key_iter_ -= __x; + __mapped_iter_ -= __x; + return *this; + } + + _LIBCPP_HIDE_FROM_ABI __reference operator[](difference_type __n) const { return *(*this + __n); } + + _LIBCPP_HIDE_FROM_ABI friend constexpr bool + operator==(const __key_value_iterator& __x, const __key_value_iterator& __y) { + return __x.__key_iter_ == __y.__key_iter_; + } + + _LIBCPP_HIDE_FROM_ABI friend bool operator<(const __key_value_iterator& __x, const __key_value_iterator& __y) { + return __x.__key_iter_ < __y.__key_iter_; + } + + _LIBCPP_HIDE_FROM_ABI friend bool operator>(const __key_value_iterator& __x, const __key_value_iterator& __y) { + return __y < __x; + } + + _LIBCPP_HIDE_FROM_ABI friend bool operator<=(const __key_value_iterator& __x, const __key_value_iterator& __y) { + return !(__y < __x); + } + + _LIBCPP_HIDE_FROM_ABI friend bool operator>=(const __key_value_iterator& __x, const __key_value_iterator& __y) { + return !(__x < __y); + } + + _LIBCPP_HIDE_FROM_ABI friend auto operator<=>(const __key_value_iterator& __x, const __key_value_iterator& __y) + requires three_way_comparable<__key_iterator> + { + return __x.__key_iter_ <=> __y.__key_iter_; + } + + _LIBCPP_HIDE_FROM_ABI friend __key_value_iterator operator+(const __key_value_iterator& __i, difference_type __n) { + auto __tmp = __i; + __tmp += __n; + return __tmp; + } + + _LIBCPP_HIDE_FROM_ABI friend __key_value_iterator operator+(difference_type __n, const __key_value_iterator& __i) { + return __i + __n; + } + + _LIBCPP_HIDE_FROM_ABI friend __key_value_iterator operator-(const __key_value_iterator& __i, difference_type __n) { + auto __tmp = __i; + __tmp -= __n; + return __tmp; + } + + _LIBCPP_HIDE_FROM_ABI friend difference_type + operator-(const __key_value_iterator& __x, const __key_value_iterator& __y) { + return difference_type(__x.__key_iter_ - __y.__key_iter_); + } +}; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_STD_VER >= 23 + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___FLAT_MAP_KEY_VALUE_ITERATOR_H diff --git a/system/lib/libcxx/include/__flat_map/sorted_equivalent.h b/system/lib/libcxx/include/__flat_map/sorted_equivalent.h new file mode 100644 index 0000000000000..1db935cc6ee75 --- /dev/null +++ b/system/lib/libcxx/include/__flat_map/sorted_equivalent.h @@ -0,0 +1,31 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#ifndef _LIBCPP___FLAT_MAP_SORTED_EQUIVALENT_H +#define _LIBCPP___FLAT_MAP_SORTED_EQUIVALENT_H + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#if _LIBCPP_STD_VER >= 23 + +_LIBCPP_BEGIN_NAMESPACE_STD + +struct sorted_equivalent_t { + explicit sorted_equivalent_t() = default; +}; +inline constexpr sorted_equivalent_t sorted_equivalent{}; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_STD_VER >= 23 + +#endif // _LIBCPP___FLAT_MAP_SORTED_EQUIVALENT_H diff --git a/system/lib/libcxx/include/__type_traits/add_cv.h b/system/lib/libcxx/include/__flat_map/sorted_unique.h similarity index 62% rename from system/lib/libcxx/include/__type_traits/add_cv.h rename to system/lib/libcxx/include/__flat_map/sorted_unique.h index 9e23e5ceb7a3b..0189a5ff1d568 100644 --- a/system/lib/libcxx/include/__type_traits/add_cv.h +++ b/system/lib/libcxx/include/__flat_map/sorted_unique.h @@ -1,3 +1,4 @@ +// -*- C++ -*- //===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. @@ -5,9 +6,8 @@ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___TYPE_TRAITS_ADD_CV_H -#define _LIBCPP___TYPE_TRAITS_ADD_CV_H +#ifndef _LIBCPP___FLAT_MAP_SORTED_UNIQUE_H +#define _LIBCPP___FLAT_MAP_SORTED_UNIQUE_H #include <__config> @@ -15,18 +15,17 @@ # pragma GCC system_header #endif +#if _LIBCPP_STD_VER >= 23 + _LIBCPP_BEGIN_NAMESPACE_STD -template -struct _LIBCPP_TEMPLATE_VIS add_cv { - typedef _LIBCPP_NODEBUG const volatile _Tp type; +struct sorted_unique_t { + explicit sorted_unique_t() = default; }; - -#if _LIBCPP_STD_VER >= 14 -template -using add_cv_t = typename add_cv<_Tp>::type; -#endif +inline constexpr sorted_unique_t sorted_unique{}; _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP___TYPE_TRAITS_ADD_CV_H +#endif // _LIBCPP_STD_VER >= 23 + +#endif // _LIBCPP___FLAT_MAP_SORTED_UNIQUE_H diff --git a/system/lib/libcxx/include/__flat_map/utils.h b/system/lib/libcxx/include/__flat_map/utils.h new file mode 100644 index 0000000000000..acb7dca7ffe96 --- /dev/null +++ b/system/lib/libcxx/include/__flat_map/utils.h @@ -0,0 +1,103 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___FLAT_MAP_UTILS_H +#define _LIBCPP___FLAT_MAP_UTILS_H + +#include <__config> +#include <__type_traits/container_traits.h> +#include <__utility/exception_guard.h> +#include <__utility/forward.h> +#include <__utility/move.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +#if _LIBCPP_STD_VER >= 23 + +_LIBCPP_BEGIN_NAMESPACE_STD + +// These utilities are defined in a class instead of a namespace so that this class can be befriended more easily. +struct __flat_map_utils { + // Emplace a {key: value} into a flat_{multi}map, at the exact position that + // __it_key and __it_mapped point to, assuming that the key is not already present in the map. + // When an exception is thrown during the emplacement, the function will try its best to + // roll back the changes it made to the map. If it cannot roll back the changes, it will + // clear the map. + template + _LIBCPP_HIDE_FROM_ABI static typename _Map::iterator __emplace_exact_pos( + _Map& __map, _IterK&& __it_key, _IterM&& __it_mapped, _KeyArg&& __key, _MArgs&&... __mapped_args) { + auto __on_key_failed = std::__make_exception_guard([&]() noexcept { + using _KeyContainer = typename _Map::key_container_type; + if constexpr (__container_traits<_KeyContainer>::__emplacement_has_strong_exception_safety_guarantee) { + // Nothing to roll back! + } else { + // we need to clear both because we don't know the state of our keys anymore + __map.clear() /* noexcept */; + } + }); + auto __key_it = __map.__containers_.keys.emplace(__it_key, std::forward<_KeyArg>(__key)); + __on_key_failed.__complete(); + + auto __on_value_failed = std::__make_exception_guard([&]() noexcept { + using _MappedContainer = typename _Map::mapped_container_type; + if constexpr (!__container_traits<_MappedContainer>::__emplacement_has_strong_exception_safety_guarantee) { + // we need to clear both because we don't know the state of our values anymore + __map.clear() /* noexcept */; + } else { + // In this case, we know the values are just like before we attempted emplacement, + // and we also know that the keys have been emplaced successfully. Just roll back the keys. +# if _LIBCPP_HAS_EXCEPTIONS + try { +# endif // _LIBCPP_HAS_EXCEPTIONS + __map.__containers_.keys.erase(__key_it); +# if _LIBCPP_HAS_EXCEPTIONS + } catch (...) { + // Now things are funky for real. We're failing to rollback the keys. + // Just give up and clear the whole thing. + // + // Also, swallow the exception that happened during the rollback and let the + // original value-emplacement exception propagate normally. + __map.clear() /* noexcept */; + } +# endif // _LIBCPP_HAS_EXCEPTIONS + } + }); + auto __mapped_it = __map.__containers_.values.emplace(__it_mapped, std::forward<_MArgs>(__mapped_args)...); + __on_value_failed.__complete(); + + return typename _Map::iterator(std::move(__key_it), std::move(__mapped_it)); + } + + // TODO: We could optimize this, see + // https://github.com/llvm/llvm-project/issues/108624 + template + _LIBCPP_HIDE_FROM_ABI static typename _Map::size_type + __append(_Map& __map, _InputIterator __first, _Sentinel __last) { + typename _Map::size_type __num_appended = 0; + for (; __first != __last; ++__first) { + typename _Map::value_type __kv = *__first; + __map.__containers_.keys.insert(__map.__containers_.keys.end(), std::move(__kv.first)); + __map.__containers_.values.insert(__map.__containers_.values.end(), std::move(__kv.second)); + ++__num_appended; + } + return __num_appended; + } +}; +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_STD_VER >= 23 + +_LIBCPP_POP_MACROS + +#endif // #define _LIBCPP___FLAT_MAP_UTILS_H diff --git a/system/lib/libcxx/include/__format/buffer.h b/system/lib/libcxx/include/__format/buffer.h index 8598f0a1c0395..0c054bbc3a1d8 100644 --- a/system/lib/libcxx/include/__format/buffer.h +++ b/system/lib/libcxx/include/__format/buffer.h @@ -14,6 +14,7 @@ #include <__algorithm/fill_n.h> #include <__algorithm/max.h> #include <__algorithm/min.h> +#include <__algorithm/ranges_copy.h> #include <__algorithm/ranges_copy_n.h> #include <__algorithm/transform.h> #include <__algorithm/unwrap_iter.h> @@ -29,6 +30,7 @@ #include <__iterator/wrap_iter.h> #include <__memory/addressof.h> #include <__memory/allocate_at_least.h> +#include <__memory/allocator.h> #include <__memory/allocator_traits.h> #include <__memory/construct_at.h> #include <__memory/ranges_construct_at.h> @@ -37,7 +39,7 @@ #include <__type_traits/conditional.h> #include <__utility/exception_guard.h> #include <__utility/move.h> -#include +#include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -53,24 +55,147 @@ _LIBCPP_BEGIN_NAMESPACE_STD namespace __format { +// A helper to limit the total size of code units written. +class _LIBCPP_HIDE_FROM_ABI __max_output_size { +public: + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI explicit __max_output_size(size_t __max_size) : __max_size_{__max_size} {} + + // This function adjusts the size of a (bulk) write operations. It ensures the + // number of code units written by a __output_buffer never exceeds + // __max_size_ code units. + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI size_t __write_request(size_t __code_units) { + size_t __result = + __code_units_written_ < __max_size_ ? std::min(__code_units, __max_size_ - __code_units_written_) : 0; + __code_units_written_ += __code_units; + return __result; + } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI size_t __code_units_written() const noexcept { return __code_units_written_; } + +private: + size_t __max_size_; + // The code units that would have been written if there was no limit. + // format_to_n returns this value. + size_t __code_units_written_{0}; +}; + /// A "buffer" that handles writing to the proper iterator. /// /// This helper is used together with the @ref back_insert_iterator to offer /// type-erasure for the formatting functions. This reduces the number to /// template instantiations. +/// +/// The design is the following: +/// - There is an external object that connects the buffer to the output. +/// - This buffer object: +/// - inherits publicly from this class. +/// - has a static or dynamic buffer. +/// - has a static member function to make space in its buffer write +/// operations. This can be done by increasing the size of the internal +/// buffer or by writing the contents of the buffer to the output iterator. +/// +/// This member function is a constructor argument, so its name is not +/// fixed. The code uses the name __prepare_write. +/// - The number of output code units can be limited by a __max_output_size +/// object. This is used in format_to_n This object: +/// - Contains the maximum number of code units to be written. +/// - Contains the number of code units that are requested to be written. +/// This number is returned to the user of format_to_n. +/// - The write functions call the object's __request_write member function. +/// This function: +/// - Updates the number of code units that are requested to be written. +/// - Returns the number of code units that can be written without +/// exceeding the maximum number of code units to be written. +/// +/// Documentation for the buffer usage members: +/// - __ptr_ +/// The start of the buffer. +/// - __capacity_ +/// The number of code units that can be written. This means +/// [__ptr_, __ptr_ + __capacity_) is a valid range to write to. +/// - __size_ +/// The number of code units written in the buffer. The next code unit will +/// be written at __ptr_ + __size_. This __size_ may NOT contain the total +/// number of code units written by the __output_buffer. Whether or not it +/// does depends on the sub-class used. Typically the total number of code +/// units written is not interesting. It is interesting for format_to_n which +/// has its own way to track this number. +/// +/// Documentation for the modifying buffer operations: +/// The subclasses have a function with the following signature: +/// +/// static void __prepare_write( +/// __output_buffer<_CharT>& __buffer, size_t __code_units); +/// +/// This function is called when a write function writes more code units than +/// the buffer's available space. When an __max_output_size object is provided +/// the number of code units is the number of code units returned from +/// __max_output_size::__request_write function. +/// +/// - The __buffer contains *this. Since the class containing this function +/// inherits from __output_buffer it's safe to cast it to the subclass being +/// used. +/// - The __code_units is the number of code units the caller will write + 1. +/// - This value does not take the available space of the buffer into account. +/// - The push_back function is more efficient when writing before resizing, +/// this means the buffer should always have room for one code unit. Hence +/// the + 1 is the size. +/// - When the function returns there is room for at least one additional code +/// unit. There is no requirement there is room for __code_units code units: +/// - The class has some "bulk" operations. For example, __copy which copies +/// the contents of a basic_string_view to the output. If the sub-class has +/// a fixed size buffer the size of the basic_string_view may be larger +/// than the buffer. In that case it's impossible to honor the requested +/// size. +/// - When the buffer has room for at least one code unit the function may be +/// a no-op. +/// - When the function makes space for more code units it uses one for these +/// functions to signal the change: +/// - __buffer_flushed() +/// - This function is typically used for a fixed sized buffer. +/// - The current contents of [__ptr_, __ptr_ + __size_) have been +/// processed. +/// - __ptr_ remains unchanged. +/// - __capacity_ remains unchanged. +/// - __size_ will be set to 0. +/// - __buffer_moved(_CharT* __ptr, size_t __capacity) +/// - This function is typically used for a dynamic sized buffer. There the +/// location of the buffer changes due to reallocations. +/// - __ptr_ will be set to __ptr. (This value may be the old value of +/// __ptr_). +/// - __capacity_ will be set to __capacity. (This value may be the old +/// value of __capacity_). +/// - __size_ remains unchanged, +/// - The range [__ptr, __ptr + __size_) contains the original data of the +/// range [__ptr_, __ptr_ + __size_). +/// +/// The push_back function expects a valid buffer and a capacity of at least 1. +/// This means: +/// - The class is constructed with a valid buffer, +/// - __buffer_moved is called with a valid buffer is used before the first +/// write operation, +/// - no write function is ever called, or +/// - the class is constructed with a __max_output_size object with __max_size 0. +/// +/// The latter option allows formatted_size to use the output buffer without +/// ever writing anything to the buffer. template <__fmt_char_type _CharT> class _LIBCPP_TEMPLATE_VIS __output_buffer { public: - using value_type = _CharT; + using value_type _LIBCPP_NODEBUG = _CharT; + using __prepare_write_type _LIBCPP_NODEBUG = void (*)(__output_buffer<_CharT>&, size_t); - template - _LIBCPP_HIDE_FROM_ABI explicit __output_buffer(_CharT* __ptr, size_t __capacity, _Tp* __obj) - : __ptr_(__ptr), - __capacity_(__capacity), - __flush_([](_CharT* __p, size_t __n, void* __o) { static_cast<_Tp*>(__o)->__flush(__p, __n); }), - __obj_(__obj) {} + [[nodiscard]] + _LIBCPP_HIDE_FROM_ABI explicit __output_buffer(_CharT* __ptr, size_t __capacity, __prepare_write_type __function) + : __output_buffer{__ptr, __capacity, __function, nullptr} {} - _LIBCPP_HIDE_FROM_ABI void __reset(_CharT* __ptr, size_t __capacity) { + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI explicit __output_buffer( + _CharT* __ptr, size_t __capacity, __prepare_write_type __function, __max_output_size* __max_output_size) + : __ptr_(__ptr), __capacity_(__capacity), __prepare_write_(__function), __max_output_size_(__max_output_size) {} + + _LIBCPP_HIDE_FROM_ABI void __buffer_flushed() { __size_ = 0; } + + _LIBCPP_HIDE_FROM_ABI void __buffer_moved(_CharT* __ptr, size_t __capacity) { __ptr_ = __ptr; __capacity_ = __capacity; } @@ -79,12 +204,18 @@ class _LIBCPP_TEMPLATE_VIS __output_buffer { // Used in std::back_insert_iterator. _LIBCPP_HIDE_FROM_ABI void push_back(_CharT __c) { + if (__max_output_size_ && __max_output_size_->__write_request(1) == 0) + return; + + _LIBCPP_ASSERT_INTERNAL( + __ptr_ && __size_ < __capacity_ && __available() >= 1, "attempted to write outside the buffer"); + __ptr_[__size_++] = __c; // Profiling showed flushing after adding is more efficient than flushing // when entering the function. if (__size_ == __capacity_) - __flush(); + __prepare_write(0); } /// Copies the input __str to the buffer. @@ -105,25 +236,20 @@ class _LIBCPP_TEMPLATE_VIS __output_buffer { // upper case. For integral these strings are short. // TODO FMT Look at the improvements above. size_t __n = __str.size(); - - __flush_on_overflow(__n); - if (__n < __capacity_) { // push_back requires the buffer to have room for at least one character (so use <). - std::copy_n(__str.data(), __n, std::addressof(__ptr_[__size_])); - __size_ += __n; - return; + if (__max_output_size_) { + __n = __max_output_size_->__write_request(__n); + if (__n == 0) + return; } - // The output doesn't fit in the internal buffer. - // Copy the data in "__capacity_" sized chunks. - _LIBCPP_ASSERT_INTERNAL(__size_ == 0, "the buffer should be flushed by __flush_on_overflow"); const _InCharT* __first = __str.data(); do { - size_t __chunk = std::min(__n, __capacity_); + __prepare_write(__n); + size_t __chunk = std::min(__n, __available()); std::copy_n(__first, __chunk, std::addressof(__ptr_[__size_])); - __size_ = __chunk; + __size_ += __chunk; __first += __chunk; __n -= __chunk; - __flush(); } while (__n); } @@ -137,121 +263,59 @@ class _LIBCPP_TEMPLATE_VIS __output_buffer { _LIBCPP_ASSERT_INTERNAL(__first <= __last, "not a valid range"); size_t __n = static_cast(__last - __first); - __flush_on_overflow(__n); - if (__n < __capacity_) { // push_back requires the buffer to have room for at least one character (so use <). - std::transform(__first, __last, std::addressof(__ptr_[__size_]), std::move(__operation)); - __size_ += __n; - return; + if (__max_output_size_) { + __n = __max_output_size_->__write_request(__n); + if (__n == 0) + return; } - // The output doesn't fit in the internal buffer. - // Transform the data in "__capacity_" sized chunks. - _LIBCPP_ASSERT_INTERNAL(__size_ == 0, "the buffer should be flushed by __flush_on_overflow"); do { - size_t __chunk = std::min(__n, __capacity_); + __prepare_write(__n); + size_t __chunk = std::min(__n, __available()); std::transform(__first, __first + __chunk, std::addressof(__ptr_[__size_]), __operation); - __size_ = __chunk; + __size_ += __chunk; __first += __chunk; __n -= __chunk; - __flush(); } while (__n); } /// A \c fill_n wrapper. _LIBCPP_HIDE_FROM_ABI void __fill(size_t __n, _CharT __value) { - __flush_on_overflow(__n); - if (__n < __capacity_) { // push_back requires the buffer to have room for at least one character (so use <). - std::fill_n(std::addressof(__ptr_[__size_]), __n, __value); - __size_ += __n; - return; + if (__max_output_size_) { + __n = __max_output_size_->__write_request(__n); + if (__n == 0) + return; } - // The output doesn't fit in the internal buffer. - // Fill the buffer in "__capacity_" sized chunks. - _LIBCPP_ASSERT_INTERNAL(__size_ == 0, "the buffer should be flushed by __flush_on_overflow"); do { - size_t __chunk = std::min(__n, __capacity_); + __prepare_write(__n); + size_t __chunk = std::min(__n, __available()); std::fill_n(std::addressof(__ptr_[__size_]), __chunk, __value); - __size_ = __chunk; + __size_ += __chunk; __n -= __chunk; - __flush(); } while (__n); } - _LIBCPP_HIDE_FROM_ABI void __flush() { - __flush_(__ptr_, __size_, __obj_); - __size_ = 0; - } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI size_t __capacity() const { return __capacity_; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI size_t __size() const { return __size_; } private: _CharT* __ptr_; size_t __capacity_; size_t __size_{0}; - void (*__flush_)(_CharT*, size_t, void*); - void* __obj_; + void (*__prepare_write_)(__output_buffer<_CharT>&, size_t); + __max_output_size* __max_output_size_; - /// Flushes the buffer when the output operation would overflow the buffer. - /// - /// A simple approach for the overflow detection would be something along the - /// lines: - /// \code - /// // The internal buffer is large enough. - /// if (__n <= __capacity_) { - /// // Flush when we really would overflow. - /// if (__size_ + __n >= __capacity_) - /// __flush(); - /// ... - /// } - /// \endcode - /// - /// This approach works for all cases but one: - /// A __format_to_n_buffer_base where \ref __enable_direct_output is true. - /// In that case the \ref __capacity_ of the buffer changes during the first - /// \ref __flush. During that operation the output buffer switches from its - /// __writer_ to its __storage_. The \ref __capacity_ of the former depends - /// on the value of n, of the latter is a fixed size. For example: - /// - a format_to_n call with a 10'000 char buffer, - /// - the buffer is filled with 9'500 chars, - /// - adding 1'000 elements would overflow the buffer so the buffer gets - /// changed and the \ref __capacity_ decreases from 10'000 to - /// __buffer_size (256 at the time of writing). - /// - /// This means that the \ref __flush for this class may need to copy a part of - /// the internal buffer to the proper output. In this example there will be - /// 500 characters that need this copy operation. - /// - /// Note it would be more efficient to write 500 chars directly and then swap - /// the buffers. This would make the code more complex and \ref format_to_n is - /// not the most common use case. Therefore the optimization isn't done. - _LIBCPP_HIDE_FROM_ABI void __flush_on_overflow(size_t __n) { - if (__size_ + __n >= __capacity_) - __flush(); - } -}; - -/// A storage using an internal buffer. -/// -/// This storage is used when writing a single element to the output iterator -/// is expensive. -template <__fmt_char_type _CharT> -class _LIBCPP_TEMPLATE_VIS __internal_storage { -public: - _LIBCPP_HIDE_FROM_ABI _CharT* __begin() { return __buffer_; } - - static constexpr size_t __buffer_size = 256 / sizeof(_CharT); + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI size_t __available() const { return __capacity_ - __size_; } -private: - _CharT __buffer_[__buffer_size]; + _LIBCPP_HIDE_FROM_ABI void __prepare_write(size_t __code_units) { + // Always have space for one additional code unit. This is a precondition of the push_back function. + __code_units += 1; + if (__available() < __code_units) + __prepare_write_(*this, __code_units + 1); + } }; -/// A storage writing directly to the storage. -/// -/// This requires the storage to be a contiguous buffer of \a _CharT. -/// Since the output is directly written to the underlying storage this class -/// is just an empty class. -template <__fmt_char_type _CharT> -class _LIBCPP_TEMPLATE_VIS __direct_storage {}; - template concept __enable_direct_output = __fmt_char_type<_CharT> && @@ -260,40 +324,6 @@ concept __enable_direct_output = // `#ifdef`. || same_as<_OutIt, __wrap_iter<_CharT*>>); -/// Write policy for directly writing to the underlying output. -template -class _LIBCPP_TEMPLATE_VIS __writer_direct { -public: - _LIBCPP_HIDE_FROM_ABI explicit __writer_direct(_OutIt __out_it) : __out_it_(__out_it) {} - - _LIBCPP_HIDE_FROM_ABI _OutIt __out_it() { return __out_it_; } - - _LIBCPP_HIDE_FROM_ABI void __flush(_CharT*, size_t __n) { - // _OutIt can be a __wrap_iter. Therefore the original iterator - // is adjusted. - __out_it_ += __n; - } - -private: - _OutIt __out_it_; -}; - -/// Write policy for copying the buffer to the output. -template -class _LIBCPP_TEMPLATE_VIS __writer_iterator { -public: - _LIBCPP_HIDE_FROM_ABI explicit __writer_iterator(_OutIt __out_it) : __out_it_{std::move(__out_it)} {} - - _LIBCPP_HIDE_FROM_ABI _OutIt __out_it() && { return std::move(__out_it_); } - - _LIBCPP_HIDE_FROM_ABI void __flush(_CharT* __ptr, size_t __n) { - __out_it_ = std::ranges::copy_n(__ptr, __n, std::move(__out_it_)).out; - } - -private: - _OutIt __out_it_; -}; - /// Concept to see whether a \a _Container is insertable. /// /// The concept is used to validate whether multiple calls to a @@ -311,196 +341,220 @@ concept __insertable = /// Extract the container type of a \ref back_insert_iterator. template struct _LIBCPP_TEMPLATE_VIS __back_insert_iterator_container { - using type = void; + using type _LIBCPP_NODEBUG = void; }; template <__insertable _Container> struct _LIBCPP_TEMPLATE_VIS __back_insert_iterator_container> { - using type = _Container; + using type _LIBCPP_NODEBUG = _Container; }; -/// Write policy for inserting the buffer in a container. -template -class _LIBCPP_TEMPLATE_VIS __writer_container { +// A dynamically growing buffer. +template <__fmt_char_type _CharT> +class _LIBCPP_TEMPLATE_VIS __allocating_buffer : public __output_buffer<_CharT> { public: - using _CharT = typename _Container::value_type; + __allocating_buffer(const __allocating_buffer&) = delete; + __allocating_buffer& operator=(const __allocating_buffer&) = delete; - _LIBCPP_HIDE_FROM_ABI explicit __writer_container(back_insert_iterator<_Container> __out_it) - : __container_{__out_it.__get_container()} {} + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI __allocating_buffer() : __allocating_buffer{nullptr} {} - _LIBCPP_HIDE_FROM_ABI auto __out_it() { return std::back_inserter(*__container_); } + [[nodiscard]] + _LIBCPP_HIDE_FROM_ABI explicit __allocating_buffer(__max_output_size* __max_output_size) + : __output_buffer<_CharT>{__small_buffer_, __buffer_size_, __prepare_write, __max_output_size} {} - _LIBCPP_HIDE_FROM_ABI void __flush(_CharT* __ptr, size_t __n) { - __container_->insert(__container_->end(), __ptr, __ptr + __n); + _LIBCPP_HIDE_FROM_ABI ~__allocating_buffer() { + if (__ptr_ != __small_buffer_) + _Alloc{}.deallocate(__ptr_, this->__capacity()); } -private: - _Container* __container_; -}; + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI basic_string_view<_CharT> __view() { return {__ptr_, this->__size()}; } -/// Selects the type of the writer used for the output iterator. -template -class _LIBCPP_TEMPLATE_VIS __writer_selector { - using _Container = typename __back_insert_iterator_container<_OutIt>::type; +private: + using _Alloc _LIBCPP_NODEBUG = allocator<_CharT>; -public: - using type = - conditional_t, - __writer_container<_Container>, - conditional_t<__enable_direct_output<_OutIt, _CharT>, - __writer_direct<_OutIt, _CharT>, - __writer_iterator<_OutIt, _CharT>>>; -}; + // Since allocating is expensive the class has a small internal buffer. When + // its capacity is exceeded a dynamic buffer will be allocated. + static constexpr size_t __buffer_size_ = 256; + _CharT __small_buffer_[__buffer_size_]; -/// The generic formatting buffer. -template - requires(output_iterator<_OutIt, const _CharT&>) -class _LIBCPP_TEMPLATE_VIS __format_buffer { - using _Storage = - conditional_t<__enable_direct_output<_OutIt, _CharT>, __direct_storage<_CharT>, __internal_storage<_CharT>>; + _CharT* __ptr_{__small_buffer_}; -public: - _LIBCPP_HIDE_FROM_ABI explicit __format_buffer(_OutIt __out_it) - requires(same_as<_Storage, __internal_storage<_CharT>>) - : __output_(__storage_.__begin(), __storage_.__buffer_size, this), __writer_(std::move(__out_it)) {} + _LIBCPP_HIDE_FROM_ABI void __grow_buffer(size_t __capacity) { + if (__capacity < __buffer_size_) + return; - _LIBCPP_HIDE_FROM_ABI explicit __format_buffer(_OutIt __out_it) - requires(same_as<_Storage, __direct_storage<_CharT>>) - : __output_(std::__unwrap_iter(__out_it), size_t(-1), this), __writer_(std::move(__out_it)) {} + _LIBCPP_ASSERT_INTERNAL(__capacity > this->__capacity(), "the buffer must grow"); - _LIBCPP_HIDE_FROM_ABI auto __make_output_iterator() { return __output_.__make_output_iterator(); } + // _CharT is an implicit lifetime type so can be used without explicit + // construction or destruction. + _Alloc __alloc; + auto __result = std::__allocate_at_least(__alloc, __capacity); + std::copy_n(__ptr_, this->__size(), __result.ptr); + if (__ptr_ != __small_buffer_) + __alloc.deallocate(__ptr_, this->__capacity()); - _LIBCPP_HIDE_FROM_ABI void __flush(_CharT* __ptr, size_t __n) { __writer_.__flush(__ptr, __n); } + __ptr_ = __result.ptr; + this->__buffer_moved(__ptr_, __result.count); + } - _LIBCPP_HIDE_FROM_ABI _OutIt __out_it() && { - __output_.__flush(); - return std::move(__writer_).__out_it(); + _LIBCPP_HIDE_FROM_ABI void __prepare_write(size_t __size_hint) { + __grow_buffer(std::max(this->__capacity() + __size_hint, this->__capacity() * 1.6)); } -private: - _LIBCPP_NO_UNIQUE_ADDRESS _Storage __storage_; - __output_buffer<_CharT> __output_; - typename __writer_selector<_OutIt, _CharT>::type __writer_; + _LIBCPP_HIDE_FROM_ABI static void __prepare_write(__output_buffer<_CharT>& __buffer, size_t __size_hint) { + static_cast<__allocating_buffer<_CharT>&>(__buffer).__prepare_write(__size_hint); + } }; -/// A buffer that counts the number of insertions. -/// -/// Since \ref formatted_size only needs to know the size, the output itself is -/// discarded. -template <__fmt_char_type _CharT> -class _LIBCPP_TEMPLATE_VIS __formatted_size_buffer { +// A buffer that directly writes to the underlying buffer. +template +class _LIBCPP_TEMPLATE_VIS __direct_iterator_buffer : public __output_buffer<_CharT> { public: - _LIBCPP_HIDE_FROM_ABI auto __make_output_iterator() { return __output_.__make_output_iterator(); } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI explicit __direct_iterator_buffer(_OutIt __out_it) + : __direct_iterator_buffer{__out_it, nullptr} {} - _LIBCPP_HIDE_FROM_ABI void __flush(const _CharT*, size_t __n) { __size_ += __n; } + [[nodiscard]] + _LIBCPP_HIDE_FROM_ABI explicit __direct_iterator_buffer(_OutIt __out_it, __max_output_size* __max_output_size) + : __output_buffer<_CharT>{std::__unwrap_iter(__out_it), __buffer_size, __prepare_write, __max_output_size}, + __out_it_(__out_it) {} - _LIBCPP_HIDE_FROM_ABI size_t __result() && { - __output_.__flush(); - return __size_; - } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI _OutIt __out_it() && { return __out_it_ + this->__size(); } private: - __internal_storage<_CharT> __storage_; - __output_buffer<_CharT> __output_{__storage_.__begin(), __storage_.__buffer_size, this}; - size_t __size_{0}; -}; + // The function format_to expects a buffer large enough for the output. The + // function format_to_n has its own helper class that restricts the number of + // write options. So this function class can pretend to have an infinite + // buffer. + static constexpr size_t __buffer_size = -1; + + _OutIt __out_it_; -/// The base of a buffer that counts and limits the number of insertions. -template - requires(output_iterator<_OutIt, const _CharT&>) -struct _LIBCPP_TEMPLATE_VIS __format_to_n_buffer_base { - using _Size = iter_difference_t<_OutIt>; + _LIBCPP_HIDE_FROM_ABI static void + __prepare_write([[maybe_unused]] __output_buffer<_CharT>& __buffer, [[maybe_unused]] size_t __size_hint) { + std::__throw_length_error("__direct_iterator_buffer"); + } +}; +// A buffer that writes its output to the end of a container. +template +class _LIBCPP_TEMPLATE_VIS __container_inserter_buffer : public __output_buffer<_CharT> { public: - _LIBCPP_HIDE_FROM_ABI explicit __format_to_n_buffer_base(_OutIt __out_it, _Size __max_size) - : __writer_(std::move(__out_it)), __max_size_(std::max(_Size(0), __max_size)) {} + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI explicit __container_inserter_buffer(_OutIt __out_it) + : __container_inserter_buffer{__out_it, nullptr} {} - _LIBCPP_HIDE_FROM_ABI void __flush(_CharT* __ptr, size_t __n) { - if (_Size(__size_) <= __max_size_) - __writer_.__flush(__ptr, std::min(_Size(__n), __max_size_ - __size_)); - __size_ += __n; + [[nodiscard]] + _LIBCPP_HIDE_FROM_ABI explicit __container_inserter_buffer(_OutIt __out_it, __max_output_size* __max_output_size) + : __output_buffer<_CharT>{__small_buffer_, __buffer_size, __prepare_write, __max_output_size}, + __container_{__out_it.__get_container()} {} + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI auto __out_it() && { + __container_->insert(__container_->end(), __small_buffer_, __small_buffer_ + this->__size()); + return std::back_inserter(*__container_); } -protected: - __internal_storage<_CharT> __storage_; - __output_buffer<_CharT> __output_{__storage_.__begin(), __storage_.__buffer_size, this}; - typename __writer_selector<_OutIt, _CharT>::type __writer_; +private: + typename __back_insert_iterator_container<_OutIt>::type* __container_; + + // This class uses a fixed size buffer and appends the elements in + // __buffer_size chunks. An alternative would be to use an allocating buffer + // and append the output in a single write operation. Benchmarking showed no + // performance difference. + static constexpr size_t __buffer_size = 256; + _CharT __small_buffer_[__buffer_size]; + + _LIBCPP_HIDE_FROM_ABI void __prepare_write() { + __container_->insert(__container_->end(), __small_buffer_, __small_buffer_ + this->__size()); + this->__buffer_flushed(); + } - _Size __max_size_; - _Size __size_{0}; + _LIBCPP_HIDE_FROM_ABI static void + __prepare_write(__output_buffer<_CharT>& __buffer, [[maybe_unused]] size_t __size_hint) { + static_cast<__container_inserter_buffer<_OutIt, _CharT>&>(__buffer).__prepare_write(); + } }; -/// The base of a buffer that counts and limits the number of insertions. -/// -/// This version is used when \c __enable_direct_output<_OutIt, _CharT> == true. -/// -/// This class limits the size available to the direct writer so it will not -/// exceed the maximum number of code units. +// A buffer that writes to an iterator. +// +// Unlike the __container_inserter_buffer this class' performance does benefit +// from allocating and then inserting. template - requires(output_iterator<_OutIt, const _CharT&>) -class _LIBCPP_TEMPLATE_VIS __format_to_n_buffer_base<_OutIt, _CharT, true> { - using _Size = iter_difference_t<_OutIt>; - +class _LIBCPP_TEMPLATE_VIS __iterator_buffer : public __allocating_buffer<_CharT> { public: - _LIBCPP_HIDE_FROM_ABI explicit __format_to_n_buffer_base(_OutIt __out_it, _Size __max_size) - : __output_(std::__unwrap_iter(__out_it), __max_size, this), - __writer_(std::move(__out_it)), - __max_size_(__max_size) { - if (__max_size <= 0) [[unlikely]] - __output_.__reset(__storage_.__begin(), __storage_.__buffer_size); - } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI explicit __iterator_buffer(_OutIt __out_it) + : __allocating_buffer<_CharT>{}, __out_it_{std::move(__out_it)} {} - _LIBCPP_HIDE_FROM_ABI void __flush(_CharT* __ptr, size_t __n) { - // A __flush to the direct writer happens in the following occasions: - // - The format function has written the maximum number of allowed code - // units. At this point it's no longer valid to write to this writer. So - // switch to the internal storage. This internal storage doesn't need to - // be written anywhere so the __flush for that storage writes no output. - // - Like above, but the next "mass write" operation would overflow the - // buffer. In that case the buffer is pre-emptively switched. The still - // valid code units will be written separately. - // - The format_to_n function is finished. In this case there's no need to - // switch the buffer, but for simplicity the buffers are still switched. - // When the __max_size <= 0 the constructor already switched the buffers. - if (__size_ == 0 && __ptr != __storage_.__begin()) { - __writer_.__flush(__ptr, __n); - __output_.__reset(__storage_.__begin(), __storage_.__buffer_size); - } else if (__size_ < __max_size_) { - // Copies a part of the internal buffer to the output up to n characters. - // See __output_buffer<_CharT>::__flush_on_overflow for more information. - _Size __s = std::min(_Size(__n), __max_size_ - __size_); - std::copy_n(__ptr, __s, __writer_.__out_it()); - __writer_.__flush(__ptr, __s); - } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI explicit __iterator_buffer(_OutIt __out_it, __max_output_size* __max_output_size) + : __allocating_buffer<_CharT>{__max_output_size}, __out_it_{std::move(__out_it)} {} - __size_ += __n; + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI auto __out_it() && { + return std::ranges::copy(this->__view(), std::move(__out_it_)).out; } -protected: - __internal_storage<_CharT> __storage_; - __output_buffer<_CharT> __output_; - __writer_direct<_OutIt, _CharT> __writer_; +private: + _OutIt __out_it_; +}; + +// Selects the type of the buffer used for the output iterator. +template +class _LIBCPP_TEMPLATE_VIS __buffer_selector { + using _Container _LIBCPP_NODEBUG = __back_insert_iterator_container<_OutIt>::type; - _Size __max_size_; - _Size __size_{0}; +public: + using type _LIBCPP_NODEBUG = + conditional_t, + __container_inserter_buffer<_OutIt, _CharT>, + conditional_t<__enable_direct_output<_OutIt, _CharT>, + __direct_iterator_buffer<_OutIt, _CharT>, + __iterator_buffer<_OutIt, _CharT>>>; }; -/// The buffer that counts and limits the number of insertions. +// A buffer that counts and limits the number of insertions. template - requires(output_iterator<_OutIt, const _CharT&>) -struct _LIBCPP_TEMPLATE_VIS __format_to_n_buffer final - : public __format_to_n_buffer_base< _OutIt, _CharT, __enable_direct_output<_OutIt, _CharT>> { - using _Base = __format_to_n_buffer_base<_OutIt, _CharT, __enable_direct_output<_OutIt, _CharT>>; - using _Size = iter_difference_t<_OutIt>; +class _LIBCPP_TEMPLATE_VIS __format_to_n_buffer : private __buffer_selector<_OutIt, _CharT>::type { +public: + using _Base _LIBCPP_NODEBUG = __buffer_selector<_OutIt, _CharT>::type; + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI __format_to_n_buffer(_OutIt __out_it, iter_difference_t<_OutIt> __n) + : _Base{std::move(__out_it), std::addressof(__max_output_size_)}, + __max_output_size_{__n < 0 ? size_t{0} : static_cast(__n)} {} + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI auto __make_output_iterator() { return _Base::__make_output_iterator(); } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI format_to_n_result<_OutIt> __result() && { + return {static_cast<_Base&&>(*this).__out_it(), + static_cast>(__max_output_size_.__code_units_written())}; + } + +private: + __max_output_size __max_output_size_; +}; +// A buffer that counts the number of insertions. +// +// Since formatted_size only needs to know the size, the output itself is +// discarded. +template <__fmt_char_type _CharT> +class _LIBCPP_TEMPLATE_VIS __formatted_size_buffer : private __output_buffer<_CharT> { public: - _LIBCPP_HIDE_FROM_ABI explicit __format_to_n_buffer(_OutIt __out_it, _Size __max_size) - : _Base(std::move(__out_it), __max_size) {} - _LIBCPP_HIDE_FROM_ABI auto __make_output_iterator() { return this->__output_.__make_output_iterator(); } + using _Base _LIBCPP_NODEBUG = __output_buffer<_CharT>; + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI __formatted_size_buffer() + : _Base{nullptr, 0, __prepare_write, std::addressof(__max_output_size_)} {} + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI auto __make_output_iterator() { return _Base::__make_output_iterator(); } + + // This function does not need to be r-value qualified, however this is + // consistent with similar objects. + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI size_t __result() && { return __max_output_size_.__code_units_written(); } + +private: + __max_output_size __max_output_size_{0}; - _LIBCPP_HIDE_FROM_ABI format_to_n_result<_OutIt> __result() && { - this->__output_.__flush(); - return {std::move(this->__writer_).__out_it(), this->__size_}; + _LIBCPP_HIDE_FROM_ABI static void + __prepare_write([[maybe_unused]] __output_buffer<_CharT>& __buffer, [[maybe_unused]] size_t __size_hint) { + // Note this function does not satisfy the requirement of giving a 1 code unit buffer. + _LIBCPP_ASSERT_INTERNAL( + false, "Since __max_output_size_.__max_size_ == 0 there should never be call to this function."); } }; @@ -524,14 +578,14 @@ struct _LIBCPP_TEMPLATE_VIS __format_to_n_buffer final // would lead to a circular include with formatter for vector. template <__fmt_char_type _CharT> class _LIBCPP_TEMPLATE_VIS __retarget_buffer { - using _Alloc = allocator<_CharT>; + using _Alloc _LIBCPP_NODEBUG = allocator<_CharT>; public: - using value_type = _CharT; + using value_type _LIBCPP_NODEBUG = _CharT; struct __iterator { - using difference_type = ptrdiff_t; - using value_type = _CharT; + using difference_type _LIBCPP_NODEBUG = ptrdiff_t; + using value_type _LIBCPP_NODEBUG = _CharT; _LIBCPP_HIDE_FROM_ABI constexpr explicit __iterator(__retarget_buffer& __buffer) : __buffer_(std::addressof(__buffer)) {} @@ -646,7 +700,7 @@ class _LIBCPP_TEMPLATE_VIS __retarget_buffer { } // namespace __format -#endif //_LIBCPP_STD_VER >= 20 +#endif // _LIBCPP_STD_VER >= 20 _LIBCPP_END_NAMESPACE_STD diff --git a/system/lib/libcxx/include/__format/concepts.h b/system/lib/libcxx/include/__format/concepts.h index 13380e9b91aff..28297c612db77 100644 --- a/system/lib/libcxx/include/__format/concepts.h +++ b/system/lib/libcxx/include/__format/concepts.h @@ -34,7 +34,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template concept __fmt_char_type = same_as<_CharT, char> -# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +# if _LIBCPP_HAS_WIDE_CHARACTERS || same_as<_CharT, wchar_t> # endif ; @@ -44,7 +44,7 @@ concept __fmt_char_type = // (Note testing for (w)format_context would be a valid choice, but requires // selecting the proper one depending on the type of _CharT.) template -using __fmt_iter_for = _CharT*; +using __fmt_iter_for _LIBCPP_NODEBUG = _CharT*; template >> concept __formattable_with = @@ -75,8 +75,8 @@ template concept __fmt_pair_like = __is_specialization_v<_Tp, pair> || (__is_specialization_v<_Tp, tuple> && tuple_size_v<_Tp> == 2); -# endif //_LIBCPP_STD_VER >= 23 -#endif //_LIBCPP_STD_VER >= 20 +# endif // _LIBCPP_STD_VER >= 23 +#endif // _LIBCPP_STD_VER >= 20 _LIBCPP_END_NAMESPACE_STD diff --git a/system/lib/libcxx/include/__format/container_adaptor.h b/system/lib/libcxx/include/__format/container_adaptor.h index 9f49ca03bf4f5..48d42ee7d901b 100644 --- a/system/lib/libcxx/include/__format/container_adaptor.h +++ b/system/lib/libcxx/include/__format/container_adaptor.h @@ -37,8 +37,8 @@ _LIBCPP_BEGIN_NAMESPACE_STD template struct _LIBCPP_TEMPLATE_VIS __formatter_container_adaptor { private: - using __maybe_const_container = __fmt_maybe_const; - using __maybe_const_adaptor = __maybe_const, _Adaptor>; + using __maybe_const_container _LIBCPP_NODEBUG = __fmt_maybe_const; + using __maybe_const_adaptor _LIBCPP_NODEBUG = __maybe_const, _Adaptor>; formatter, _CharT> __underlying_; public: @@ -66,7 +66,7 @@ template _Container> struct _LIBCPP_TEMPLATE_VIS formatter, _CharT> : public __formatter_container_adaptor, _CharT> {}; -#endif //_LIBCPP_STD_VER >= 23 +#endif // _LIBCPP_STD_VER >= 23 _LIBCPP_END_NAMESPACE_STD diff --git a/system/lib/libcxx/include/__format/enable_insertable.h b/system/lib/libcxx/include/__format/enable_insertable.h index 86ef94a325b19..29fe566ff06a3 100644 --- a/system/lib/libcxx/include/__format/enable_insertable.h +++ b/system/lib/libcxx/include/__format/enable_insertable.h @@ -28,7 +28,7 @@ inline constexpr bool __enable_insertable = false; } // namespace __format -#endif //_LIBCPP_STD_VER >= 20 +#endif // _LIBCPP_STD_VER >= 20 _LIBCPP_END_NAMESPACE_STD diff --git a/system/lib/libcxx/include/__format/escaped_output_table.h b/system/lib/libcxx/include/__format/escaped_output_table.h index f7be2dc61f21a..7a0b35239861e 100644 --- a/system/lib/libcxx/include/__format/escaped_output_table.h +++ b/system/lib/libcxx/include/__format/escaped_output_table.h @@ -63,7 +63,7 @@ #include <__algorithm/ranges_upper_bound.h> #include <__config> -#include +#include <__cstddef/ptrdiff_t.h> #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -856,7 +856,7 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[711] = { // clang-format on } // namespace __escaped_output_table -#endif //_LIBCPP_STD_VER >= 23 +#endif // _LIBCPP_STD_VER >= 23 _LIBCPP_END_NAMESPACE_STD diff --git a/system/lib/libcxx/include/__format/extended_grapheme_cluster_table.h b/system/lib/libcxx/include/__format/extended_grapheme_cluster_table.h index 48581d8a5dde3..7653a9e03b815 100644 --- a/system/lib/libcxx/include/__format/extended_grapheme_cluster_table.h +++ b/system/lib/libcxx/include/__format/extended_grapheme_cluster_table.h @@ -63,8 +63,8 @@ #include <__algorithm/ranges_upper_bound.h> #include <__config> +#include <__cstddef/ptrdiff_t.h> #include <__iterator/access.h> -#include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -1656,7 +1656,7 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[1496] = { } // namespace __extended_grapheme_custer_property_boundary -#endif //_LIBCPP_STD_VER >= 20 +#endif // _LIBCPP_STD_VER >= 20 _LIBCPP_END_NAMESPACE_STD diff --git a/system/lib/libcxx/include/__format/format_arg.h b/system/lib/libcxx/include/__format/format_arg.h index aa02f81dc40e2..10f0ba9928ce7 100644 --- a/system/lib/libcxx/include/__format/format_arg.h +++ b/system/lib/libcxx/include/__format/format_arg.h @@ -13,6 +13,7 @@ #include <__assert> #include <__concepts/arithmetic.h> #include <__config> +#include <__cstddef/size_t.h> #include <__format/concepts.h> #include <__format/format_parse_context.h> #include <__functional/invoke.h> @@ -113,7 +114,7 @@ _LIBCPP_HIDE_FROM_ABI decltype(auto) __visit_format_arg(_Visitor&& __vis, basic_ case __format::__arg_t::__long_long: return std::invoke(std::forward<_Visitor>(__vis), __arg.__value_.__long_long_); case __format::__arg_t::__i128: -# ifndef _LIBCPP_HAS_NO_INT128 +# if _LIBCPP_HAS_INT128 return std::invoke(std::forward<_Visitor>(__vis), __arg.__value_.__i128_); # else __libcpp_unreachable(); @@ -123,7 +124,7 @@ _LIBCPP_HIDE_FROM_ABI decltype(auto) __visit_format_arg(_Visitor&& __vis, basic_ case __format::__arg_t::__unsigned_long_long: return std::invoke(std::forward<_Visitor>(__vis), __arg.__value_.__unsigned_long_long_); case __format::__arg_t::__u128: -# ifndef _LIBCPP_HAS_NO_INT128 +# if _LIBCPP_HAS_INT128 return std::invoke(std::forward<_Visitor>(__vis), __arg.__value_.__u128_); # else __libcpp_unreachable(); @@ -148,7 +149,7 @@ _LIBCPP_HIDE_FROM_ABI decltype(auto) __visit_format_arg(_Visitor&& __vis, basic_ __libcpp_unreachable(); } -# if _LIBCPP_STD_VER >= 26 && defined(_LIBCPP_HAS_EXPLICIT_THIS_PARAMETER) +# if _LIBCPP_STD_VER >= 26 && _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER template _LIBCPP_HIDE_FROM_ABI _Rp __visit_format_arg(_Visitor&& __vis, basic_format_arg<_Context> __arg) { @@ -164,7 +165,7 @@ _LIBCPP_HIDE_FROM_ABI _Rp __visit_format_arg(_Visitor&& __vis, basic_format_arg< case __format::__arg_t::__long_long: return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), __arg.__value_.__long_long_); case __format::__arg_t::__i128: -# ifndef _LIBCPP_HAS_NO_INT128 +# if _LIBCPP_HAS_INT128 return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), __arg.__value_.__i128_); # else __libcpp_unreachable(); @@ -174,7 +175,7 @@ _LIBCPP_HIDE_FROM_ABI _Rp __visit_format_arg(_Visitor&& __vis, basic_format_arg< case __format::__arg_t::__unsigned_long_long: return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), __arg.__value_.__unsigned_long_long_); case __format::__arg_t::__u128: -# ifndef _LIBCPP_HAS_NO_INT128 +# if _LIBCPP_HAS_INT128 return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), __arg.__value_.__u128_); # else __libcpp_unreachable(); @@ -199,7 +200,7 @@ _LIBCPP_HIDE_FROM_ABI _Rp __visit_format_arg(_Visitor&& __vis, basic_format_arg< __libcpp_unreachable(); } -# endif // _LIBCPP_STD_VER >= 26 && defined(_LIBCPP_HAS_EXPLICIT_THIS_PARAMETER) +# endif // _LIBCPP_STD_VER >= 26 && _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER /// Contains the values used in basic_format_arg. /// @@ -207,7 +208,7 @@ _LIBCPP_HIDE_FROM_ABI _Rp __visit_format_arg(_Visitor&& __vis, basic_format_arg< /// separate arrays. template class __basic_format_arg_value { - using _CharT = typename _Context::char_type; + using _CharT _LIBCPP_NODEBUG = typename _Context::char_type; public: /// Contains the implementation for basic_format_arg::handle. @@ -237,7 +238,7 @@ class __basic_format_arg_value { unsigned __unsigned_; long long __long_long_; unsigned long long __unsigned_long_long_; -# ifndef _LIBCPP_HAS_NO_INT128 +# if _LIBCPP_HAS_INT128 __int128_t __i128_; __uint128_t __u128_; # endif @@ -261,7 +262,7 @@ class __basic_format_arg_value { _LIBCPP_HIDE_FROM_ABI __basic_format_arg_value(long long __value) noexcept : __long_long_(__value) {} _LIBCPP_HIDE_FROM_ABI __basic_format_arg_value(unsigned long long __value) noexcept : __unsigned_long_long_(__value) {} -# ifndef _LIBCPP_HAS_NO_INT128 +# if _LIBCPP_HAS_INT128 _LIBCPP_HIDE_FROM_ABI __basic_format_arg_value(__int128_t __value) noexcept : __i128_(__value) {} _LIBCPP_HIDE_FROM_ABI __basic_format_arg_value(__uint128_t __value) noexcept : __u128_(__value) {} # endif @@ -276,7 +277,7 @@ class __basic_format_arg_value { }; template -class _LIBCPP_TEMPLATE_VIS basic_format_arg { +class _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS basic_format_arg { public: class _LIBCPP_TEMPLATE_VIS handle; @@ -284,14 +285,14 @@ class _LIBCPP_TEMPLATE_VIS basic_format_arg { _LIBCPP_HIDE_FROM_ABI explicit operator bool() const noexcept { return __type_ != __format::__arg_t::__none; } -# if _LIBCPP_STD_VER >= 26 && defined(_LIBCPP_HAS_EXPLICIT_THIS_PARAMETER) +# if _LIBCPP_STD_VER >= 26 && _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER // This function is user facing, so it must wrap the non-standard types of // the "variant" in a handle to stay conforming. See __arg_t for more details. template _LIBCPP_HIDE_FROM_ABI decltype(auto) visit(this basic_format_arg __arg, _Visitor&& __vis) { switch (__arg.__type_) { -# ifndef _LIBCPP_HAS_NO_INT128 +# if _LIBCPP_HAS_INT128 case __format::__arg_t::__i128: { typename __basic_format_arg_value<_Context>::__handle __h{__arg.__value_.__i128_}; return std::invoke(std::forward<_Visitor>(__vis), typename basic_format_arg<_Context>::handle{__h}); @@ -312,7 +313,7 @@ class _LIBCPP_TEMPLATE_VIS basic_format_arg { template _LIBCPP_HIDE_FROM_ABI _Rp visit(this basic_format_arg __arg, _Visitor&& __vis) { switch (__arg.__type_) { -# ifndef _LIBCPP_HAS_NO_INT128 +# if _LIBCPP_HAS_INT128 case __format::__arg_t::__i128: { typename __basic_format_arg_value<_Context>::__handle __h{__arg.__value_.__i128_}; return std::invoke_r<_Rp>(std::forward<_Visitor>(__vis), typename basic_format_arg<_Context>::handle{__h}); @@ -328,7 +329,7 @@ class _LIBCPP_TEMPLATE_VIS basic_format_arg { } } -# endif // _LIBCPP_STD_VER >= 26 && defined(_LIBCPP_HAS_EXPLICIT_THIS_PARAMETER) +# endif // _LIBCPP_STD_VER >= 26 && _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER private: using char_type = typename _Context::char_type; @@ -370,13 +371,13 @@ class _LIBCPP_TEMPLATE_VIS basic_format_arg<_Context>::handle { // This function is user facing, so it must wrap the non-standard types of // the "variant" in a handle to stay conforming. See __arg_t for more details. template -# if _LIBCPP_STD_VER >= 26 && defined(_LIBCPP_HAS_EXPLICIT_THIS_PARAMETER) +# if _LIBCPP_STD_VER >= 26 && _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER _LIBCPP_DEPRECATED_IN_CXX26 # endif _LIBCPP_HIDE_FROM_ABI decltype(auto) visit_format_arg(_Visitor&& __vis, basic_format_arg<_Context> __arg) { switch (__arg.__type_) { -# ifndef _LIBCPP_HAS_NO_INT128 +# if _LIBCPP_HAS_INT128 case __format::__arg_t::__i128: { typename __basic_format_arg_value<_Context>::__handle __h{__arg.__value_.__i128_}; return std::invoke(std::forward<_Visitor>(__vis), typename basic_format_arg<_Context>::handle{__h}); @@ -386,13 +387,13 @@ _LIBCPP_DEPRECATED_IN_CXX26 typename __basic_format_arg_value<_Context>::__handle __h{__arg.__value_.__u128_}; return std::invoke(std::forward<_Visitor>(__vis), typename basic_format_arg<_Context>::handle{__h}); } -# endif // _LIBCPP_STD_VER >= 26 && defined(_LIBCPP_HAS_EXPLICIT_THIS_PARAMETER) +# endif // _LIBCPP_STD_VER >= 26 && _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER default: return std::__visit_format_arg(std::forward<_Visitor>(__vis), __arg); } } -#endif //_LIBCPP_STD_VER >= 20 +#endif // _LIBCPP_STD_VER >= 20 _LIBCPP_END_NAMESPACE_STD diff --git a/system/lib/libcxx/include/__format/format_arg_store.h b/system/lib/libcxx/include/__format/format_arg_store.h index 23a599e995759..4c5ee9e9e4fd3 100644 --- a/system/lib/libcxx/include/__format/format_arg_store.h +++ b/system/lib/libcxx/include/__format/format_arg_store.h @@ -22,6 +22,7 @@ #include <__type_traits/conditional.h> #include <__type_traits/extent.h> #include <__type_traits/remove_const.h> +#include #include #include @@ -48,7 +49,7 @@ template _Tp> consteval __arg_t __determine_arg_t() { return __arg_t::__char_type; } -# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +# if _LIBCPP_HAS_WIDE_CHARACTERS template requires(same_as && same_as<_CharT, char>) consteval __arg_t __determine_arg_t() { @@ -63,7 +64,7 @@ consteval __arg_t __determine_arg_t() { return __arg_t::__int; else if constexpr (sizeof(_Tp) <= sizeof(long long)) return __arg_t::__long_long; -# ifndef _LIBCPP_HAS_NO_INT128 +# if _LIBCPP_HAS_INT128 else if constexpr (sizeof(_Tp) == sizeof(__int128_t)) return __arg_t::__i128; # endif @@ -78,7 +79,7 @@ consteval __arg_t __determine_arg_t() { return __arg_t::__unsigned; else if constexpr (sizeof(_Tp) <= sizeof(unsigned long long)) return __arg_t::__unsigned_long_long; -# ifndef _LIBCPP_HAS_NO_INT128 +# if _LIBCPP_HAS_INT128 else if constexpr (sizeof(_Tp) == sizeof(__uint128_t)) return __arg_t::__u128; # endif @@ -172,7 +173,7 @@ _LIBCPP_HIDE_FROM_ABI basic_format_arg<_Context> __create_format_arg(_Tp& __valu // final else requires no adjustment. if constexpr (__arg == __arg_t::__char_type) -# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +# if _LIBCPP_HAS_WIDE_CHARACTERS if constexpr (same_as && same_as<_Dp, char>) return basic_format_arg<_Context>{__arg, static_cast(static_cast(__value))}; else @@ -233,6 +234,11 @@ struct __packed_format_arg_store { uint64_t __types_ = 0; }; +template +struct __packed_format_arg_store<_Context, 0> { + uint64_t __types_ = 0; +}; + template struct __unpacked_format_arg_store { basic_format_arg<_Context> __args_[_Np]; @@ -251,7 +257,7 @@ struct _LIBCPP_TEMPLATE_VIS __format_arg_store { } } - using _Storage = + using _Storage _LIBCPP_NODEBUG = conditional_t<__format::__use_packed_format_arg_store(sizeof...(_Args)), __format::__packed_format_arg_store<_Context, sizeof...(_Args)>, __format::__unpacked_format_arg_store<_Context, sizeof...(_Args)>>; @@ -259,7 +265,7 @@ struct _LIBCPP_TEMPLATE_VIS __format_arg_store { _Storage __storage; }; -#endif //_LIBCPP_STD_VER >= 20 +#endif // _LIBCPP_STD_VER >= 20 _LIBCPP_END_NAMESPACE_STD diff --git a/system/lib/libcxx/include/__format/format_args.h b/system/lib/libcxx/include/__format/format_args.h index 07923570f3893..b98663c06ea4d 100644 --- a/system/lib/libcxx/include/__format/format_args.h +++ b/system/lib/libcxx/include/__format/format_args.h @@ -11,10 +11,10 @@ #define _LIBCPP___FORMAT_FORMAT_ARGS_H #include <__config> +#include <__cstddef/size_t.h> #include <__format/format_arg.h> #include <__format/format_arg_store.h> #include <__fwd/format.h> -#include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -71,7 +71,7 @@ class _LIBCPP_TEMPLATE_VIS basic_format_args { template basic_format_args(__format_arg_store<_Context, _Args...>) -> basic_format_args<_Context>; -#endif //_LIBCPP_STD_VER >= 20 +#endif // _LIBCPP_STD_VER >= 20 _LIBCPP_END_NAMESPACE_STD diff --git a/system/lib/libcxx/include/__format/format_context.h b/system/lib/libcxx/include/__format/format_context.h index 20c07559eae44..4dbfdbc02a267 100644 --- a/system/lib/libcxx/include/__format/format_context.h +++ b/system/lib/libcxx/include/__format/format_context.h @@ -23,9 +23,8 @@ #include <__memory/addressof.h> #include <__utility/move.h> #include <__variant/monostate.h> -#include -#ifndef _LIBCPP_HAS_NO_LOCALIZATION +#if _LIBCPP_HAS_LOCALIZATION # include <__locale> # include #endif @@ -45,7 +44,7 @@ template requires output_iterator<_OutIt, const _CharT&> class _LIBCPP_TEMPLATE_VIS basic_format_context; -# ifndef _LIBCPP_HAS_NO_LOCALIZATION +# if _LIBCPP_HAS_LOCALIZATION /** * Helper to create a basic_format_context. * @@ -67,7 +66,7 @@ __format_context_create(_OutIt __out_it, basic_format_args>, char>; -# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +# if _LIBCPP_HAS_WIDE_CHARACTERS using wformat_context = basic_format_context< back_insert_iterator<__format::__output_buffer>, wchar_t>; # endif @@ -89,7 +88,7 @@ class _LIBCPP_HIDE_FROM_ABI basic_format_arg arg(size_t __id) const noexcept { return __args_.get(__id); } -# ifndef _LIBCPP_HAS_NO_LOCALIZATION +# if _LIBCPP_HAS_LOCALIZATION _LIBCPP_HIDE_FROM_ABI std::locale locale() { if (!__loc_) __loc_ = std::locale{}; @@ -102,7 +101,7 @@ class private: iterator __out_it_; basic_format_args __args_; -# ifndef _LIBCPP_HAS_NO_LOCALIZATION +# if _LIBCPP_HAS_LOCALIZATION // The Standard doesn't specify how the locale is stored. // [format.context]/6 @@ -132,6 +131,7 @@ class : __out_it_(std::move(__out_it)), __args_(__args) {} # endif +public: basic_format_context(const basic_format_context&) = delete; basic_format_context& operator=(const basic_format_context&) = delete; }; @@ -163,7 +163,7 @@ class _LIBCPP_TEMPLATE_VIS basic_format_context _LIBCPP_HIDE_FROM_ABI explicit basic_format_context(iterator __out_it, _Context& __ctx) : __out_it_(std::move(__out_it)), -# ifndef _LIBCPP_HAS_NO_LOCALIZATION +# if _LIBCPP_HAS_LOCALIZATION __loc_([](void* __c) { return static_cast<_Context*>(__c)->locale(); }), # endif __ctx_(std::addressof(__ctx)), @@ -180,20 +180,20 @@ class _LIBCPP_TEMPLATE_VIS basic_format_context(), __basic_format_arg_value(__arg)}; }; -# if _LIBCPP_STD_VER >= 26 && defined(_LIBCPP_HAS_EXPLICIT_THIS_PARAMETER) +# if _LIBCPP_STD_VER >= 26 && _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER return static_cast<_Context*>(__c)->arg(__id).visit(std::move(__visitor)); # else _LIBCPP_SUPPRESS_DEPRECATED_PUSH return std::visit_format_arg(std::move(__visitor), static_cast<_Context*>(__c)->arg(__id)); _LIBCPP_SUPPRESS_DEPRECATED_POP -# endif // _LIBCPP_STD_VER >= 26 && defined(_LIBCPP_HAS_EXPLICIT_THIS_PARAMETER) +# endif // _LIBCPP_STD_VER >= 26 && _LIBCPP_HAS_EXPLICIT_THIS_PARAMETER }) { } _LIBCPP_HIDE_FROM_ABI basic_format_arg arg(size_t __id) const noexcept { return __arg_(__ctx_, __id); } -# ifndef _LIBCPP_HAS_NO_LOCALIZATION +# if _LIBCPP_HAS_LOCALIZATION _LIBCPP_HIDE_FROM_ABI std::locale locale() { return __loc_(__ctx_); } # endif _LIBCPP_HIDE_FROM_ABI iterator out() { return std::move(__out_it_); } @@ -202,7 +202,7 @@ class _LIBCPP_TEMPLATE_VIS basic_format_context= 20 +#endif // _LIBCPP_STD_VER >= 20 _LIBCPP_END_NAMESPACE_STD diff --git a/system/lib/libcxx/include/__format/format_error.h b/system/lib/libcxx/include/__format/format_error.h index ed40e395d6af7..b92e6d1de00e2 100644 --- a/system/lib/libcxx/include/__format/format_error.h +++ b/system/lib/libcxx/include/__format/format_error.h @@ -35,15 +35,15 @@ class _LIBCPP_EXPORTED_FROM_ABI format_error : public runtime_error { }; _LIBCPP_DIAGNOSTIC_POP -_LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI void __throw_format_error(const char* __s) { -# ifndef _LIBCPP_HAS_NO_EXCEPTIONS +[[noreturn]] inline _LIBCPP_HIDE_FROM_ABI void __throw_format_error(const char* __s) { +# if _LIBCPP_HAS_EXCEPTIONS throw format_error(__s); # else _LIBCPP_VERBOSE_ABORT("format_error was thrown in -fno-exceptions mode with message \"%s\"", __s); # endif } -#endif //_LIBCPP_STD_VER >= 20 +#endif // _LIBCPP_STD_VER >= 20 _LIBCPP_END_NAMESPACE_STD diff --git a/system/lib/libcxx/include/__format/format_functions.h b/system/lib/libcxx/include/__format/format_functions.h index d14b49aff1495..5feaf7e5a064a 100644 --- a/system/lib/libcxx/include/__format/format_functions.h +++ b/system/lib/libcxx/include/__format/format_functions.h @@ -31,7 +31,6 @@ #include <__format/formatter_pointer.h> #include <__format/formatter_string.h> #include <__format/parser_std_format_spec.h> -#include <__iterator/back_insert_iterator.h> #include <__iterator/concepts.h> #include <__iterator/incrementable_traits.h> #include <__iterator/iterator_traits.h> // iter_value_t @@ -40,7 +39,7 @@ #include #include -#ifndef _LIBCPP_HAS_NO_LOCALIZATION +#if _LIBCPP_HAS_LOCALIZATION # include <__locale> #endif @@ -61,7 +60,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD // to do this optimization now. using format_args = basic_format_args; -# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +# if _LIBCPP_HAS_WIDE_CHARACTERS using wformat_args = basic_format_args; # endif @@ -70,7 +69,7 @@ template return std::__format_arg_store<_Context, _Args...>(__args...); } -# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +# if _LIBCPP_HAS_WIDE_CHARACTERS template [[nodiscard]] _LIBCPP_HIDE_FROM_ABI __format_arg_store make_wformat_args(_Args&... __args) { return std::__format_arg_store(__args...); @@ -206,7 +205,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr void __compile_time_visit_format_arg( case __arg_t::__long_long: return __format::__compile_time_validate_argument<_CharT, long long>(__parse_ctx, __ctx); case __arg_t::__i128: -# ifndef _LIBCPP_HAS_NO_INT128 +# if _LIBCPP_HAS_INT128 return __format::__compile_time_validate_argument<_CharT, __int128_t>(__parse_ctx, __ctx); # else std::__throw_format_error("Invalid argument"); @@ -217,7 +216,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr void __compile_time_visit_format_arg( case __arg_t::__unsigned_long_long: return __format::__compile_time_validate_argument<_CharT, unsigned long long>(__parse_ctx, __ctx); case __arg_t::__u128: -# ifndef _LIBCPP_HAS_NO_INT128 +# if _LIBCPP_HAS_INT128 return __format::__compile_time_validate_argument<_CharT, __uint128_t>(__parse_ctx, __ctx); # else std::__throw_format_error("Invalid argument"); @@ -355,12 +354,12 @@ struct _LIBCPP_TEMPLATE_VIS __runtime_format_string { }; _LIBCPP_HIDE_FROM_ABI inline __runtime_format_string runtime_format(string_view __fmt) noexcept { return __fmt; } -# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +# if _LIBCPP_HAS_WIDE_CHARACTERS _LIBCPP_HIDE_FROM_ABI inline __runtime_format_string runtime_format(wstring_view __fmt) noexcept { return __fmt; } # endif -# endif //_LIBCPP_STD_VER >= 26 +# endif // _LIBCPP_STD_VER >= 26 template struct _LIBCPP_TEMPLATE_VIS basic_format_string { @@ -379,7 +378,7 @@ struct _LIBCPP_TEMPLATE_VIS basic_format_string { private: basic_string_view<_CharT> __str_; - using _Context = __format::__compile_time_basic_format_context<_CharT>; + using _Context _LIBCPP_NODEBUG = __format::__compile_time_basic_format_context<_CharT>; static constexpr array<__format::__arg_t, sizeof...(_Args)> __types_{ __format::__determine_arg_t<_Context, remove_cvref_t<_Args>>()...}; @@ -397,7 +396,7 @@ struct _LIBCPP_TEMPLATE_VIS basic_format_string { template using format_string = basic_format_string...>; -# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +# if _LIBCPP_HAS_WIDE_CHARACTERS template using wformat_string = basic_format_string...>; # endif @@ -411,7 +410,7 @@ _LIBCPP_HIDE_FROM_ABI _OutIt __vformat_to(_OutIt __out_it, return std::__format::__vformat_to( basic_format_parse_context{__fmt, __args.__size()}, std::__format_context_create(std::move(__out_it), __args)); else { - __format::__format_buffer<_OutIt, _CharT> __buffer{std::move(__out_it)}; + typename __format::__buffer_selector<_OutIt, _CharT>::type __buffer{std::move(__out_it)}; std::__format::__vformat_to(basic_format_parse_context{__fmt, __args.__size()}, std::__format_context_create(__buffer.__make_output_iterator(), __args)); return std::move(__buffer).__out_it(); @@ -426,7 +425,7 @@ _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _OutIt vformat_to(_OutIt __out_it, s return std::__vformat_to(std::move(__out_it), __fmt, __args); } -# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +# if _LIBCPP_HAS_WIDE_CHARACTERS template _OutIt> _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _OutIt vformat_to(_OutIt __out_it, wstring_view __fmt, wformat_args __args) { @@ -440,7 +439,7 @@ format_to(_OutIt __out_it, format_string<_Args...> __fmt, _Args&&... __args) { return std::vformat_to(std::move(__out_it), __fmt.get(), std::make_format_args(__args...)); } -# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +# if _LIBCPP_HAS_WIDE_CHARACTERS template _OutIt, class... _Args> _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _OutIt format_to(_OutIt __out_it, wformat_string<_Args...> __fmt, _Args&&... __args) { @@ -452,20 +451,20 @@ format_to(_OutIt __out_it, wformat_string<_Args...> __fmt, _Args&&... __args) { // fires too eagerly, see http://llvm.org/PR61563. template [[nodiscard]] _LIBCPP_ALWAYS_INLINE inline _LIBCPP_HIDE_FROM_ABI string vformat(string_view __fmt, format_args __args) { - string __res; - std::vformat_to(std::back_inserter(__res), __fmt, __args); - return __res; + __format::__allocating_buffer __buffer; + std::vformat_to(__buffer.__make_output_iterator(), __fmt, __args); + return string{__buffer.__view()}; } -# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +# if _LIBCPP_HAS_WIDE_CHARACTERS // TODO FMT This needs to be a template or std::to_chars(floating-point) availability markup // fires too eagerly, see http://llvm.org/PR61563. template [[nodiscard]] _LIBCPP_ALWAYS_INLINE inline _LIBCPP_HIDE_FROM_ABI wstring vformat(wstring_view __fmt, wformat_args __args) { - wstring __res; - std::vformat_to(std::back_inserter(__res), __fmt, __args); - return __res; + __format::__allocating_buffer __buffer; + std::vformat_to(__buffer.__make_output_iterator(), __fmt, __args); + return wstring{__buffer.__view()}; } # endif @@ -475,7 +474,7 @@ format(format_string<_Args...> __fmt, _Args&&... __args) { return std::vformat(__fmt.get(), std::make_format_args(__args...)); } -# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +# if _LIBCPP_HAS_WIDE_CHARACTERS template [[nodiscard]] _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI wstring format(wformat_string<_Args...> __fmt, _Args&&... __args) { @@ -501,7 +500,7 @@ format_to_n(_OutIt __out_it, iter_difference_t<_OutIt> __n, format_string<_Args. return std::__vformat_to_n(std::move(__out_it), __n, __fmt.get(), std::make_format_args(__args...)); } -# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +# if _LIBCPP_HAS_WIDE_CHARACTERS template _OutIt, class... _Args> _LIBCPP_HIDE_FROM_ABI format_to_n_result<_OutIt> format_to_n(_OutIt __out_it, iter_difference_t<_OutIt> __n, wformat_string<_Args...> __fmt, _Args&&... __args) { @@ -523,7 +522,7 @@ formatted_size(format_string<_Args...> __fmt, _Args&&... __args) { return std::__vformatted_size(__fmt.get(), basic_format_args{std::make_format_args(__args...)}); } -# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +# if _LIBCPP_HAS_WIDE_CHARACTERS template [[nodiscard]] _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI size_t formatted_size(wformat_string<_Args...> __fmt, _Args&&... __args) { @@ -531,7 +530,7 @@ formatted_size(wformat_string<_Args...> __fmt, _Args&&... __args) { } # endif -# ifndef _LIBCPP_HAS_NO_LOCALIZATION +# if _LIBCPP_HAS_LOCALIZATION template requires(output_iterator<_OutIt, const _CharT&>) @@ -544,7 +543,7 @@ _LIBCPP_HIDE_FROM_ABI _OutIt __vformat_to( return std::__format::__vformat_to(basic_format_parse_context{__fmt, __args.__size()}, std::__format_context_create(std::move(__out_it), __args, std::move(__loc))); else { - __format::__format_buffer<_OutIt, _CharT> __buffer{std::move(__out_it)}; + typename __format::__buffer_selector<_OutIt, _CharT>::type __buffer{std::move(__out_it)}; std::__format::__vformat_to( basic_format_parse_context{__fmt, __args.__size()}, std::__format_context_create(__buffer.__make_output_iterator(), __args, std::move(__loc))); @@ -558,7 +557,7 @@ vformat_to(_OutIt __out_it, locale __loc, string_view __fmt, format_args __args) return std::__vformat_to(std::move(__out_it), std::move(__loc), __fmt, __args); } -# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +# if _LIBCPP_HAS_WIDE_CHARACTERS template _OutIt> _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _OutIt vformat_to(_OutIt __out_it, locale __loc, wstring_view __fmt, wformat_args __args) { @@ -572,7 +571,7 @@ format_to(_OutIt __out_it, locale __loc, format_string<_Args...> __fmt, _Args&&. return std::vformat_to(std::move(__out_it), std::move(__loc), __fmt.get(), std::make_format_args(__args...)); } -# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +# if _LIBCPP_HAS_WIDE_CHARACTERS template _OutIt, class... _Args> _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _OutIt format_to(_OutIt __out_it, locale __loc, wformat_string<_Args...> __fmt, _Args&&... __args) { @@ -585,20 +584,20 @@ format_to(_OutIt __out_it, locale __loc, wformat_string<_Args...> __fmt, _Args&& template [[nodiscard]] _LIBCPP_ALWAYS_INLINE inline _LIBCPP_HIDE_FROM_ABI string vformat(locale __loc, string_view __fmt, format_args __args) { - string __res; - std::vformat_to(std::back_inserter(__res), std::move(__loc), __fmt, __args); - return __res; + __format::__allocating_buffer __buffer; + std::vformat_to(__buffer.__make_output_iterator(), std::move(__loc), __fmt, __args); + return string{__buffer.__view()}; } -# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +# if _LIBCPP_HAS_WIDE_CHARACTERS // TODO FMT This needs to be a template or std::to_chars(floating-point) availability markup // fires too eagerly, see http://llvm.org/PR61563. template [[nodiscard]] _LIBCPP_ALWAYS_INLINE inline _LIBCPP_HIDE_FROM_ABI wstring vformat(locale __loc, wstring_view __fmt, wformat_args __args) { - wstring __res; - std::vformat_to(std::back_inserter(__res), std::move(__loc), __fmt, __args); - return __res; + __format::__allocating_buffer __buffer; + std::vformat_to(__buffer.__make_output_iterator(), std::move(__loc), __fmt, __args); + return wstring{__buffer.__view()}; } # endif @@ -608,7 +607,7 @@ format(locale __loc, format_string<_Args...> __fmt, _Args&&... __args) { return std::vformat(std::move(__loc), __fmt.get(), std::make_format_args(__args...)); } -# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +# if _LIBCPP_HAS_WIDE_CHARACTERS template [[nodiscard]] _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI wstring format(locale __loc, wformat_string<_Args...> __fmt, _Args&&... __args) { @@ -637,7 +636,7 @@ _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI format_to_n_result<_OutIt> format_to std::move(__out_it), __n, std::move(__loc), __fmt.get(), std::make_format_args(__args...)); } -# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +# if _LIBCPP_HAS_WIDE_CHARACTERS template _OutIt, class... _Args> _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI format_to_n_result<_OutIt> format_to_n( _OutIt __out_it, iter_difference_t<_OutIt> __n, locale __loc, wformat_string<_Args...> __fmt, _Args&&... __args) { @@ -661,7 +660,7 @@ formatted_size(locale __loc, format_string<_Args...> __fmt, _Args&&... __args) { return std::__vformatted_size(std::move(__loc), __fmt.get(), basic_format_args{std::make_format_args(__args...)}); } -# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +# if _LIBCPP_HAS_WIDE_CHARACTERS template [[nodiscard]] _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI size_t formatted_size(locale __loc, wformat_string<_Args...> __fmt, _Args&&... __args) { @@ -669,9 +668,9 @@ formatted_size(locale __loc, wformat_string<_Args...> __fmt, _Args&&... __args) } # endif -# endif // _LIBCPP_HAS_NO_LOCALIZATION +# endif // _LIBCPP_HAS_LOCALIZATION -#endif //_LIBCPP_STD_VER >= 20 +#endif // _LIBCPP_STD_VER >= 20 _LIBCPP_END_NAMESPACE_STD diff --git a/system/lib/libcxx/include/__format/format_parse_context.h b/system/lib/libcxx/include/__format/format_parse_context.h index aefcd5497f3b9..459db751c9df0 100644 --- a/system/lib/libcxx/include/__format/format_parse_context.h +++ b/system/lib/libcxx/include/__format/format_parse_context.h @@ -94,11 +94,11 @@ class _LIBCPP_TEMPLATE_VIS basic_format_parse_context { _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(basic_format_parse_context); using format_parse_context = basic_format_parse_context; -# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +# if _LIBCPP_HAS_WIDE_CHARACTERS using wformat_parse_context = basic_format_parse_context; # endif -#endif //_LIBCPP_STD_VER >= 20 +#endif // _LIBCPP_STD_VER >= 20 _LIBCPP_END_NAMESPACE_STD diff --git a/system/lib/libcxx/include/__format/format_string.h b/system/lib/libcxx/include/__format/format_string.h index bdf3cff7f49b1..5db5973dd5889 100644 --- a/system/lib/libcxx/include/__format/format_string.h +++ b/system/lib/libcxx/include/__format/format_string.h @@ -12,10 +12,10 @@ #include <__assert> #include <__config> +#include <__cstddef/size_t.h> #include <__format/format_error.h> #include <__iterator/concepts.h> #include <__iterator/iterator_traits.h> // iter_value_t -#include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -153,7 +153,7 @@ __parse_arg_id(_Iterator __begin, _Iterator __end, auto& __parse_ctx) { } // namespace __format -#endif //_LIBCPP_STD_VER >= 20 +#endif // _LIBCPP_STD_VER >= 20 _LIBCPP_END_NAMESPACE_STD diff --git a/system/lib/libcxx/include/__format/format_to_n_result.h b/system/lib/libcxx/include/__format/format_to_n_result.h index 6f30546dec081..344299e32f0ee 100644 --- a/system/lib/libcxx/include/__format/format_to_n_result.h +++ b/system/lib/libcxx/include/__format/format_to_n_result.h @@ -28,7 +28,7 @@ struct _LIBCPP_TEMPLATE_VIS format_to_n_result { }; _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(format_to_n_result); -#endif //_LIBCPP_STD_VER >= 20 +#endif // _LIBCPP_STD_VER >= 20 _LIBCPP_END_NAMESPACE_STD diff --git a/system/lib/libcxx/include/__format/formatter.h b/system/lib/libcxx/include/__format/formatter.h index e2f418f936ee1..39c2670dd8431 100644 --- a/system/lib/libcxx/include/__format/formatter.h +++ b/system/lib/libcxx/include/__format/formatter.h @@ -39,6 +39,9 @@ struct _LIBCPP_TEMPLATE_VIS formatter { # if _LIBCPP_STD_VER >= 23 +template +constexpr bool enable_nonlocking_formatter_optimization = false; + template _LIBCPP_HIDE_FROM_ABI constexpr void __set_debug_format(_Tp& __formatter) { if constexpr (requires { __formatter.set_debug_format(); }) diff --git a/system/lib/libcxx/include/__format/formatter_bool.h b/system/lib/libcxx/include/__format/formatter_bool.h index 17dc69541e8fe..d08acd474439c 100644 --- a/system/lib/libcxx/include/__format/formatter_bool.h +++ b/system/lib/libcxx/include/__format/formatter_bool.h @@ -20,7 +20,7 @@ #include <__format/parser_std_format_spec.h> #include <__utility/unreachable.h> -#ifndef _LIBCPP_HAS_NO_LOCALIZATION +#if _LIBCPP_HAS_LOCALIZATION # include <__locale> #endif @@ -69,7 +69,11 @@ struct _LIBCPP_TEMPLATE_VIS formatter { __format_spec::__parser<_CharT> __parser_; }; -#endif //_LIBCPP_STD_VER >= 20 +# if _LIBCPP_STD_VER >= 23 +template <> +inline constexpr bool enable_nonlocking_formatter_optimization = true; +# endif // _LIBCPP_STD_VER >= 23 +#endif // _LIBCPP_STD_VER >= 20 _LIBCPP_END_NAMESPACE_STD diff --git a/system/lib/libcxx/include/__format/formatter_char.h b/system/lib/libcxx/include/__format/formatter_char.h index d33e84368a765..8b8fd2d42c9f3 100644 --- a/system/lib/libcxx/include/__format/formatter_char.h +++ b/system/lib/libcxx/include/__format/formatter_char.h @@ -77,16 +77,24 @@ struct _LIBCPP_TEMPLATE_VIS __formatter_char { template <> struct _LIBCPP_TEMPLATE_VIS formatter : public __formatter_char {}; -# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +# if _LIBCPP_HAS_WIDE_CHARACTERS template <> struct _LIBCPP_TEMPLATE_VIS formatter : public __formatter_char {}; template <> struct _LIBCPP_TEMPLATE_VIS formatter : public __formatter_char {}; +# endif // _LIBCPP_HAS_WIDE_CHARACTERS -# endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS +# if _LIBCPP_STD_VER >= 23 +template <> +inline constexpr bool enable_nonlocking_formatter_optimization = true; +# if _LIBCPP_HAS_WIDE_CHARACTERS +template <> +inline constexpr bool enable_nonlocking_formatter_optimization = true; +# endif // _LIBCPP_HAS_WIDE_CHARACTERS +# endif // _LIBCPP_STD_VER >= 23 -#endif //_LIBCPP_STD_VER >= 20 +#endif // _LIBCPP_STD_VER >= 20 _LIBCPP_END_NAMESPACE_STD diff --git a/system/lib/libcxx/include/__format/formatter_floating_point.h b/system/lib/libcxx/include/__format/formatter_floating_point.h index fa42ba203b0b5..ac4be9b619355 100644 --- a/system/lib/libcxx/include/__format/formatter_floating_point.h +++ b/system/lib/libcxx/include/__format/formatter_floating_point.h @@ -23,6 +23,7 @@ #include <__concepts/arithmetic.h> #include <__concepts/same_as.h> #include <__config> +#include <__cstddef/ptrdiff_t.h> #include <__format/concepts.h> #include <__format/format_parse_context.h> #include <__format/formatter.h> @@ -36,9 +37,8 @@ #include <__utility/move.h> #include <__utility/unreachable.h> #include -#include -#ifndef _LIBCPP_HAS_NO_LOCALIZATION +#if _LIBCPP_HAS_LOCALIZATION # include <__locale> #endif @@ -141,7 +141,7 @@ struct __traits { /// on the stack or the heap. template class _LIBCPP_TEMPLATE_VIS __float_buffer { - using _Traits = __traits<_Fp>; + using _Traits _LIBCPP_NODEBUG = __traits<_Fp>; public: // TODO FMT Improve this constructor to do a better estimate. @@ -491,7 +491,7 @@ _LIBCPP_HIDE_FROM_ABI __float_result __format_buffer( } } -# ifndef _LIBCPP_HAS_NO_LOCALIZATION +# if _LIBCPP_HAS_LOCALIZATION template _LIBCPP_HIDE_FROM_ABI _OutIt __format_locale_specific_form( _OutIt __out_it, @@ -576,7 +576,7 @@ _LIBCPP_HIDE_FROM_ABI _OutIt __format_locale_specific_form( // alignment return __formatter::__fill(std::move(__out_it), __padding.__after_, __specs.__fill_); } -# endif // _LIBCPP_HAS_NO_LOCALIZATION +# endif // _LIBCPP_HAS_LOCALIZATION template _LIBCPP_HIDE_FROM_ABI _OutIt __format_floating_point_non_finite( @@ -705,7 +705,7 @@ __format_floating_point(_Tp __value, _FormatContext& __ctx, __format_spec::__par } } -# ifndef _LIBCPP_HAS_NO_LOCALIZATION +# if _LIBCPP_HAS_LOCALIZATION if (__specs.__std_.__locale_specific_form_) return __formatter::__format_locale_specific_form(__ctx.out(), __buffer, __result, __ctx.locale(), __specs); # endif @@ -774,7 +774,15 @@ struct _LIBCPP_TEMPLATE_VIS formatter : public __formatter_float template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS formatter : public __formatter_floating_point<_CharT> {}; -#endif //_LIBCPP_STD_VER >= 20 +# if _LIBCPP_STD_VER >= 23 +template <> +inline constexpr bool enable_nonlocking_formatter_optimization = true; +template <> +inline constexpr bool enable_nonlocking_formatter_optimization = true; +template <> +inline constexpr bool enable_nonlocking_formatter_optimization = true; +# endif // _LIBCPP_STD_VER >= 23 +#endif // _LIBCPP_STD_VER >= 20 _LIBCPP_END_NAMESPACE_STD diff --git a/system/lib/libcxx/include/__format/formatter_integer.h b/system/lib/libcxx/include/__format/formatter_integer.h index 41400f00478eb..3f51b10d75aac 100644 --- a/system/lib/libcxx/include/__format/formatter_integer.h +++ b/system/lib/libcxx/include/__format/formatter_integer.h @@ -67,7 +67,7 @@ template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS formatter : public __formatter_integer<_CharT> {}; template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS formatter : public __formatter_integer<_CharT> {}; -# ifndef _LIBCPP_HAS_NO_INT128 +# if _LIBCPP_HAS_INT128 template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS formatter<__int128_t, _CharT> : public __formatter_integer<_CharT> {}; # endif @@ -83,12 +83,43 @@ template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS formatter : public __formatter_integer<_CharT> {}; template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS formatter : public __formatter_integer<_CharT> {}; -# ifndef _LIBCPP_HAS_NO_INT128 +# if _LIBCPP_HAS_INT128 template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS formatter<__uint128_t, _CharT> : public __formatter_integer<_CharT> {}; # endif -#endif //_LIBCPP_STD_VER >= 20 +# if _LIBCPP_STD_VER >= 23 +template <> +inline constexpr bool enable_nonlocking_formatter_optimization = true; +template <> +inline constexpr bool enable_nonlocking_formatter_optimization = true; +template <> +inline constexpr bool enable_nonlocking_formatter_optimization = true; +template <> +inline constexpr bool enable_nonlocking_formatter_optimization = true; +template <> +inline constexpr bool enable_nonlocking_formatter_optimization = true; +# if _LIBCPP_HAS_INT128 +template <> +inline constexpr bool enable_nonlocking_formatter_optimization<__int128_t> = true; +# endif + +template <> +inline constexpr bool enable_nonlocking_formatter_optimization = true; +template <> +inline constexpr bool enable_nonlocking_formatter_optimization = true; +template <> +inline constexpr bool enable_nonlocking_formatter_optimization = true; +template <> +inline constexpr bool enable_nonlocking_formatter_optimization = true; +template <> +inline constexpr bool enable_nonlocking_formatter_optimization = true; +# if _LIBCPP_HAS_INT128 +template <> +inline constexpr bool enable_nonlocking_formatter_optimization<__uint128_t> = true; +# endif +# endif // _LIBCPP_STD_VER >= 23 +#endif // _LIBCPP_STD_VER >= 20 _LIBCPP_END_NAMESPACE_STD diff --git a/system/lib/libcxx/include/__format/formatter_integral.h b/system/lib/libcxx/include/__format/formatter_integral.h index eca966f8886f8..996b7620b3e3f 100644 --- a/system/lib/libcxx/include/__format/formatter_integral.h +++ b/system/lib/libcxx/include/__format/formatter_integral.h @@ -27,11 +27,12 @@ #include <__type_traits/make_unsigned.h> #include <__utility/unreachable.h> #include +#include #include #include #include -#ifndef _LIBCPP_HAS_NO_LOCALIZATION +#if _LIBCPP_HAS_LOCALIZATION # include <__locale> #endif @@ -297,7 +298,7 @@ _LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator __format_integer( _Iterator __last = __formatter::__to_buffer(__first, __end, __value, __base); -# ifndef _LIBCPP_HAS_NO_LOCALIZATION +# if _LIBCPP_HAS_LOCALIZATION if (__specs.__std_.__locale_specific_form_) { const auto& __np = std::use_facet>(__ctx.locale()); string __grouping = __np.grouping(); @@ -411,7 +412,7 @@ struct _LIBCPP_TEMPLATE_VIS __bool_strings { static constexpr string_view __false{"false"}; }; -# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +# if _LIBCPP_HAS_WIDE_CHARACTERS template <> struct _LIBCPP_TEMPLATE_VIS __bool_strings { static constexpr wstring_view __true{L"true"}; @@ -422,7 +423,7 @@ struct _LIBCPP_TEMPLATE_VIS __bool_strings { template _LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator __format_bool(bool __value, _FormatContext& __ctx, __format_spec::__parsed_specifications<_CharT> __specs) { -# ifndef _LIBCPP_HAS_NO_LOCALIZATION +# if _LIBCPP_HAS_LOCALIZATION if (__specs.__std_.__locale_specific_form_) { const auto& __np = std::use_facet>(__ctx.locale()); basic_string<_CharT> __str = __value ? __np.truename() : __np.falsename(); @@ -436,7 +437,7 @@ __format_bool(bool __value, _FormatContext& __ctx, __format_spec::__parsed_speci } // namespace __formatter -#endif //_LIBCPP_STD_VER >= 20 +#endif // _LIBCPP_STD_VER >= 20 _LIBCPP_END_NAMESPACE_STD diff --git a/system/lib/libcxx/include/__format/formatter_output.h b/system/lib/libcxx/include/__format/formatter_output.h index 1498f64c4aeff..e1f1309cd2c53 100644 --- a/system/lib/libcxx/include/__format/formatter_output.h +++ b/system/lib/libcxx/include/__format/formatter_output.h @@ -16,6 +16,8 @@ #include <__bit/countl.h> #include <__concepts/same_as.h> #include <__config> +#include <__cstddef/ptrdiff_t.h> +#include <__cstddef/size_t.h> #include <__format/buffer.h> #include <__format/concepts.h> #include <__format/formatter.h> @@ -28,7 +30,6 @@ #include <__memory/pointer_traits.h> #include <__utility/move.h> #include <__utility/unreachable.h> -#include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -168,7 +169,7 @@ _LIBCPP_HIDE_FROM_ABI _OutIt __fill(_OutIt __out_it, size_t __n, _CharT __value) } } -# ifndef _LIBCPP_HAS_NO_UNICODE +# if _LIBCPP_HAS_UNICODE template <__fmt_char_type _CharT, output_iterator _OutIt> requires(same_as<_CharT, char>) _LIBCPP_HIDE_FROM_ABI _OutIt __fill(_OutIt __out_it, size_t __n, __format_spec::__code_point<_CharT> __value) { @@ -182,7 +183,7 @@ _LIBCPP_HIDE_FROM_ABI _OutIt __fill(_OutIt __out_it, size_t __n, __format_spec:: return __out_it; } -# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +# if _LIBCPP_HAS_WIDE_CHARACTERS template <__fmt_char_type _CharT, output_iterator _OutIt> requires(same_as<_CharT, wchar_t> && sizeof(wchar_t) == 2) _LIBCPP_HIDE_FROM_ABI _OutIt __fill(_OutIt __out_it, size_t __n, __format_spec::__code_point<_CharT> __value) { @@ -200,13 +201,13 @@ template <__fmt_char_type _CharT, output_iterator _OutIt> _LIBCPP_HIDE_FROM_ABI _OutIt __fill(_OutIt __out_it, size_t __n, __format_spec::__code_point<_CharT> __value) { return __formatter::__fill(std::move(__out_it), __n, __value.__data[0]); } -# endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS -# else // _LIBCPP_HAS_NO_UNICODE +# endif // _LIBCPP_HAS_WIDE_CHARACTERS +# else // _LIBCPP_HAS_UNICODE template <__fmt_char_type _CharT, output_iterator _OutIt> _LIBCPP_HIDE_FROM_ABI _OutIt __fill(_OutIt __out_it, size_t __n, __format_spec::__code_point<_CharT> __value) { return __formatter::__fill(std::move(__out_it), __n, __value.__data[0]); } -# endif // _LIBCPP_HAS_NO_UNICODE +# endif // _LIBCPP_HAS_UNICODE /// Writes the input to the output with the required padding. /// @@ -294,8 +295,7 @@ _LIBCPP_HIDE_FROM_ABI auto __write_transformed( /// /// \pre !__specs.__has_precision() /// -/// \note When \c _LIBCPP_HAS_NO_UNICODE is defined the function assumes the -/// input is ASCII. +/// \note When \c _LIBCPP_HAS_UNICODE is false the function assumes the input is ASCII. template _LIBCPP_HIDE_FROM_ABI auto __write_string_no_precision( basic_string_view<_CharT> __str, @@ -326,7 +326,7 @@ _LIBCPP_HIDE_FROM_ABI int __truncate(basic_string_view<_CharT>& __str, int __pre } // namespace __formatter -#endif //_LIBCPP_STD_VER >= 20 +#endif // _LIBCPP_STD_VER >= 20 _LIBCPP_END_NAMESPACE_STD diff --git a/system/lib/libcxx/include/__format/formatter_pointer.h b/system/lib/libcxx/include/__format/formatter_pointer.h index 6941343efd91f..4ef48c168d0d8 100644 --- a/system/lib/libcxx/include/__format/formatter_pointer.h +++ b/system/lib/libcxx/include/__format/formatter_pointer.h @@ -11,13 +11,13 @@ #define _LIBCPP___FORMAT_FORMATTER_POINTER_H #include <__config> +#include <__cstddef/nullptr_t.h> #include <__format/concepts.h> #include <__format/format_parse_context.h> #include <__format/formatter.h> #include <__format/formatter_integral.h> #include <__format/formatter_output.h> #include <__format/parser_std_format_spec.h> -#include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -65,7 +65,15 @@ struct _LIBCPP_TEMPLATE_VIS formatter : public __formatter_pointe template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS formatter : public __formatter_pointer<_CharT> {}; -#endif //_LIBCPP_STD_VER >= 20 +# if _LIBCPP_STD_VER >= 23 +template <> +inline constexpr bool enable_nonlocking_formatter_optimization = true; +template <> +inline constexpr bool enable_nonlocking_formatter_optimization = true; +template <> +inline constexpr bool enable_nonlocking_formatter_optimization = true; +# endif // _LIBCPP_STD_VER >= 23 +#endif // _LIBCPP_STD_VER >= 20 _LIBCPP_END_NAMESPACE_STD diff --git a/system/lib/libcxx/include/__format/formatter_string.h b/system/lib/libcxx/include/__format/formatter_string.h index 347439fc8dff1..30084e582214d 100644 --- a/system/lib/libcxx/include/__format/formatter_string.h +++ b/system/lib/libcxx/include/__format/formatter_string.h @@ -59,44 +59,26 @@ struct _LIBCPP_TEMPLATE_VIS __formatter_string { // Formatter const char*. template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS formatter : public __formatter_string<_CharT> { - using _Base = __formatter_string<_CharT>; + using _Base _LIBCPP_NODEBUG = __formatter_string<_CharT>; template _LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator format(const _CharT* __str, _FormatContext& __ctx) const { _LIBCPP_ASSERT_INTERNAL(__str, "The basic_format_arg constructor should have prevented an invalid pointer."); - - __format_spec::__parsed_specifications<_CharT> __specs = _Base::__parser_.__get_parsed_std_specifications(__ctx); -# if _LIBCPP_STD_VER >= 23 - if (_Base::__parser_.__type_ == __format_spec::__type::__debug) - return __formatter::__format_escaped_string(basic_string_view<_CharT>{__str}, __ctx.out(), __specs); -# endif - - // When using a center or right alignment and the width option the length - // of __str must be known to add the padding upfront. This case is handled - // by the base class by converting the argument to a basic_string_view. + // Converting the input to a basic_string_view means the data is looped over twice; + // - once to determine the length, and + // - once to process the data. // - // When using left alignment and the width option the padding is added - // after outputting __str so the length can be determined while outputting - // __str. The same holds true for the precision, during outputting __str it - // can be validated whether the precision threshold has been reached. For - // now these optimizations aren't implemented. Instead the base class - // handles these options. - // TODO FMT Implement these improvements. - if (__specs.__has_width() || __specs.__has_precision()) - return __formatter::__write_string(basic_string_view<_CharT>{__str}, __ctx.out(), __specs); - - // No formatting required, copy the string to the output. - auto __out_it = __ctx.out(); - while (*__str) - *__out_it++ = *__str++; - return __out_it; + // This sounds slower than writing the output directly. However internally + // the output algorithms have optimizations for "bulk" operations, which + // makes this faster than a single-pass character-by-character output. + return _Base::format(basic_string_view<_CharT>(__str), __ctx); } }; // Formatter char*. template <__fmt_char_type _CharT> struct _LIBCPP_TEMPLATE_VIS formatter<_CharT*, _CharT> : public formatter { - using _Base = formatter; + using _Base _LIBCPP_NODEBUG = formatter; template _LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator format(_CharT* __str, _FormatContext& __ctx) const { @@ -107,7 +89,7 @@ struct _LIBCPP_TEMPLATE_VIS formatter<_CharT*, _CharT> : public formatter struct _LIBCPP_TEMPLATE_VIS formatter<_CharT[_Size], _CharT> : public __formatter_string<_CharT> { - using _Base = __formatter_string<_CharT>; + using _Base _LIBCPP_NODEBUG = __formatter_string<_CharT>; template _LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator @@ -120,7 +102,7 @@ struct _LIBCPP_TEMPLATE_VIS formatter<_CharT[_Size], _CharT> : public __formatte template <__fmt_char_type _CharT, class _Traits, class _Allocator> struct _LIBCPP_TEMPLATE_VIS formatter, _CharT> : public __formatter_string<_CharT> { - using _Base = __formatter_string<_CharT>; + using _Base _LIBCPP_NODEBUG = __formatter_string<_CharT>; template _LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator @@ -133,7 +115,7 @@ struct _LIBCPP_TEMPLATE_VIS formatter, // Formatter std::string_view. template <__fmt_char_type _CharT, class _Traits> struct _LIBCPP_TEMPLATE_VIS formatter, _CharT> : public __formatter_string<_CharT> { - using _Base = __formatter_string<_CharT>; + using _Base _LIBCPP_NODEBUG = __formatter_string<_CharT>; template _LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator @@ -143,7 +125,32 @@ struct _LIBCPP_TEMPLATE_VIS formatter, _CharT } }; -#endif //_LIBCPP_STD_VER >= 20 +# if _LIBCPP_STD_VER >= 23 +template <> +inline constexpr bool enable_nonlocking_formatter_optimization = true; +template <> +inline constexpr bool enable_nonlocking_formatter_optimization = true; +template +inline constexpr bool enable_nonlocking_formatter_optimization = true; +template +inline constexpr bool enable_nonlocking_formatter_optimization> = true; +template +inline constexpr bool enable_nonlocking_formatter_optimization> = true; + +# if _LIBCPP_HAS_WIDE_CHARACTERS +template <> +inline constexpr bool enable_nonlocking_formatter_optimization = true; +template <> +inline constexpr bool enable_nonlocking_formatter_optimization = true; +template +inline constexpr bool enable_nonlocking_formatter_optimization = true; +template +inline constexpr bool enable_nonlocking_formatter_optimization> = true; +template +inline constexpr bool enable_nonlocking_formatter_optimization> = true; +# endif // _LIBCPP_HAS_WIDE_CHARACTERS +# endif // _LIBCPP_STD_VER >= 23 +#endif // _LIBCPP_STD_VER >= 20 _LIBCPP_END_NAMESPACE_STD diff --git a/system/lib/libcxx/include/__format/formatter_tuple.h b/system/lib/libcxx/include/__format/formatter_tuple.h index 030097a8797da..bb841ef11440d 100644 --- a/system/lib/libcxx/include/__format/formatter_tuple.h +++ b/system/lib/libcxx/include/__format/formatter_tuple.h @@ -143,7 +143,7 @@ template <__fmt_char_type _CharT, formattable<_CharT>... _Args> struct _LIBCPP_TEMPLATE_VIS formatter, _CharT> : public __formatter_tuple<_CharT, tuple<_Args...>, _Args...> {}; -#endif //_LIBCPP_STD_VER >= 23 +#endif // _LIBCPP_STD_VER >= 23 _LIBCPP_END_NAMESPACE_STD diff --git a/system/lib/libcxx/include/__format/indic_conjunct_break_table.h b/system/lib/libcxx/include/__format/indic_conjunct_break_table.h index 44521d27498c3..df6cfe6a02f34 100644 --- a/system/lib/libcxx/include/__format/indic_conjunct_break_table.h +++ b/system/lib/libcxx/include/__format/indic_conjunct_break_table.h @@ -63,8 +63,8 @@ #include <__algorithm/ranges_upper_bound.h> #include <__config> +#include <__cstddef/ptrdiff_t.h> #include <__iterator/access.h> -#include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -343,7 +343,7 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[201] = { } // namespace __indic_conjunct_break -#endif //_LIBCPP_STD_VER >= 20 +#endif // _LIBCPP_STD_VER >= 20 _LIBCPP_END_NAMESPACE_STD diff --git a/system/lib/libcxx/include/__format/parser_std_format_spec.h b/system/lib/libcxx/include/__format/parser_std_format_spec.h index 150bdde89f3b3..415261acf0ffe 100644 --- a/system/lib/libcxx/include/__format/parser_std_format_spec.h +++ b/system/lib/libcxx/include/__format/parser_std_format_spec.h @@ -52,13 +52,13 @@ _LIBCPP_BEGIN_NAMESPACE_STD namespace __format_spec { -_LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI inline void +[[noreturn]] _LIBCPP_HIDE_FROM_ABI inline void __throw_invalid_option_format_error(const char* __id, const char* __option) { std::__throw_format_error( (string("The format specifier for ") + __id + " does not allow the " + __option + " option").c_str()); } -_LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI inline void __throw_invalid_type_format_error(const char* __id) { +[[noreturn]] _LIBCPP_HIDE_FROM_ABI inline void __throw_invalid_type_format_error(const char* __id) { std::__throw_format_error( (string("The type option contains an invalid value for ") + __id + " formatting argument").c_str()); } @@ -268,7 +268,7 @@ struct __code_point { char __data[4] = {' '}; }; -# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +# if _LIBCPP_HAS_WIDE_CHARACTERS template <> struct __code_point { wchar_t __data[4 / sizeof(wchar_t)] = {L' '}; @@ -321,7 +321,7 @@ struct __parsed_specifications { // value in formatting functions. static_assert(sizeof(__parsed_specifications) == 16); static_assert(is_trivially_copyable_v<__parsed_specifications>); -# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +# if _LIBCPP_HAS_WIDE_CHARACTERS static_assert(sizeof(__parsed_specifications) == 16); static_assert(is_trivially_copyable_v<__parsed_specifications>); # endif @@ -580,11 +580,11 @@ class _LIBCPP_TEMPLATE_VIS __parser { std::__throw_format_error("The fill option contains an invalid value"); } -# ifndef _LIBCPP_HAS_NO_UNICODE +# if _LIBCPP_HAS_UNICODE // range-fill and tuple-fill are identical template requires same_as<_CharT, char> -# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +# if _LIBCPP_HAS_WIDE_CHARACTERS || (same_as<_CharT, wchar_t> && sizeof(wchar_t) == 2) # endif _LIBCPP_HIDE_FROM_ABI constexpr bool __parse_fill_align(_Iterator& __begin, _Iterator __end) { @@ -617,7 +617,7 @@ class _LIBCPP_TEMPLATE_VIS __parser { return true; } -# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +# if _LIBCPP_HAS_WIDE_CHARACTERS template requires(same_as<_CharT, wchar_t> && sizeof(wchar_t) == 4) _LIBCPP_HIDE_FROM_ABI constexpr bool __parse_fill_align(_Iterator& __begin, _Iterator __end) { @@ -643,9 +643,9 @@ class _LIBCPP_TEMPLATE_VIS __parser { return true; } -# endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS +# endif // _LIBCPP_HAS_WIDE_CHARACTERS -# else // _LIBCPP_HAS_NO_UNICODE +# else // _LIBCPP_HAS_UNICODE // range-fill and tuple-fill are identical template _LIBCPP_HIDE_FROM_ABI constexpr bool __parse_fill_align(_Iterator& __begin, _Iterator __end) { @@ -670,7 +670,7 @@ class _LIBCPP_TEMPLATE_VIS __parser { return true; } -# endif // _LIBCPP_HAS_NO_UNICODE +# endif // _LIBCPP_HAS_UNICODE template _LIBCPP_HIDE_FROM_ABI constexpr bool __parse_sign(_Iterator& __begin) { @@ -874,7 +874,7 @@ class _LIBCPP_TEMPLATE_VIS __parser { // Validates whether the reserved bitfields don't change the size. static_assert(sizeof(__parser) == 16); -# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +# if _LIBCPP_HAS_WIDE_CHARACTERS static_assert(sizeof(__parser) == 16); # endif @@ -1026,7 +1026,7 @@ __column_width_result(size_t, _Iterator) -> __column_width_result<_Iterator>; /// "rounded up". enum class __column_width_rounding { __down, __up }; -# ifndef _LIBCPP_HAS_NO_UNICODE +# if _LIBCPP_HAS_UNICODE namespace __detail { template @@ -1148,7 +1148,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr __column_width_result<_Iterator> __estimate_colu __result.__width_ += __ascii_size; return __result; } -# else // !defined(_LIBCPP_HAS_NO_UNICODE) +# else // _LIBCPP_HAS_UNICODE template _LIBCPP_HIDE_FROM_ABI constexpr __column_width_result::const_iterator> __estimate_column_width(basic_string_view<_CharT> __str, size_t __maximum, __column_width_rounding) noexcept { @@ -1159,11 +1159,11 @@ __estimate_column_width(basic_string_view<_CharT> __str, size_t __maximum, __col return {__width, __str.begin() + __width}; } -# endif // !defined(_LIBCPP_HAS_NO_UNICODE) +# endif // _LIBCPP_HAS_UNICODE } // namespace __format_spec -#endif //_LIBCPP_STD_VER >= 20 +#endif // _LIBCPP_STD_VER >= 20 _LIBCPP_END_NAMESPACE_STD diff --git a/system/lib/libcxx/include/__format/range_default_formatter.h b/system/lib/libcxx/include/__format/range_default_formatter.h index b35223ae93329..bb4c520f5ea11 100644 --- a/system/lib/libcxx/include/__format/range_default_formatter.h +++ b/system/lib/libcxx/include/__format/range_default_formatter.h @@ -40,7 +40,7 @@ concept __const_formattable_range = ranges::input_range && formattable, _CharT>; template -using __fmt_maybe_const = conditional_t<__const_formattable_range<_Rp, _CharT>, const _Rp, _Rp>; +using __fmt_maybe_const _LIBCPP_NODEBUG = conditional_t<__const_formattable_range<_Rp, _CharT>, const _Rp, _Rp>; _LIBCPP_DIAGNOSTIC_PUSH _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wshadow") @@ -95,7 +95,7 @@ struct _LIBCPP_TEMPLATE_VIS __range_default_formatter; template struct _LIBCPP_TEMPLATE_VIS __range_default_formatter { private: - using __maybe_const_r = __fmt_maybe_const<_Rp, _CharT>; + using __maybe_const_r _LIBCPP_NODEBUG = __fmt_maybe_const<_Rp, _CharT>; range_formatter>, _CharT> __underlying_; public: @@ -122,8 +122,8 @@ struct _LIBCPP_TEMPLATE_VIS __range_default_formatter struct _LIBCPP_TEMPLATE_VIS __range_default_formatter { private: - using __maybe_const_map = __fmt_maybe_const<_Rp, _CharT>; - using __element_type = remove_cvref_t>; + using __maybe_const_map _LIBCPP_NODEBUG = __fmt_maybe_const<_Rp, _CharT>; + using __element_type _LIBCPP_NODEBUG = remove_cvref_t>; range_formatter<__element_type, _CharT> __underlying_; public: @@ -150,8 +150,8 @@ struct _LIBCPP_TEMPLATE_VIS __range_default_formatter struct _LIBCPP_TEMPLATE_VIS __range_default_formatter { private: - using __maybe_const_set = __fmt_maybe_const<_Rp, _CharT>; - using __element_type = remove_cvref_t>; + using __maybe_const_set _LIBCPP_NODEBUG = __fmt_maybe_const<_Rp, _CharT>; + using __element_type _LIBCPP_NODEBUG = remove_cvref_t>; range_formatter<__element_type, _CharT> __underlying_; public: @@ -207,7 +207,7 @@ template requires(format_kind<_Rp> != range_format::disabled && formattable, _CharT>) struct _LIBCPP_TEMPLATE_VIS formatter<_Rp, _CharT> : __range_default_formatter, _Rp, _CharT> {}; -#endif //_LIBCPP_STD_VER >= 23 +#endif // _LIBCPP_STD_VER >= 23 _LIBCPP_END_NAMESPACE_STD diff --git a/system/lib/libcxx/include/__format/range_formatter.h b/system/lib/libcxx/include/__format/range_formatter.h index 6915630743493..def55c86ce51c 100644 --- a/system/lib/libcxx/include/__format/range_formatter.h +++ b/system/lib/libcxx/include/__format/range_formatter.h @@ -257,7 +257,7 @@ struct _LIBCPP_TEMPLATE_VIS range_formatter { basic_string_view<_CharT> __closing_bracket_ = _LIBCPP_STATICALLY_WIDEN(_CharT, "]"); }; -#endif //_LIBCPP_STD_VER >= 23 +#endif // _LIBCPP_STD_VER >= 23 _LIBCPP_END_NAMESPACE_STD diff --git a/system/lib/libcxx/include/__format/unicode.h b/system/lib/libcxx/include/__format/unicode.h index de7d0fea1df56..46096fda1e8ae 100644 --- a/system/lib/libcxx/include/__format/unicode.h +++ b/system/lib/libcxx/include/__format/unicode.h @@ -54,7 +54,7 @@ struct __consume_result { }; static_assert(sizeof(__consume_result) == sizeof(char32_t)); -# ifndef _LIBCPP_HAS_NO_UNICODE +# if _LIBCPP_HAS_UNICODE /// Implements the grapheme cluster boundary rules /// @@ -123,7 +123,7 @@ class __code_point_view; /// UTF-8 specialization. template <> class __code_point_view { - using _Iterator = basic_string_view::const_iterator; + using _Iterator _LIBCPP_NODEBUG = basic_string_view::const_iterator; public: _LIBCPP_HIDE_FROM_ABI constexpr explicit __code_point_view(_Iterator __first, _Iterator __last) @@ -235,7 +235,7 @@ class __code_point_view { _Iterator __last_; }; -# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +# if _LIBCPP_HAS_WIDE_CHARACTERS _LIBCPP_HIDE_FROM_ABI constexpr bool __is_surrogate_pair_high(wchar_t __value) { return __value >= 0xd800 && __value <= 0xdbff; } @@ -249,7 +249,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool __is_surrogate_pair_low(wchar_t __value) { /// - 4 UTF-32 (for example Linux) template <> class __code_point_view { - using _Iterator = typename basic_string_view::const_iterator; + using _Iterator _LIBCPP_NODEBUG = typename basic_string_view::const_iterator; public: static_assert(sizeof(wchar_t) == 2 || sizeof(wchar_t) == 4, "sizeof(wchar_t) has a not implemented value"); @@ -292,7 +292,7 @@ class __code_point_view { _Iterator __first_; _Iterator __last_; }; -# endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS +# endif // _LIBCPP_HAS_WIDE_CHARACTERS // State machine to implement the Extended Grapheme Cluster Boundary // @@ -300,8 +300,8 @@ class __code_point_view { // This implements the extended rules see // https://www.unicode.org/reports/tr29/#Grapheme_Cluster_Boundaries class __extended_grapheme_cluster_break { - using __EGC_property = __extended_grapheme_custer_property_boundary::__property; - using __inCB_property = __indic_conjunct_break::__property; + using __EGC_property _LIBCPP_NODEBUG = __extended_grapheme_custer_property_boundary::__property; + using __inCB_property _LIBCPP_NODEBUG = __indic_conjunct_break::__property; public: _LIBCPP_HIDE_FROM_ABI constexpr explicit __extended_grapheme_cluster_break(char32_t __first_code_point) @@ -527,7 +527,7 @@ class __extended_grapheme_cluster_break { /// Therefore only this code point is extracted. template class __extended_grapheme_cluster_view { - using _Iterator = typename basic_string_view<_CharT>::const_iterator; + using _Iterator _LIBCPP_NODEBUG = typename basic_string_view<_CharT>::const_iterator; public: _LIBCPP_HIDE_FROM_ABI constexpr explicit __extended_grapheme_cluster_view(_Iterator __first, _Iterator __last) @@ -566,13 +566,13 @@ class __extended_grapheme_cluster_view { template __extended_grapheme_cluster_view(_Iterator, _Iterator) -> __extended_grapheme_cluster_view>; -# else // _LIBCPP_HAS_NO_UNICODE +# else // _LIBCPP_HAS_UNICODE // For ASCII every character is a "code point". -// This makes it easier to write code agnostic of the _LIBCPP_HAS_NO_UNICODE define. +// This makes it easier to write code agnostic of the _LIBCPP_HAS_UNICODE define. template class __code_point_view { - using _Iterator = typename basic_string_view<_CharT>::const_iterator; + using _Iterator _LIBCPP_NODEBUG = typename basic_string_view<_CharT>::const_iterator; public: _LIBCPP_HIDE_FROM_ABI constexpr explicit __code_point_view(_Iterator __first, _Iterator __last) @@ -591,11 +591,11 @@ class __code_point_view { _Iterator __last_; }; -# endif // _LIBCPP_HAS_NO_UNICODE +# endif // _LIBCPP_HAS_UNICODE } // namespace __unicode -#endif //_LIBCPP_STD_VER >= 20 +#endif // _LIBCPP_STD_VER >= 20 _LIBCPP_END_NAMESPACE_STD diff --git a/system/lib/libcxx/include/__format/width_estimation_table.h b/system/lib/libcxx/include/__format/width_estimation_table.h index 11f61dea18d69..5b4b3950c6a1d 100644 --- a/system/lib/libcxx/include/__format/width_estimation_table.h +++ b/system/lib/libcxx/include/__format/width_estimation_table.h @@ -63,7 +63,7 @@ #include <__algorithm/ranges_upper_bound.h> #include <__config> -#include +#include <__cstddef/ptrdiff_t.h> #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -263,7 +263,7 @@ inline constexpr uint32_t __table_upper_bound = 0x0003fffd; } // namespace __width_estimation_table -#endif //_LIBCPP_STD_VER >= 20 +#endif // _LIBCPP_STD_VER >= 20 _LIBCPP_END_NAMESPACE_STD diff --git a/system/lib/libcxx/include/__format/write_escaped.h b/system/lib/libcxx/include/__format/write_escaped.h index 052ea98c3c3b8..aa74940032f78 100644 --- a/system/lib/libcxx/include/__format/write_escaped.h +++ b/system/lib/libcxx/include/__format/write_escaped.h @@ -16,6 +16,7 @@ #include <__charconv/to_chars_result.h> #include <__chrono/statically_widen.h> #include <__format/escaped_output_table.h> +#include <__format/extended_grapheme_cluster_table.h> #include <__format/formatter_output.h> #include <__format/parser_std_format_spec.h> #include <__format/unicode.h> @@ -41,8 +42,7 @@ namespace __formatter { /// Writes a string using format's width estimation algorithm. /// -/// \note When \c _LIBCPP_HAS_NO_UNICODE is defined the function assumes the -/// input is ASCII. +/// \note When \c _LIBCPP_HAS_UNICODE is false the function assumes the input is ASCII. template _LIBCPP_HIDE_FROM_ABI auto __write_string(basic_string_view<_CharT> __str, @@ -103,7 +103,7 @@ _LIBCPP_HIDE_FROM_ABI void __write_escape_ill_formed_code_unit(basic_string<_Cha template [[nodiscard]] _LIBCPP_HIDE_FROM_ABI bool __is_escaped_sequence_written(basic_string<_CharT>& __str, bool __last_escaped, char32_t __value) { -# ifdef _LIBCPP_HAS_NO_UNICODE +# if !_LIBCPP_HAS_UNICODE // For ASCII assume everything above 127 is printable. if (__value > 127) return false; diff --git a/system/lib/libcxx/include/__functional/binary_function.h b/system/lib/libcxx/include/__functional/binary_function.h index ddee3b170311f..bde8b03ef8281 100644 --- a/system/lib/libcxx/include/__functional/binary_function.h +++ b/system/lib/libcxx/include/__functional/binary_function.h @@ -42,11 +42,11 @@ struct __binary_function_keep_layout_base { _LIBCPP_DIAGNOSTIC_PUSH _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations") template -using __binary_function = binary_function<_Arg1, _Arg2, _Result>; +using __binary_function _LIBCPP_NODEBUG = binary_function<_Arg1, _Arg2, _Result>; _LIBCPP_DIAGNOSTIC_POP #else template -using __binary_function = __binary_function_keep_layout_base<_Arg1, _Arg2, _Result>; +using __binary_function _LIBCPP_NODEBUG = __binary_function_keep_layout_base<_Arg1, _Arg2, _Result>; #endif _LIBCPP_END_NAMESPACE_STD diff --git a/system/lib/libcxx/include/__functional/bind.h b/system/lib/libcxx/include/__functional/bind.h index b4f46441da507..a3c327ab40cc9 100644 --- a/system/lib/libcxx/include/__functional/bind.h +++ b/system/lib/libcxx/include/__functional/bind.h @@ -11,13 +11,12 @@ #define _LIBCPP___FUNCTIONAL_BIND_H #include <__config> -#include <__functional/invoke.h> #include <__functional/weak_result_type.h> #include <__fwd/functional.h> #include <__type_traits/decay.h> +#include <__type_traits/invoke.h> #include <__type_traits/is_reference_wrapper.h> #include <__type_traits/is_void.h> -#include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -83,13 +82,13 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp& __mu(reference_w } template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 typename __invoke_of<_Ti&, _Uj...>::type +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __invoke_result_t<_Ti&, _Uj...> __mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>) { return __ti(std::forward<_Uj>(std::get<_Indx>(__uj))...); } template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 typename __invoke_of<_Ti&, _Uj...>::type +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __invoke_result_t<_Ti&, _Uj...> __mu(_Ti& __ti, tuple<_Uj...>& __uj) { typedef typename __make_tuple_indices::type __indices; return std::__mu_expand(__ti, __uj, __indices()); @@ -131,12 +130,12 @@ struct __mu_return_invokable // false template struct __mu_return_invokable { - typedef typename __invoke_of<_Ti&, _Uj...>::type type; + using type = __invoke_result_t<_Ti&, _Uj...>; }; template struct __mu_return_impl<_Ti, false, true, false, tuple<_Uj...> > - : public __mu_return_invokable<__invokable<_Ti&, _Uj...>::value, _Ti, _Uj...> {}; + : public __mu_return_invokable<__is_invocable_v<_Ti&, _Uj...>, _Ti, _Uj...> {}; template struct __mu_return_impl<_Ti, false, false, true, _TupleUj> { @@ -169,12 +168,12 @@ struct __is_valid_bind_return { template struct __is_valid_bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj> { - static const bool value = __invokable<_Fp, typename __mu_return<_BoundArgs, _TupleUj>::type...>::value; + static const bool value = __is_invocable_v<_Fp, typename __mu_return<_BoundArgs, _TupleUj>::type...>; }; template struct __is_valid_bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj> { - static const bool value = __invokable<_Fp, typename __mu_return::type...>::value; + static const bool value = __is_invocable_v<_Fp, typename __mu_return::type...>; }; template ::value> @@ -182,12 +181,12 @@ struct __bind_return; template struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true> { - typedef typename __invoke_of< _Fp&, typename __mu_return< _BoundArgs, _TupleUj >::type... >::type type; + using type = __invoke_result_t< _Fp&, typename __mu_return< _BoundArgs, _TupleUj >::type... >; }; template struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true> { - typedef typename __invoke_of< _Fp&, typename __mu_return< const _BoundArgs, _TupleUj >::type... >::type type; + using type = __invoke_result_t< _Fp&, typename __mu_return< const _BoundArgs, _TupleUj >::type... >; }; template @@ -199,7 +198,7 @@ __apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>, _ template class __bind : public __weak_result_type<__decay_t<_Fp> > { protected: - using _Fd = __decay_t<_Fp>; + using _Fd _LIBCPP_NODEBUG = __decay_t<_Fp>; typedef tuple<__decay_t<_BoundArgs>...> _Td; private: @@ -257,8 +256,7 @@ class __bind_r : public __bind<_Fp, _BoundArgs...> { is_void<_Rp>::value, int> = 0> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 result_type operator()(_Args&&... __args) { - typedef __invoke_void_return_wrapper<_Rp> _Invoker; - return _Invoker::__call(static_cast(*this), std::forward<_Args>(__args)...); + return std::__invoke_r<_Rp>(static_cast(*this), std::forward<_Args>(__args)...); } template { is_void<_Rp>::value, int> = 0> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 result_type operator()(_Args&&... __args) const { - typedef __invoke_void_return_wrapper<_Rp> _Invoker; - return _Invoker::__call(static_cast(*this), std::forward<_Args>(__args)...); + return std::__invoke_r<_Rp>(static_cast(*this), std::forward<_Args>(__args)...); } }; diff --git a/system/lib/libcxx/include/__functional/boyer_moore_searcher.h b/system/lib/libcxx/include/__functional/boyer_moore_searcher.h index 648b60c505219..1e49cc5464be5 100644 --- a/system/lib/libcxx/include/__functional/boyer_moore_searcher.h +++ b/system/lib/libcxx/include/__functional/boyer_moore_searcher.h @@ -22,9 +22,10 @@ #include <__memory/shared_ptr.h> #include <__type_traits/make_unsigned.h> #include <__utility/pair.h> +#include <__vector/vector.h> #include +#include #include -#include #if _LIBCPP_STD_VER >= 17 @@ -91,7 +92,7 @@ class _LIBCPP_TEMPLATE_VIS boyer_moore_searcher { private: using difference_type = typename std::iterator_traits<_RandomAccessIterator1>::difference_type; using value_type = typename std::iterator_traits<_RandomAccessIterator1>::value_type; - using __skip_table_type = + using __skip_table_type _LIBCPP_NODEBUG = _BMSkipTable::difference_type; using value_type = typename iterator_traits<_RandomAccessIterator1>::value_type; - using __skip_table_type = + using __skip_table_type _LIBCPP_NODEBUG = _BMSkipTable #include <__config> +#include <__cstddef/nullptr_t.h> #include <__exception/exception.h> #include <__functional/binary_function.h> #include <__functional/invoke.h> @@ -21,7 +22,6 @@ #include <__memory/allocator.h> #include <__memory/allocator_destructor.h> #include <__memory/allocator_traits.h> -#include <__memory/builtin_new_allocator.h> #include <__memory/compressed_pair.h> #include <__memory/unique_ptr.h> #include <__type_traits/aligned_storage.h> @@ -37,7 +37,6 @@ #include <__utility/piecewise_construct.h> #include <__utility/swap.h> #include <__verbose_abort> -#include #include #include @@ -78,8 +77,8 @@ class _LIBCPP_EXPORTED_FROM_ABI bad_function_call : public exception { }; _LIBCPP_DIAGNOSTIC_POP -_LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI void __throw_bad_function_call() { -# ifndef _LIBCPP_HAS_NO_EXCEPTIONS +[[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI void __throw_bad_function_call() { +# if _LIBCPP_HAS_EXCEPTIONS throw bad_function_call(); # else _LIBCPP_VERBOSE_ABORT("bad_function_call was thrown in -fno-exceptions mode"); @@ -123,7 +122,7 @@ _LIBCPP_HIDE_FROM_ABI bool __not_null(function<_Fp> const& __f) { return !!__f; } -# ifdef _LIBCPP_HAS_EXTENSION_BLOCKS +# if _LIBCPP_HAS_EXTENSION_BLOCKS template _LIBCPP_HIDE_FROM_ABI bool __not_null(_Rp (^__p)(_Args...)) { return __p; @@ -143,45 +142,45 @@ class __default_alloc_func; template class __alloc_func<_Fp, _Ap, _Rp(_ArgTypes...)> { - __compressed_pair<_Fp, _Ap> __f_; + _LIBCPP_COMPRESSED_PAIR(_Fp, __func_, _Ap, __alloc_); public: - typedef _LIBCPP_NODEBUG _Fp _Target; - typedef _LIBCPP_NODEBUG _Ap _Alloc; + using _Target _LIBCPP_NODEBUG = _Fp; + using _Alloc _LIBCPP_NODEBUG = _Ap; - _LIBCPP_HIDE_FROM_ABI const _Target& __target() const { return __f_.first(); } + _LIBCPP_HIDE_FROM_ABI const _Target& __target() const { return __func_; } // WIN32 APIs may define __allocator, so use __get_allocator instead. - _LIBCPP_HIDE_FROM_ABI const _Alloc& __get_allocator() const { return __f_.second(); } + _LIBCPP_HIDE_FROM_ABI const _Alloc& __get_allocator() const { return __alloc_; } - _LIBCPP_HIDE_FROM_ABI explicit __alloc_func(_Target&& __f) - : __f_(piecewise_construct, std::forward_as_tuple(std::move(__f)), std::forward_as_tuple()) {} + _LIBCPP_HIDE_FROM_ABI explicit __alloc_func(_Target&& __f) : __func_(std::move(__f)), __alloc_() {} - _LIBCPP_HIDE_FROM_ABI explicit __alloc_func(const _Target& __f, const _Alloc& __a) - : __f_(piecewise_construct, std::forward_as_tuple(__f), std::forward_as_tuple(__a)) {} + _LIBCPP_HIDE_FROM_ABI explicit __alloc_func(const _Target& __f, const _Alloc& __a) : __func_(__f), __alloc_(__a) {} _LIBCPP_HIDE_FROM_ABI explicit __alloc_func(const _Target& __f, _Alloc&& __a) - : __f_(piecewise_construct, std::forward_as_tuple(__f), std::forward_as_tuple(std::move(__a))) {} + : __func_(__f), __alloc_(std::move(__a)) {} _LIBCPP_HIDE_FROM_ABI explicit __alloc_func(_Target&& __f, _Alloc&& __a) - : __f_(piecewise_construct, std::forward_as_tuple(std::move(__f)), std::forward_as_tuple(std::move(__a))) {} + : __func_(std::move(__f)), __alloc_(std::move(__a)) {} _LIBCPP_HIDE_FROM_ABI _Rp operator()(_ArgTypes&&... __arg) { - typedef __invoke_void_return_wrapper<_Rp> _Invoker; - return _Invoker::__call(__f_.first(), std::forward<_ArgTypes>(__arg)...); + return std::__invoke_r<_Rp>(__func_, std::forward<_ArgTypes>(__arg)...); } _LIBCPP_HIDE_FROM_ABI __alloc_func* __clone() const { typedef allocator_traits<_Alloc> __alloc_traits; typedef __rebind_alloc<__alloc_traits, __alloc_func> _AA; - _AA __a(__f_.second()); + _AA __a(__alloc_); typedef __allocator_destructor<_AA> _Dp; unique_ptr<__alloc_func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); - ::new ((void*)__hold.get()) __alloc_func(__f_.first(), _Alloc(__a)); + ::new ((void*)__hold.get()) __alloc_func(__func_, _Alloc(__a)); return __hold.release(); } - _LIBCPP_HIDE_FROM_ABI void destroy() _NOEXCEPT { __f_.~__compressed_pair<_Target, _Alloc>(); } + _LIBCPP_HIDE_FROM_ABI void destroy() _NOEXCEPT { + __func_.~_Fp(); + __alloc_.~_Alloc(); + } _LIBCPP_HIDE_FROM_ABI static void __destroy_and_delete(__alloc_func* __f) { typedef allocator_traits<_Alloc> __alloc_traits; @@ -192,12 +191,19 @@ class __alloc_func<_Fp, _Ap, _Rp(_ArgTypes...)> { } }; +template +struct __deallocating_deleter { + _LIBCPP_HIDE_FROM_ABI void operator()(void* __p) const { + std::__libcpp_deallocate<_Tp>(static_cast<_Tp*>(__p), __element_count(1)); + } +}; + template class __default_alloc_func<_Fp, _Rp(_ArgTypes...)> { _Fp __f_; public: - typedef _LIBCPP_NODEBUG _Fp _Target; + using _Target _LIBCPP_NODEBUG = _Fp; _LIBCPP_HIDE_FROM_ABI const _Target& __target() const { return __f_; } @@ -206,13 +212,13 @@ class __default_alloc_func<_Fp, _Rp(_ArgTypes...)> { _LIBCPP_HIDE_FROM_ABI explicit __default_alloc_func(const _Target& __f) : __f_(__f) {} _LIBCPP_HIDE_FROM_ABI _Rp operator()(_ArgTypes&&... __arg) { - typedef __invoke_void_return_wrapper<_Rp> _Invoker; - return _Invoker::__call(__f_, std::forward<_ArgTypes>(__arg)...); + return std::__invoke_r<_Rp>(__f_, std::forward<_ArgTypes>(__arg)...); } _LIBCPP_HIDE_FROM_ABI __default_alloc_func* __clone() const { - __builtin_new_allocator::__holder_t __hold = __builtin_new_allocator::__allocate_type<__default_alloc_func>(1); - __default_alloc_func* __res = ::new ((void*)__hold.get()) __default_alloc_func(__f_); + using _Self = __default_alloc_func; + unique_ptr<_Self, __deallocating_deleter<_Self>> __hold(std::__libcpp_allocate<_Self>(__element_count(1))); + _Self* __res = ::new ((void*)__hold.get()) _Self(__f_); (void)__hold.release(); return __res; } @@ -221,7 +227,7 @@ class __default_alloc_func<_Fp, _Rp(_ArgTypes...)> { _LIBCPP_HIDE_FROM_ABI static void __destroy_and_delete(__default_alloc_func* __f) { __f->destroy(); - __builtin_new_allocator::__deallocate_type<__default_alloc_func>(__f, 1); + std::__libcpp_deallocate<__default_alloc_func>(__f, __element_count(1)); } }; @@ -243,10 +249,10 @@ class __base<_Rp(_ArgTypes...)> { virtual void destroy() _NOEXCEPT = 0; virtual void destroy_deallocate() _NOEXCEPT = 0; virtual _Rp operator()(_ArgTypes&&...) = 0; -# ifndef _LIBCPP_HAS_NO_RTTI +# if _LIBCPP_HAS_RTTI virtual const void* target(const type_info&) const _NOEXCEPT = 0; virtual const std::type_info& target_type() const _NOEXCEPT = 0; -# endif // _LIBCPP_HAS_NO_RTTI +# endif // _LIBCPP_HAS_RTTI }; // __func implements __base for a given functor type. @@ -272,10 +278,10 @@ class __func<_Fp, _Alloc, _Rp(_ArgTypes...)> : public __base<_Rp(_ArgTypes...)> _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void destroy() _NOEXCEPT; _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void destroy_deallocate() _NOEXCEPT; _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual _Rp operator()(_ArgTypes&&... __arg); -# ifndef _LIBCPP_HAS_NO_RTTI +# if _LIBCPP_HAS_RTTI _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual const void* target(const type_info&) const _NOEXCEPT; _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual const std::type_info& target_type() const _NOEXCEPT; -# endif // _LIBCPP_HAS_NO_RTTI +# endif // _LIBCPP_HAS_RTTI }; template @@ -313,7 +319,7 @@ _Rp __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&&... __arg) { return __f_(std::forward<_ArgTypes>(__arg)...); } -# ifndef _LIBCPP_HAS_NO_RTTI +# if _LIBCPP_HAS_RTTI template const void* __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT { @@ -327,7 +333,7 @@ const std::type_info& __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target_type() cons return typeid(_Fp); } -# endif // _LIBCPP_HAS_NO_RTTI +# endif // _LIBCPP_HAS_RTTI // __value_func creates a value-type from a __func. @@ -464,7 +470,7 @@ class __value_func<_Rp(_ArgTypes...)> { _LIBCPP_HIDE_FROM_ABI explicit operator bool() const _NOEXCEPT { return __f_ != nullptr; } -# ifndef _LIBCPP_HAS_NO_RTTI +# if _LIBCPP_HAS_RTTI _LIBCPP_HIDE_FROM_ABI const std::type_info& target_type() const _NOEXCEPT { if (__f_ == nullptr) return typeid(void); @@ -477,7 +483,7 @@ class __value_func<_Rp(_ArgTypes...)> { return nullptr; return (const _Tp*)__f_->target(typeid(_Tp)); } -# endif // _LIBCPP_HAS_NO_RTTI +# endif // _LIBCPP_HAS_RTTI }; // Storage for a functor object, to be used with __policy to manage copy and @@ -520,7 +526,7 @@ struct __policy { nullptr, nullptr, true, -# ifndef _LIBCPP_HAS_NO_RTTI +# if _LIBCPP_HAS_RTTI &typeid(void) # else nullptr @@ -547,7 +553,7 @@ struct __policy { &__large_clone<_Fun>, &__large_destroy<_Fun>, false, -# ifndef _LIBCPP_HAS_NO_RTTI +# if _LIBCPP_HAS_RTTI &typeid(typename _Fun::_Target) # else nullptr @@ -562,7 +568,7 @@ struct __policy { nullptr, nullptr, false, -# ifndef _LIBCPP_HAS_NO_RTTI +# if _LIBCPP_HAS_RTTI &typeid(typename _Fun::_Target) # else nullptr @@ -575,7 +581,7 @@ struct __policy { // Used to choose between perfect forwarding or pass-by-value. Pass-by-value is // faster for types that can be passed in registers. template -using __fast_forward = __conditional_t::value, _Tp, _Tp&&>; +using __fast_forward _LIBCPP_NODEBUG = __conditional_t::value, _Tp, _Tp&&>; // __policy_invoker calls an instance of __alloc_func held in __policy_storage. @@ -667,8 +673,8 @@ class __policy_func<_Rp(_ArgTypes...)> { if (__use_small_storage<_Fun>()) { ::new ((void*)&__buf_.__small) _Fun(std::move(__f)); } else { - __builtin_new_allocator::__holder_t __hold = __builtin_new_allocator::__allocate_type<_Fun>(1); - __buf_.__large = ::new ((void*)__hold.get()) _Fun(std::move(__f)); + unique_ptr<_Fun, __deallocating_deleter<_Fun>> __hold(std::__libcpp_allocate<_Fun>(__element_count(1))); + __buf_.__large = ::new ((void*)__hold.get()) _Fun(std::move(__f)); (void)__hold.release(); } } @@ -724,7 +730,7 @@ class __policy_func<_Rp(_ArgTypes...)> { _LIBCPP_HIDE_FROM_ABI explicit operator bool() const _NOEXCEPT { return !__policy_->__is_null; } -# ifndef _LIBCPP_HAS_NO_RTTI +# if _LIBCPP_HAS_RTTI _LIBCPP_HIDE_FROM_ABI const std::type_info& target_type() const _NOEXCEPT { return *__policy_->__type_info; } template @@ -736,10 +742,10 @@ class __policy_func<_Rp(_ArgTypes...)> { else return reinterpret_cast(&__buf_.__small); } -# endif // _LIBCPP_HAS_NO_RTTI +# endif // _LIBCPP_HAS_RTTI }; -# if defined(_LIBCPP_HAS_BLOCKS_RUNTIME) +# if _LIBCPP_HAS_BLOCKS_RUNTIME extern "C" void* _Block_copy(const void*); extern "C" void _Block_release(const void*); @@ -751,7 +757,7 @@ class __func<_Rp1 (^)(_ArgTypes1...), _Alloc, _Rp(_ArgTypes...)> : public __base public: _LIBCPP_HIDE_FROM_ABI explicit __func(__block_type const& __f) -# ifdef _LIBCPP_HAS_OBJC_ARC +# if _LIBCPP_HAS_OBJC_ARC : __f_(__f) # else : __f_(reinterpret_cast<__block_type>(__f ? _Block_copy(__f) : nullptr)) @@ -762,7 +768,7 @@ class __func<_Rp1 (^)(_ArgTypes1...), _Alloc, _Rp(_ArgTypes...)> : public __base // [TODO] add && to save on a retain _LIBCPP_HIDE_FROM_ABI explicit __func(__block_type __f, const _Alloc& /* unused */) -# ifdef _LIBCPP_HAS_OBJC_ARC +# if _LIBCPP_HAS_OBJC_ARC : __f_(__f) # else : __f_(reinterpret_cast<__block_type>(__f ? _Block_copy(__f) : nullptr)) @@ -784,7 +790,7 @@ class __func<_Rp1 (^)(_ArgTypes1...), _Alloc, _Rp(_ArgTypes...)> : public __base } _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void destroy() _NOEXCEPT { -# ifndef _LIBCPP_HAS_OBJC_ARC +# if !_LIBCPP_HAS_OBJC_ARC if (__f_) _Block_release(__f_); # endif @@ -803,7 +809,7 @@ class __func<_Rp1 (^)(_ArgTypes1...), _Alloc, _Rp(_ArgTypes...)> : public __base return std::__invoke(__f_, std::forward<_ArgTypes>(__arg)...); } -# ifndef _LIBCPP_HAS_NO_RTTI +# if _LIBCPP_HAS_RTTI _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual const void* target(type_info const& __ti) const _NOEXCEPT { if (__ti == typeid(__func::__block_type)) return &__f_; @@ -813,7 +819,7 @@ class __func<_Rp1 (^)(_ArgTypes1...), _Alloc, _Rp(_ArgTypes...)> : public __base _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual const std::type_info& target_type() const _NOEXCEPT { return typeid(__func::__block_type); } -# endif // _LIBCPP_HAS_NO_RTTI +# endif // _LIBCPP_HAS_RTTI }; # endif // _LIBCPP_HAS_EXTENSION_BLOCKS @@ -833,12 +839,12 @@ class _LIBCPP_TEMPLATE_VIS function<_Rp(_ArgTypes...)> __func __f_; template , function>, __invokable<_Fp, _ArgTypes...> >::value> + bool = _And<_IsNotSame<__remove_cvref_t<_Fp>, function>, __is_invocable<_Fp, _ArgTypes...> >::value> struct __callable; template struct __callable<_Fp, true> { static const bool value = - is_void<_Rp>::value || __is_core_convertible::type, _Rp>::value; + is_void<_Rp>::value || __is_core_convertible<__invoke_result_t<_Fp, _ArgTypes...>, _Rp>::value; }; template struct __callable<_Fp, false> { @@ -846,14 +852,14 @@ class _LIBCPP_TEMPLATE_VIS function<_Rp(_ArgTypes...)> }; template - using _EnableIfLValueCallable = __enable_if_t<__callable<_Fp&>::value>; + using _EnableIfLValueCallable _LIBCPP_NODEBUG = __enable_if_t<__callable<_Fp&>::value>; public: typedef _Rp result_type; // construct/copy/destroy: _LIBCPP_HIDE_FROM_ABI function() _NOEXCEPT {} - _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI function(nullptr_t) _NOEXCEPT {} + _LIBCPP_HIDE_FROM_ABI function(nullptr_t) _NOEXCEPT {} _LIBCPP_HIDE_FROM_ABI function(const function&); _LIBCPP_HIDE_FROM_ABI function(function&&) _NOEXCEPT; template > @@ -905,14 +911,14 @@ class _LIBCPP_TEMPLATE_VIS function<_Rp(_ArgTypes...)> // function invocation: _LIBCPP_HIDE_FROM_ABI _Rp operator()(_ArgTypes...) const; -# ifndef _LIBCPP_HAS_NO_RTTI +# if _LIBCPP_HAS_RTTI // function target access: _LIBCPP_HIDE_FROM_ABI const std::type_info& target_type() const _NOEXCEPT; template _LIBCPP_HIDE_FROM_ABI _Tp* target() _NOEXCEPT; template _LIBCPP_HIDE_FROM_ABI const _Tp* target() const _NOEXCEPT; -# endif // _LIBCPP_HAS_NO_RTTI +# endif // _LIBCPP_HAS_RTTI }; # if _LIBCPP_STD_VER >= 17 @@ -989,7 +995,7 @@ _Rp function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const { return __f_(std::forward<_ArgTypes>(__arg)...); } -# ifndef _LIBCPP_HAS_NO_RTTI +# if _LIBCPP_HAS_RTTI template const std::type_info& function<_Rp(_ArgTypes...)>::target_type() const _NOEXCEPT { @@ -1008,7 +1014,7 @@ const _Tp* function<_Rp(_ArgTypes...)>::target() const _NOEXCEPT { return __f_.template target<_Tp>(); } -# endif // _LIBCPP_HAS_NO_RTTI +# endif // _LIBCPP_HAS_RTTI template inline _LIBCPP_HIDE_FROM_ABI bool operator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT { diff --git a/system/lib/libcxx/include/__functional/hash.h b/system/lib/libcxx/include/__functional/hash.h index a9e450edd39f5..28b2635ab1253 100644 --- a/system/lib/libcxx/include/__functional/hash.h +++ b/system/lib/libcxx/include/__functional/hash.h @@ -10,16 +10,17 @@ #define _LIBCPP___FUNCTIONAL_HASH_H #include <__config> +#include <__cstddef/nullptr_t.h> #include <__functional/unary_function.h> #include <__fwd/functional.h> #include <__type_traits/conjunction.h> +#include <__type_traits/enable_if.h> #include <__type_traits/invoke.h> #include <__type_traits/is_constructible.h> #include <__type_traits/is_enum.h> #include <__type_traits/underlying_type.h> #include <__utility/pair.h> #include <__utility/swap.h> -#include #include #include @@ -355,12 +356,12 @@ struct _LIBCPP_TEMPLATE_VIS hash : public __unary_function(__v); } }; -#ifndef _LIBCPP_HAS_NO_CHAR8_T +#if _LIBCPP_HAS_CHAR8_T template <> struct _LIBCPP_TEMPLATE_VIS hash : public __unary_function { _LIBCPP_HIDE_FROM_ABI size_t operator()(char8_t __v) const _NOEXCEPT { return static_cast(__v); } }; -#endif // !_LIBCPP_HAS_NO_CHAR8_T +#endif // _LIBCPP_HAS_CHAR8_T template <> struct _LIBCPP_TEMPLATE_VIS hash : public __unary_function { @@ -372,12 +373,12 @@ struct _LIBCPP_TEMPLATE_VIS hash : public __unary_function(__v); } }; -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +#if _LIBCPP_HAS_WIDE_CHARACTERS template <> struct _LIBCPP_TEMPLATE_VIS hash : public __unary_function { _LIBCPP_HIDE_FROM_ABI size_t operator()(wchar_t __v) const _NOEXCEPT { return static_cast(__v); } }; -#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS +#endif // _LIBCPP_HAS_WIDE_CHARACTERS template <> struct _LIBCPP_TEMPLATE_VIS hash : public __unary_function { @@ -406,7 +407,11 @@ struct _LIBCPP_TEMPLATE_VIS hash : public __unary_function { template <> struct _LIBCPP_TEMPLATE_VIS hash : public __unary_function { - _LIBCPP_HIDE_FROM_ABI size_t operator()(unsigned long __v) const _NOEXCEPT { return static_cast(__v); } + _LIBCPP_HIDE_FROM_ABI size_t operator()(unsigned long __v) const _NOEXCEPT { + static_assert(sizeof(size_t) >= sizeof(unsigned long), + "This would be a terrible hash function on a platform where size_t is smaller than unsigned long"); + return static_cast(__v); + } }; template <> @@ -415,7 +420,7 @@ struct _LIBCPP_TEMPLATE_VIS hash : public __scalar_hash {} template <> struct _LIBCPP_TEMPLATE_VIS hash : public __scalar_hash {}; -#ifndef _LIBCPP_HAS_NO_INT128 +#if _LIBCPP_HAS_INT128 template <> struct _LIBCPP_TEMPLATE_VIS hash<__int128_t> : public __scalar_hash<__int128_t> {}; @@ -517,7 +522,7 @@ template using __check_hash_requirements _LIBCPP_NODEBUG = integral_constant::value && is_move_constructible<_Hash>::value && - __invokable_r::value >; + __is_invocable_r_v >; template > using __has_enabled_hash _LIBCPP_NODEBUG = diff --git a/system/lib/libcxx/include/__functional/identity.h b/system/lib/libcxx/include/__functional/identity.h index 8468de3dae26c..1b1c6cf73c378 100644 --- a/system/lib/libcxx/include/__functional/identity.h +++ b/system/lib/libcxx/include/__functional/identity.h @@ -26,7 +26,7 @@ struct __is_identity : false_type {}; struct __identity { template - _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp&& operator()(_Tp&& __t) const _NOEXCEPT { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp&& operator()(_Tp&& __t) const _NOEXCEPT { return std::forward<_Tp>(__t); } diff --git a/system/lib/libcxx/include/__functional/invoke.h b/system/lib/libcxx/include/__functional/invoke.h index ef4bf25f07759..ab201e94206e1 100644 --- a/system/lib/libcxx/include/__functional/invoke.h +++ b/system/lib/libcxx/include/__functional/invoke.h @@ -12,6 +12,7 @@ #include <__config> #include <__type_traits/invoke.h> +#include <__type_traits/is_void.h> #include <__utility/forward.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) diff --git a/system/lib/libcxx/include/__functional/is_transparent.h b/system/lib/libcxx/include/__functional/is_transparent.h index b2d62f2e3ead8..567df1a662f54 100644 --- a/system/lib/libcxx/include/__functional/is_transparent.h +++ b/system/lib/libcxx/include/__functional/is_transparent.h @@ -21,11 +21,11 @@ _LIBCPP_BEGIN_NAMESPACE_STD #if _LIBCPP_STD_VER >= 14 -template +template inline const bool __is_transparent_v = false; -template -inline const bool __is_transparent_v<_Tp, _Up, __void_t > = true; +template +inline const bool __is_transparent_v<_Tp, _Key, __void_t > = true; #endif diff --git a/system/lib/libcxx/include/__functional/mem_fn.h b/system/lib/libcxx/include/__functional/mem_fn.h index ee07a71774f9a..690393988c5a5 100644 --- a/system/lib/libcxx/include/__functional/mem_fn.h +++ b/system/lib/libcxx/include/__functional/mem_fn.h @@ -12,8 +12,8 @@ #include <__config> #include <__functional/binary_function.h> -#include <__functional/invoke.h> #include <__functional/weak_result_type.h> +#include <__type_traits/invoke.h> #include <__utility/forward.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -36,10 +36,8 @@ class __mem_fn : public __weak_result_type<_Tp> { // invoke template - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 - - typename __invoke_return::type - operator()(_ArgTypes&&... __args) const { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __invoke_result_t + operator()(_ArgTypes&&... __args) const _NOEXCEPT_(__is_nothrow_invocable_v) { return std::__invoke(__f_, std::forward<_ArgTypes>(__args)...); } }; diff --git a/system/lib/libcxx/include/__functional/not_fn.h b/system/lib/libcxx/include/__functional/not_fn.h index 4b3ce5524a743..e6f14be799db3 100644 --- a/system/lib/libcxx/include/__functional/not_fn.h +++ b/system/lib/libcxx/include/__functional/not_fn.h @@ -16,6 +16,8 @@ #include <__type_traits/decay.h> #include <__type_traits/enable_if.h> #include <__type_traits/is_constructible.h> +#include <__type_traits/is_member_pointer.h> +#include <__type_traits/is_pointer.h> #include <__utility/forward.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -48,6 +50,27 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 auto not_fn(_Fn&& __f) { #endif // _LIBCPP_STD_VER >= 17 +#if _LIBCPP_STD_VER >= 26 + +template +struct __nttp_not_fn_t { + template + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Args&&... __args) const + noexcept(noexcept(!std::invoke(_Fn, std::forward<_Args>(__args)...))) + -> decltype(!std::invoke(_Fn, std::forward<_Args>(__args)...)) { + return !std::invoke(_Fn, std::forward<_Args>(__args)...); + } +}; + +template +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI constexpr auto not_fn() noexcept { + if constexpr (using _Ty = decltype(_Fn); is_pointer_v<_Ty> || is_member_pointer_v<_Ty>) + static_assert(_Fn != nullptr, "f cannot be equal to nullptr"); + return __nttp_not_fn_t<_Fn>(); +} + +#endif // _LIBCPP_STD_VER >= 26 + _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP___FUNCTIONAL_NOT_FN_H diff --git a/system/lib/libcxx/include/__functional/operations.h b/system/lib/libcxx/include/__functional/operations.h index 0a6320f19de3f..67d9da289aead 100644 --- a/system/lib/libcxx/include/__functional/operations.h +++ b/system/lib/libcxx/include/__functional/operations.h @@ -14,6 +14,7 @@ #include <__functional/binary_function.h> #include <__functional/unary_function.h> #include <__type_traits/desugars_to.h> +#include <__type_traits/is_integral.h> #include <__utility/forward.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -364,6 +365,9 @@ _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(less); template inline const bool __desugars_to_v<__less_tag, less<_Tp>, _Tp, _Tp> = true; +template +inline const bool __desugars_to_v<__totally_ordered_less_tag, less<_Tp>, _Tp, _Tp> = is_integral<_Tp>::value; + #if _LIBCPP_STD_VER >= 14 template <> struct _LIBCPP_TEMPLATE_VIS less { @@ -376,8 +380,11 @@ struct _LIBCPP_TEMPLATE_VIS less { typedef void is_transparent; }; +template +inline const bool __desugars_to_v<__less_tag, less<>, _Tp, _Up> = true; + template -inline const bool __desugars_to_v<__less_tag, less<>, _Tp, _Tp> = true; +inline const bool __desugars_to_v<__totally_ordered_less_tag, less<>, _Tp, _Tp> = is_integral<_Tp>::value; #endif #if _LIBCPP_STD_VER >= 14 @@ -445,6 +452,9 @@ struct _LIBCPP_TEMPLATE_VIS greater : __binary_function<_Tp, _Tp, bool> { }; _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(greater); +template +inline const bool __desugars_to_v<__greater_tag, greater<_Tp>, _Tp, _Tp> = true; + #if _LIBCPP_STD_VER >= 14 template <> struct _LIBCPP_TEMPLATE_VIS greater { @@ -456,6 +466,9 @@ struct _LIBCPP_TEMPLATE_VIS greater { } typedef void is_transparent; }; + +template +inline const bool __desugars_to_v<__greater_tag, greater<>, _Tp, _Up> = true; #endif // Logical operations diff --git a/system/lib/libcxx/include/__functional/perfect_forward.h b/system/lib/libcxx/include/__functional/perfect_forward.h index 74177c789b4ad..37c3d15b4bec0 100644 --- a/system/lib/libcxx/include/__functional/perfect_forward.h +++ b/system/lib/libcxx/include/__functional/perfect_forward.h @@ -11,6 +11,7 @@ #define _LIBCPP___FUNCTIONAL_PERFECT_FORWARD_H #include <__config> +#include <__cstddef/size_t.h> #include <__type_traits/enable_if.h> #include <__type_traits/invoke.h> #include <__type_traits/is_constructible.h> @@ -93,7 +94,7 @@ struct __perfect_forward_impl<_Op, index_sequence<_Idx...>, _BoundArgs...> { // __perfect_forward implements a perfect-forwarding call wrapper as explained in [func.require]. template -using __perfect_forward = __perfect_forward_impl<_Op, index_sequence_for<_Args...>, _Args...>; +using __perfect_forward _LIBCPP_NODEBUG = __perfect_forward_impl<_Op, index_sequence_for<_Args...>, _Args...>; #endif // _LIBCPP_STD_VER >= 17 diff --git a/system/lib/libcxx/include/__functional/ranges_operations.h b/system/lib/libcxx/include/__functional/ranges_operations.h index 27f06eadd0eb1..df95843e7c9af 100644 --- a/system/lib/libcxx/include/__functional/ranges_operations.h +++ b/system/lib/libcxx/include/__functional/ranges_operations.h @@ -99,9 +99,15 @@ struct greater_equal { template inline const bool __desugars_to_v<__equal_tag, ranges::equal_to, _Tp, _Up> = true; +template +inline const bool __desugars_to_v<__totally_ordered_less_tag, ranges::less, _Tp, _Up> = true; + template inline const bool __desugars_to_v<__less_tag, ranges::less, _Tp, _Up> = true; +template +inline const bool __desugars_to_v<__greater_tag, ranges::greater, _Tp, _Up> = true; + #endif // _LIBCPP_STD_VER >= 20 _LIBCPP_END_NAMESPACE_STD diff --git a/system/lib/libcxx/include/__functional/reference_wrapper.h b/system/lib/libcxx/include/__functional/reference_wrapper.h index 3570e2673c800..d6cd6428f22db 100644 --- a/system/lib/libcxx/include/__functional/reference_wrapper.h +++ b/system/lib/libcxx/include/__functional/reference_wrapper.h @@ -13,10 +13,10 @@ #include <__compare/synth_three_way.h> #include <__concepts/boolean_testable.h> #include <__config> -#include <__functional/invoke.h> #include <__functional/weak_result_type.h> #include <__memory/addressof.h> #include <__type_traits/enable_if.h> +#include <__type_traits/invoke.h> #include <__type_traits/is_const.h> #include <__type_traits/remove_cvref.h> #include <__type_traits/void_t.h> @@ -57,7 +57,7 @@ class _LIBCPP_TEMPLATE_VIS reference_wrapper : public __weak_result_type<_Tp> { // invoke template - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 typename __invoke_of::type + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __invoke_result_t operator()(_ArgTypes&&... __args) const #if _LIBCPP_STD_VER >= 17 // Since is_nothrow_invocable requires C++17 LWG3764 is not backported diff --git a/system/lib/libcxx/include/__functional/unary_function.h b/system/lib/libcxx/include/__functional/unary_function.h index 69b1bc94220ae..769ffc9893a72 100644 --- a/system/lib/libcxx/include/__functional/unary_function.h +++ b/system/lib/libcxx/include/__functional/unary_function.h @@ -39,11 +39,11 @@ struct __unary_function_keep_layout_base { _LIBCPP_DIAGNOSTIC_PUSH _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations") template -using __unary_function = unary_function<_Arg, _Result>; +using __unary_function _LIBCPP_NODEBUG = unary_function<_Arg, _Result>; _LIBCPP_DIAGNOSTIC_POP #else template -using __unary_function = __unary_function_keep_layout_base<_Arg, _Result>; +using __unary_function _LIBCPP_NODEBUG = __unary_function_keep_layout_base<_Arg, _Result>; #endif _LIBCPP_END_NAMESPACE_STD diff --git a/system/lib/libcxx/include/__functional/weak_result_type.h b/system/lib/libcxx/include/__functional/weak_result_type.h index ad7a8395186cd..233d86009a201 100644 --- a/system/lib/libcxx/include/__functional/weak_result_type.h +++ b/system/lib/libcxx/include/__functional/weak_result_type.h @@ -12,9 +12,9 @@ #include <__config> #include <__functional/binary_function.h> -#include <__functional/invoke.h> #include <__functional/unary_function.h> #include <__type_traits/integral_constant.h> +#include <__type_traits/invoke.h> #include <__type_traits/is_same.h> #include <__utility/declval.h> @@ -221,11 +221,6 @@ struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) const volatile> { #endif }; -template -struct __invoke_return { - typedef decltype(std::__invoke(std::declval<_Tp>(), std::declval<_Args>()...)) type; -}; - _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP___FUNCTIONAL_WEAK_RESULT_TYPE_H diff --git a/system/lib/libcxx/include/__fwd/array.h b/system/lib/libcxx/include/__fwd/array.h index b429d0c5a9542..794779ae46ab7 100644 --- a/system/lib/libcxx/include/__fwd/array.h +++ b/system/lib/libcxx/include/__fwd/array.h @@ -10,7 +10,8 @@ #define _LIBCPP___FWD_ARRAY_H #include <__config> -#include +#include <__cstddef/size_t.h> +#include <__type_traits/integral_constant.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -35,11 +36,11 @@ template _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Tp&& get(const array<_Tp, _Size>&&) _NOEXCEPT; #endif -template -struct __is_std_array : false_type {}; +template +inline const bool __is_std_array_v = false; template -struct __is_std_array > : true_type {}; +inline const bool __is_std_array_v > = true; _LIBCPP_END_NAMESPACE_STD diff --git a/system/lib/libcxx/include/__fwd/bit_reference.h b/system/lib/libcxx/include/__fwd/bit_reference.h index 237efb6db6642..30462b6ce4c92 100644 --- a/system/lib/libcxx/include/__fwd/bit_reference.h +++ b/system/lib/libcxx/include/__fwd/bit_reference.h @@ -20,6 +20,9 @@ _LIBCPP_BEGIN_NAMESPACE_STD template class __bit_iterator; +template +struct __size_difference_type_traits; + _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP___FWD_BIT_REFERENCE_H diff --git a/system/lib/libcxx/include/__fwd/byte.h b/system/lib/libcxx/include/__fwd/byte.h new file mode 100644 index 0000000000000..0301833d93cf2 --- /dev/null +++ b/system/lib/libcxx/include/__fwd/byte.h @@ -0,0 +1,26 @@ +//===---------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===---------------------------------------------------------------------===// + +#ifndef _LIBCPP___FWD_BYTE_H +#define _LIBCPP___FWD_BYTE_H + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#if _LIBCPP_STD_VER >= 17 +namespace std { // purposefully not versioned + +enum class byte : unsigned char; + +} // namespace std +#endif // _LIBCPP_STD_VER >= 17 + +#endif // _LIBCPP___FWD_BYTE_H diff --git a/system/lib/libcxx/include/__fwd/complex.h b/system/lib/libcxx/include/__fwd/complex.h index 22c78c5cc3c77..092d2e10b12b5 100644 --- a/system/lib/libcxx/include/__fwd/complex.h +++ b/system/lib/libcxx/include/__fwd/complex.h @@ -10,7 +10,7 @@ #define _LIBCPP___FWD_COMPLEX_H #include <__config> -#include +#include <__cstddef/size_t.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/system/lib/libcxx/include/__fwd/format.h b/system/lib/libcxx/include/__fwd/format.h index b30c220f8a043..815e3e1922c62 100644 --- a/system/lib/libcxx/include/__fwd/format.h +++ b/system/lib/libcxx/include/__fwd/format.h @@ -31,7 +31,7 @@ class _LIBCPP_TEMPLATE_VIS basic_format_context; template struct _LIBCPP_TEMPLATE_VIS formatter; -#endif //_LIBCPP_STD_VER >= 20 +#endif // _LIBCPP_STD_VER >= 20 _LIBCPP_END_NAMESPACE_STD diff --git a/system/lib/libcxx/include/__fwd/fstream.h b/system/lib/libcxx/include/__fwd/fstream.h index b4a112bfd4de6..e6c430dbf75be 100644 --- a/system/lib/libcxx/include/__fwd/fstream.h +++ b/system/lib/libcxx/include/__fwd/fstream.h @@ -32,7 +32,7 @@ using ifstream = basic_ifstream; using ofstream = basic_ofstream; using fstream = basic_fstream; -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +#if _LIBCPP_HAS_WIDE_CHARACTERS using wfilebuf = basic_filebuf; using wifstream = basic_ifstream; using wofstream = basic_ofstream; diff --git a/system/lib/libcxx/include/__fwd/get.h b/system/lib/libcxx/include/__fwd/get.h new file mode 100644 index 0000000000000..6121ed0efd2ba --- /dev/null +++ b/system/lib/libcxx/include/__fwd/get.h @@ -0,0 +1,24 @@ +//===---------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===---------------------------------------------------------------------===// + +#ifndef _LIBCPP___FWD_GET_H +#define _LIBCPP___FWD_GET_H + +#include <__config> +#include <__fwd/array.h> +#include <__fwd/complex.h> +#include <__fwd/pair.h> +#include <__fwd/subrange.h> +#include <__fwd/tuple.h> +#include <__fwd/variant.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#endif // _LIBCPP___FWD_GET_H diff --git a/system/lib/libcxx/include/__fwd/ios.h b/system/lib/libcxx/include/__fwd/ios.h index 48350709d4ce2..bb0c6eb49b52b 100644 --- a/system/lib/libcxx/include/__fwd/ios.h +++ b/system/lib/libcxx/include/__fwd/ios.h @@ -24,7 +24,7 @@ template > class _LIBCPP_TEMPLATE_VIS basic_ios; using ios = basic_ios; -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +#if _LIBCPP_HAS_WIDE_CHARACTERS using wios = basic_ios; #endif diff --git a/system/lib/libcxx/include/__fwd/istream.h b/system/lib/libcxx/include/__fwd/istream.h index a06907a6c8ef9..66a6708544e55 100644 --- a/system/lib/libcxx/include/__fwd/istream.h +++ b/system/lib/libcxx/include/__fwd/istream.h @@ -27,7 +27,7 @@ class _LIBCPP_TEMPLATE_VIS basic_iostream; using istream = basic_istream; using iostream = basic_iostream; -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +#if _LIBCPP_HAS_WIDE_CHARACTERS using wistream = basic_istream; using wiostream = basic_iostream; #endif diff --git a/system/lib/libcxx/include/__fwd/memory.h b/system/lib/libcxx/include/__fwd/memory.h index b9e151855ad7d..564000997dec6 100644 --- a/system/lib/libcxx/include/__fwd/memory.h +++ b/system/lib/libcxx/include/__fwd/memory.h @@ -20,6 +20,9 @@ _LIBCPP_BEGIN_NAMESPACE_STD template class _LIBCPP_TEMPLATE_VIS allocator; +template +class _LIBCPP_TEMPLATE_VIS shared_ptr; + _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP___FWD_MEMORY_H diff --git a/system/lib/libcxx/include/__fwd/memory_resource.h b/system/lib/libcxx/include/__fwd/memory_resource.h index d68b2c2b63154..ca9d3770945c8 100644 --- a/system/lib/libcxx/include/__fwd/memory_resource.h +++ b/system/lib/libcxx/include/__fwd/memory_resource.h @@ -15,6 +15,8 @@ # pragma GCC system_header #endif +#if _LIBCPP_STD_VER >= 17 + _LIBCPP_BEGIN_NAMESPACE_STD namespace pmr { @@ -24,4 +26,6 @@ class _LIBCPP_AVAILABILITY_PMR _LIBCPP_TEMPLATE_VIS polymorphic_allocator; _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_STD_VER >= 17 + #endif // _LIBCPP___FWD_MEMORY_RESOURCE_H diff --git a/system/lib/libcxx/include/__fwd/ostream.h b/system/lib/libcxx/include/__fwd/ostream.h index 3347e0f71d7a1..ff5a3612ef877 100644 --- a/system/lib/libcxx/include/__fwd/ostream.h +++ b/system/lib/libcxx/include/__fwd/ostream.h @@ -23,7 +23,7 @@ class _LIBCPP_TEMPLATE_VIS basic_ostream; using ostream = basic_ostream; -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +#if _LIBCPP_HAS_WIDE_CHARACTERS using wostream = basic_ostream; #endif diff --git a/system/lib/libcxx/include/__fwd/pair.h b/system/lib/libcxx/include/__fwd/pair.h index af32628fe1e0d..b8ba2b7e92324 100644 --- a/system/lib/libcxx/include/__fwd/pair.h +++ b/system/lib/libcxx/include/__fwd/pair.h @@ -10,8 +10,8 @@ #define _LIBCPP___FWD_PAIR_H #include <__config> +#include <__cstddef/size_t.h> #include <__fwd/tuple.h> -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/system/lib/libcxx/include/__fwd/span.h b/system/lib/libcxx/include/__fwd/span.h index 8dafa742c19df..5d473ee51c6b7 100644 --- a/system/lib/libcxx/include/__fwd/span.h +++ b/system/lib/libcxx/include/__fwd/span.h @@ -11,7 +11,7 @@ #define _LIBCPP___FWD_SPAN_H #include <__config> -#include +#include <__cstddef/size_t.h> #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) diff --git a/system/lib/libcxx/include/__fwd/sstream.h b/system/lib/libcxx/include/__fwd/sstream.h index 39a9c3faf1f80..c176db6e5ada0 100644 --- a/system/lib/libcxx/include/__fwd/sstream.h +++ b/system/lib/libcxx/include/__fwd/sstream.h @@ -34,7 +34,7 @@ using istringstream = basic_istringstream; using ostringstream = basic_ostringstream; using stringstream = basic_stringstream; -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +#if _LIBCPP_HAS_WIDE_CHARACTERS using wstringbuf = basic_stringbuf; using wistringstream = basic_istringstream; using wostringstream = basic_ostringstream; diff --git a/system/lib/libcxx/include/__fwd/streambuf.h b/system/lib/libcxx/include/__fwd/streambuf.h index b35afa6afe343..aee0ebb3ce0ff 100644 --- a/system/lib/libcxx/include/__fwd/streambuf.h +++ b/system/lib/libcxx/include/__fwd/streambuf.h @@ -23,7 +23,7 @@ class _LIBCPP_TEMPLATE_VIS basic_streambuf; using streambuf = basic_streambuf; -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +#if _LIBCPP_HAS_WIDE_CHARACTERS using wstreambuf = basic_streambuf; #endif diff --git a/system/lib/libcxx/include/__fwd/string.h b/system/lib/libcxx/include/__fwd/string.h index 2418e1f9b23d0..89dec82d6ffcc 100644 --- a/system/lib/libcxx/include/__fwd/string.h +++ b/system/lib/libcxx/include/__fwd/string.h @@ -24,7 +24,7 @@ struct _LIBCPP_TEMPLATE_VIS char_traits; template <> struct char_traits; -#ifndef _LIBCPP_HAS_NO_CHAR8_T +#if _LIBCPP_HAS_CHAR8_T template <> struct char_traits; #endif @@ -34,7 +34,7 @@ struct char_traits; template <> struct char_traits; -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +#if _LIBCPP_HAS_WIDE_CHARACTERS template <> struct char_traits; #endif @@ -44,11 +44,11 @@ class _LIBCPP_TEMPLATE_VIS basic_string; using string = basic_string; -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +#if _LIBCPP_HAS_WIDE_CHARACTERS using wstring = basic_string; #endif -#ifndef _LIBCPP_HAS_NO_CHAR8_T +#if _LIBCPP_HAS_CHAR8_T using u8string = basic_string; #endif @@ -63,11 +63,11 @@ using basic_string _LIBCPP_AVAILABILITY_PMR = std::basic_string<_CharT, _Traits, using string _LIBCPP_AVAILABILITY_PMR = basic_string; -# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +# if _LIBCPP_HAS_WIDE_CHARACTERS using wstring _LIBCPP_AVAILABILITY_PMR = basic_string; # endif -# ifndef _LIBCPP_HAS_NO_CHAR8_T +# if _LIBCPP_HAS_CHAR8_T using u8string _LIBCPP_AVAILABILITY_PMR = basic_string; # endif @@ -80,20 +80,20 @@ using u32string _LIBCPP_AVAILABILITY_PMR = basic_string; // clang-format off template class _LIBCPP_PREFERRED_NAME(string) -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +#if _LIBCPP_HAS_WIDE_CHARACTERS _LIBCPP_PREFERRED_NAME(wstring) #endif -#ifndef _LIBCPP_HAS_NO_CHAR8_T +#if _LIBCPP_HAS_CHAR8_T _LIBCPP_PREFERRED_NAME(u8string) #endif _LIBCPP_PREFERRED_NAME(u16string) _LIBCPP_PREFERRED_NAME(u32string) #if _LIBCPP_STD_VER >= 17 _LIBCPP_PREFERRED_NAME(pmr::string) -# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +# if _LIBCPP_HAS_WIDE_CHARACTERS _LIBCPP_PREFERRED_NAME(pmr::wstring) # endif -# ifndef _LIBCPP_HAS_NO_CHAR8_T +# if _LIBCPP_HAS_CHAR8_T _LIBCPP_PREFERRED_NAME(pmr::u8string) # endif _LIBCPP_PREFERRED_NAME(pmr::u16string) diff --git a/system/lib/libcxx/include/__fwd/string_view.h b/system/lib/libcxx/include/__fwd/string_view.h index 72a64be5b00b5..b848cb7f60f5f 100644 --- a/system/lib/libcxx/include/__fwd/string_view.h +++ b/system/lib/libcxx/include/__fwd/string_view.h @@ -23,22 +23,22 @@ template > class _LIBCPP_TEMPLATE_VIS basic_string_view; typedef basic_string_view string_view; -#ifndef _LIBCPP_HAS_NO_CHAR8_T +#if _LIBCPP_HAS_CHAR8_T typedef basic_string_view u8string_view; #endif typedef basic_string_view u16string_view; typedef basic_string_view u32string_view; -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +#if _LIBCPP_HAS_WIDE_CHARACTERS typedef basic_string_view wstring_view; #endif // clang-format off template class _LIBCPP_PREFERRED_NAME(string_view) -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +#if _LIBCPP_HAS_WIDE_CHARACTERS _LIBCPP_PREFERRED_NAME(wstring_view) #endif -#ifndef _LIBCPP_HAS_NO_CHAR8_T +#if _LIBCPP_HAS_CHAR8_T _LIBCPP_PREFERRED_NAME(u8string_view) #endif _LIBCPP_PREFERRED_NAME(u16string_view) diff --git a/system/lib/libcxx/include/__fwd/subrange.h b/system/lib/libcxx/include/__fwd/subrange.h index 60a41da23dd44..5b3a07e55348a 100644 --- a/system/lib/libcxx/include/__fwd/subrange.h +++ b/system/lib/libcxx/include/__fwd/subrange.h @@ -11,8 +11,8 @@ #include <__concepts/copyable.h> #include <__config> +#include <__cstddef/size_t.h> #include <__iterator/concepts.h> -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/system/lib/libcxx/include/__fwd/tuple.h b/system/lib/libcxx/include/__fwd/tuple.h index 902770c29555e..2ed32bc0df4e1 100644 --- a/system/lib/libcxx/include/__fwd/tuple.h +++ b/system/lib/libcxx/include/__fwd/tuple.h @@ -10,7 +10,7 @@ #define _LIBCPP___FWD_TUPLE_H #include <__config> -#include +#include <__cstddef/size_t.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/system/lib/libcxx/include/__fwd/variant.h b/system/lib/libcxx/include/__fwd/variant.h new file mode 100644 index 0000000000000..71c792f46a901 --- /dev/null +++ b/system/lib/libcxx/include/__fwd/variant.h @@ -0,0 +1,77 @@ +//===---------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===---------------------------------------------------------------------===// + +#ifndef _LIBCPP___FWD_VARIANT_H +#define _LIBCPP___FWD_VARIANT_H + +#include <__config> +#include <__cstddef/size_t.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER >= 17 + +template +class _LIBCPP_TEMPLATE_VIS variant; + +template +struct _LIBCPP_TEMPLATE_VIS variant_size; + +template +inline constexpr size_t variant_size_v = variant_size<_Tp>::value; + +template +struct _LIBCPP_TEMPLATE_VIS variant_alternative; + +template +using variant_alternative_t = typename variant_alternative<_Ip, _Tp>::type; + +inline constexpr size_t variant_npos = static_cast(-1); + +template +_LIBCPP_HIDE_FROM_ABI +_LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr variant_alternative_t<_Ip, variant<_Types...>>& +get(variant<_Types...>&); + +template +_LIBCPP_HIDE_FROM_ABI +_LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr variant_alternative_t<_Ip, variant<_Types...>>&& +get(variant<_Types...>&&); + +template +_LIBCPP_HIDE_FROM_ABI +_LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr const variant_alternative_t<_Ip, variant<_Types...>>& +get(const variant<_Types...>&); + +template +_LIBCPP_HIDE_FROM_ABI +_LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr const variant_alternative_t<_Ip, variant<_Types...>>&& +get(const variant<_Types...>&&); + +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr _Tp& get(variant<_Types...>&); + +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr _Tp&& get(variant<_Types...>&&); + +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr const _Tp& get(const variant<_Types...>&); + +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS constexpr const _Tp&& +get(const variant<_Types...>&&); + +#endif // _LIBCPP_STD_VER >= 17 + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___FWD_VARIANT_H diff --git a/system/lib/libcxx/include/__fwd/vector.h b/system/lib/libcxx/include/__fwd/vector.h index c9cc96137449f..6980e40ec9187 100644 --- a/system/lib/libcxx/include/__fwd/vector.h +++ b/system/lib/libcxx/include/__fwd/vector.h @@ -21,6 +21,9 @@ _LIBCPP_BEGIN_NAMESPACE_STD template > class _LIBCPP_TEMPLATE_VIS vector; +template +class vector; + _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP___FWD_VECTOR_H diff --git a/system/lib/libcxx/include/__hash_table b/system/lib/libcxx/include/__hash_table index 025758528573f..9a82ec51daee7 100644 --- a/system/lib/libcxx/include/__hash_table +++ b/system/lib/libcxx/include/__hash_table @@ -15,9 +15,11 @@ #include <__assert> #include <__bit/countl.h> #include <__config> +#include <__cstddef/ptrdiff_t.h> +#include <__cstddef/size_t.h> #include <__functional/hash.h> -#include <__functional/invoke.h> #include <__iterator/iterator_traits.h> +#include <__math/rounding_functions.h> #include <__memory/addressof.h> #include <__memory/allocator_traits.h> #include <__memory/compressed_pair.h> @@ -25,14 +27,16 @@ #include <__memory/pointer_traits.h> #include <__memory/swap_allocator.h> #include <__memory/unique_ptr.h> +#include <__new/launder.h> #include <__type_traits/can_extract_key.h> -#include <__type_traits/conditional.h> +#include <__type_traits/enable_if.h> +#include <__type_traits/invoke.h> #include <__type_traits/is_const.h> #include <__type_traits/is_constructible.h> #include <__type_traits/is_nothrow_assignable.h> #include <__type_traits/is_nothrow_constructible.h> -#include <__type_traits/is_pointer.h> #include <__type_traits/is_reference.h> +#include <__type_traits/is_same.h> #include <__type_traits/is_swappable.h> #include <__type_traits/remove_const.h> #include <__type_traits/remove_cvref.h> @@ -40,10 +44,7 @@ #include <__utility/move.h> #include <__utility/pair.h> #include <__utility/swap.h> -#include -#include -#include -#include // __launder +#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -77,11 +78,18 @@ struct __hash_node_base { typedef __hash_node_base __first_node; typedef __rebind_pointer_t<_NodePtr, __first_node> __node_base_pointer; typedef _NodePtr __node_pointer; - -#if defined(_LIBCPP_ABI_FIX_UNORDERED_NODE_POINTER_UB) typedef __node_base_pointer __next_pointer; -#else - typedef __conditional_t::value, __node_base_pointer, __node_pointer> __next_pointer; + +// TODO(LLVM 22): Remove this check +#ifndef _LIBCPP_ABI_FIX_UNORDERED_NODE_POINTER_UB + static_assert(sizeof(__node_base_pointer) == sizeof(__node_pointer) && _LIBCPP_ALIGNOF(__node_base_pointer) == + _LIBCPP_ALIGNOF(__node_pointer), + "It looks like you are using std::__hash_table (an implementation detail for the unordered containers) " + "with a fancy pointer type that thas a different representation depending on whether it points to a " + "__hash_table base pointer or a __hash_table node pointer (both of which are implementation details of " + "the standard library). This means that your ABI is being broken between LLVM 19 and LLVM 20. If you " + "don't care about your ABI being broken, define the _LIBCPP_ABI_TREE_REMOVE_NODE_POINTER_UB macro to " + "silence this diagnostic."); #endif __next_pointer __next_; @@ -103,8 +111,8 @@ struct __hash_node_base { template struct __hash_node : public __hash_node_base< __rebind_pointer_t<_VoidPtr, __hash_node<_Tp, _VoidPtr> > > { typedef _Tp __node_value_type; - using _Base = __hash_node_base<__rebind_pointer_t<_VoidPtr, __hash_node<_Tp, _VoidPtr> > >; - using __next_pointer = typename _Base::__next_pointer; + using _Base _LIBCPP_NODEBUG = __hash_node_base<__rebind_pointer_t<_VoidPtr, __hash_node<_Tp, _VoidPtr> > >; + using __next_pointer _LIBCPP_NODEBUG = typename _Base::__next_pointer; size_t __hash_; @@ -554,29 +562,29 @@ class __bucket_list_deallocator { typedef allocator_traits __alloc_traits; typedef typename __alloc_traits::size_type size_type; - __compressed_pair __data_; + _LIBCPP_COMPRESSED_PAIR(size_type, __size_, allocator_type, __alloc_); public: typedef typename __alloc_traits::pointer pointer; _LIBCPP_HIDE_FROM_ABI __bucket_list_deallocator() _NOEXCEPT_(is_nothrow_default_constructible::value) - : __data_(0, __default_init_tag()) {} + : __size_(0) {} _LIBCPP_HIDE_FROM_ABI __bucket_list_deallocator(const allocator_type& __a, size_type __size) _NOEXCEPT_(is_nothrow_copy_constructible::value) - : __data_(__size, __a) {} + : __size_(__size), __alloc_(__a) {} _LIBCPP_HIDE_FROM_ABI __bucket_list_deallocator(__bucket_list_deallocator&& __x) _NOEXCEPT_(is_nothrow_move_constructible::value) - : __data_(std::move(__x.__data_)) { + : __size_(std::move(__x.__size_)), __alloc_(std::move(__x.__alloc_)) { __x.size() = 0; } - _LIBCPP_HIDE_FROM_ABI size_type& size() _NOEXCEPT { return __data_.first(); } - _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return __data_.first(); } + _LIBCPP_HIDE_FROM_ABI size_type& size() _NOEXCEPT { return __size_; } + _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return __size_; } - _LIBCPP_HIDE_FROM_ABI allocator_type& __alloc() _NOEXCEPT { return __data_.second(); } - _LIBCPP_HIDE_FROM_ABI const allocator_type& __alloc() const _NOEXCEPT { return __data_.second(); } + _LIBCPP_HIDE_FROM_ABI allocator_type& __alloc() _NOEXCEPT { return __alloc_; } + _LIBCPP_HIDE_FROM_ABI const allocator_type& __alloc() const _NOEXCEPT { return __alloc_; } _LIBCPP_HIDE_FROM_ABI void operator()(pointer __p) _NOEXCEPT { __alloc_traits::deallocate(__alloc(), __p, size()); } }; @@ -642,9 +650,9 @@ struct __enforce_unordered_container_requirements { template #ifndef _LIBCPP_CXX03_LANG -_LIBCPP_DIAGNOSE_WARNING(!__invokable<_Equal const&, _Key const&, _Key const&>::value, +_LIBCPP_DIAGNOSE_WARNING(!__is_invocable_v<_Equal const&, _Key const&, _Key const&>, "the specified comparator type does not provide a viable const call operator") -_LIBCPP_DIAGNOSE_WARNING(!__invokable<_Hash const&, _Key const&>::value, +_LIBCPP_DIAGNOSE_WARNING(!__is_invocable_v<_Hash const&, _Key const&>, "the specified hash functor does not provide a viable const call operator") #endif typename __enforce_unordered_container_requirements<_Key, _Hash, _Equal>::type @@ -716,27 +724,27 @@ private: // --- Member data begin --- __bucket_list __bucket_list_; - __compressed_pair<__first_node, __node_allocator> __p1_; - __compressed_pair __p2_; - __compressed_pair __p3_; + _LIBCPP_COMPRESSED_PAIR(__first_node, __first_node_, __node_allocator, __node_alloc_); + _LIBCPP_COMPRESSED_PAIR(size_type, __size_, hasher, __hasher_); + _LIBCPP_COMPRESSED_PAIR(float, __max_load_factor_, key_equal, __key_eq_); // --- Member data end --- - _LIBCPP_HIDE_FROM_ABI size_type& size() _NOEXCEPT { return __p2_.first(); } + _LIBCPP_HIDE_FROM_ABI size_type& size() _NOEXCEPT { return __size_; } public: - _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return __p2_.first(); } + _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return __size_; } - _LIBCPP_HIDE_FROM_ABI hasher& hash_function() _NOEXCEPT { return __p2_.second(); } - _LIBCPP_HIDE_FROM_ABI const hasher& hash_function() const _NOEXCEPT { return __p2_.second(); } + _LIBCPP_HIDE_FROM_ABI hasher& hash_function() _NOEXCEPT { return __hasher_; } + _LIBCPP_HIDE_FROM_ABI const hasher& hash_function() const _NOEXCEPT { return __hasher_; } - _LIBCPP_HIDE_FROM_ABI float& max_load_factor() _NOEXCEPT { return __p3_.first(); } - _LIBCPP_HIDE_FROM_ABI float max_load_factor() const _NOEXCEPT { return __p3_.first(); } + _LIBCPP_HIDE_FROM_ABI float& max_load_factor() _NOEXCEPT { return __max_load_factor_; } + _LIBCPP_HIDE_FROM_ABI float max_load_factor() const _NOEXCEPT { return __max_load_factor_; } - _LIBCPP_HIDE_FROM_ABI key_equal& key_eq() _NOEXCEPT { return __p3_.second(); } - _LIBCPP_HIDE_FROM_ABI const key_equal& key_eq() const _NOEXCEPT { return __p3_.second(); } + _LIBCPP_HIDE_FROM_ABI key_equal& key_eq() _NOEXCEPT { return __key_eq_; } + _LIBCPP_HIDE_FROM_ABI const key_equal& key_eq() const _NOEXCEPT { return __key_eq_; } - _LIBCPP_HIDE_FROM_ABI __node_allocator& __node_alloc() _NOEXCEPT { return __p1_.second(); } - _LIBCPP_HIDE_FROM_ABI const __node_allocator& __node_alloc() const _NOEXCEPT { return __p1_.second(); } + _LIBCPP_HIDE_FROM_ABI __node_allocator& __node_alloc() _NOEXCEPT { return __node_alloc_; } + _LIBCPP_HIDE_FROM_ABI const __node_allocator& __node_alloc() const _NOEXCEPT { return __node_alloc_; } public: typedef __hash_iterator<__node_pointer> iterator; @@ -875,10 +883,10 @@ public: _LIBCPP_HIDE_FROM_ABI void __rehash_unique(size_type __n) { __rehash(__n); } _LIBCPP_HIDE_FROM_ABI void __rehash_multi(size_type __n) { __rehash(__n); } _LIBCPP_HIDE_FROM_ABI void __reserve_unique(size_type __n) { - __rehash_unique(static_cast(std::ceil(__n / max_load_factor()))); + __rehash_unique(static_cast(__math::ceil(__n / max_load_factor()))); } _LIBCPP_HIDE_FROM_ABI void __reserve_multi(size_type __n) { - __rehash_multi(static_cast(std::ceil(__n / max_load_factor()))); + __rehash_multi(static_cast(__math::ceil(__n / max_load_factor()))); } _LIBCPP_HIDE_FROM_ABI size_type bucket_count() const _NOEXCEPT { return __bucket_list_.get_deleter().size(); } @@ -1022,26 +1030,34 @@ inline __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table() _NOEXCEPT_( is_nothrow_default_constructible<__bucket_list>::value&& is_nothrow_default_constructible<__first_node>::value&& is_nothrow_default_constructible<__node_allocator>::value&& is_nothrow_default_constructible::value&& is_nothrow_default_constructible::value) - : __p2_(0, __default_init_tag()), __p3_(1.0f, __default_init_tag()) {} + : __size_(0), __max_load_factor_(1.0f) {} template inline __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const hasher& __hf, const key_equal& __eql) - : __bucket_list_(nullptr, __bucket_list_deleter()), __p1_(), __p2_(0, __hf), __p3_(1.0f, __eql) {} + : __bucket_list_(nullptr, __bucket_list_deleter()), + __first_node_(), + __node_alloc_(), + __size_(0), + __hasher_(__hf), + __max_load_factor_(1.0f), + __key_eq_(__eql) {} template __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table( const hasher& __hf, const key_equal& __eql, const allocator_type& __a) : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)), - __p1_(__default_init_tag(), __node_allocator(__a)), - __p2_(0, __hf), - __p3_(1.0f, __eql) {} + __node_alloc_(__node_allocator(__a)), + __size_(0), + __hasher_(__hf), + __max_load_factor_(1.0f), + __key_eq_(__eql) {} template __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const allocator_type& __a) : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)), - __p1_(__default_init_tag(), __node_allocator(__a)), - __p2_(0, __default_init_tag()), - __p3_(1.0f, __default_init_tag()) {} + __node_alloc_(__node_allocator(__a)), + __size_(0), + __max_load_factor_(1.0f) {} template __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const __hash_table& __u) @@ -1049,17 +1065,20 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const __hash_table& __u) __bucket_list_deleter(allocator_traits<__pointer_allocator>::select_on_container_copy_construction( __u.__bucket_list_.get_deleter().__alloc()), 0)), - __p1_(__default_init_tag(), - allocator_traits<__node_allocator>::select_on_container_copy_construction(__u.__node_alloc())), - __p2_(0, __u.hash_function()), - __p3_(__u.__p3_) {} + __node_alloc_(allocator_traits<__node_allocator>::select_on_container_copy_construction(__u.__node_alloc())), + __size_(0), + __hasher_(__u.hash_function()), + __max_load_factor_(__u.__max_load_factor_), + __key_eq_(__u.__key_eq_) {} template __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const __hash_table& __u, const allocator_type& __a) : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)), - __p1_(__default_init_tag(), __node_allocator(__a)), - __p2_(0, __u.hash_function()), - __p3_(__u.__p3_) {} + __node_alloc_(__node_allocator(__a)), + __size_(0), + __hasher_(__u.hash_function()), + __max_load_factor_(__u.__max_load_factor_), + __key_eq_(__u.__key_eq_) {} template __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u) _NOEXCEPT_( @@ -1067,12 +1086,15 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u) _NOEX is_nothrow_move_constructible<__node_allocator>::value&& is_nothrow_move_constructible::value&& is_nothrow_move_constructible::value) : __bucket_list_(std::move(__u.__bucket_list_)), - __p1_(std::move(__u.__p1_)), - __p2_(std::move(__u.__p2_)), - __p3_(std::move(__u.__p3_)) { + __first_node_(std::move(__u.__first_node_)), + __node_alloc_(std::move(__u.__node_alloc_)), + __size_(std::move(__u.__size_)), + __hasher_(std::move(__u.__hasher_)), + __max_load_factor_(__u.__max_load_factor_), + __key_eq_(std::move(__u.__key_eq_)) { if (size() > 0) { - __bucket_list_[std::__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = __p1_.first().__ptr(); - __u.__p1_.first().__next_ = nullptr; + __bucket_list_[std::__constrain_hash(__first_node_.__next_->__hash(), bucket_count())] = __first_node_.__ptr(); + __u.__first_node_.__next_ = nullptr; __u.size() = 0; } } @@ -1080,17 +1102,19 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u) _NOEX template __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u, const allocator_type& __a) : __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)), - __p1_(__default_init_tag(), __node_allocator(__a)), - __p2_(0, std::move(__u.hash_function())), - __p3_(std::move(__u.__p3_)) { + __node_alloc_(__node_allocator(__a)), + __size_(0), + __hasher_(std::move(__u.__hasher_)), + __max_load_factor_(__u.__max_load_factor_), + __key_eq_(std::move(__u.__key_eq_)) { if (__a == allocator_type(__u.__node_alloc())) { __bucket_list_.reset(__u.__bucket_list_.release()); __bucket_list_.get_deleter().size() = __u.__bucket_list_.get_deleter().size(); __u.__bucket_list_.get_deleter().size() = 0; if (__u.size() > 0) { - __p1_.first().__next_ = __u.__p1_.first().__next_; - __u.__p1_.first().__next_ = nullptr; - __bucket_list_[std::__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = __p1_.first().__ptr(); + __first_node_.__next_ = __u.__first_node_.__next_; + __u.__first_node_.__next_ = nullptr; + __bucket_list_[std::__constrain_hash(__first_node_.__next_->__hash(), bucket_count())] = __first_node_.__ptr(); size() = __u.size(); __u.size() = 0; } @@ -1104,7 +1128,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::~__hash_table() { static_assert(is_copy_constructible::value, "Hasher must be copy-constructible."); #endif - __deallocate_node(__p1_.first().__next_); + __deallocate_node(__first_node_.__next_); } template @@ -1150,8 +1174,8 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__detach() _NOEXCEPT { for (size_type __i = 0; __i < __bc; ++__i) __bucket_list_[__i] = nullptr; size() = 0; - __next_pointer __cache = __p1_.first().__next_; - __p1_.first().__next_ = nullptr; + __next_pointer __cache = __first_node_.__next_; + __first_node_.__next_ = nullptr; return __cache; } @@ -1168,10 +1192,10 @@ void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign(__hash_table& __u, hash_function() = std::move(__u.hash_function()); max_load_factor() = __u.max_load_factor(); key_eq() = std::move(__u.key_eq()); - __p1_.first().__next_ = __u.__p1_.first().__next_; + __first_node_.__next_ = __u.__first_node_.__next_; if (size() > 0) { - __bucket_list_[std::__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = __p1_.first().__ptr(); - __u.__p1_.first().__next_ = nullptr; + __bucket_list_[std::__constrain_hash(__first_node_.__next_->__hash(), bucket_count())] = __first_node_.__ptr(); + __u.__first_node_.__next_ = nullptr; __u.size() = 0; } } @@ -1186,9 +1210,9 @@ void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign(__hash_table& __u, max_load_factor() = __u.max_load_factor(); if (bucket_count() != 0) { __next_pointer __cache = __detach(); -#ifndef _LIBCPP_HAS_NO_EXCEPTIONS +#if _LIBCPP_HAS_EXCEPTIONS try { -#endif // _LIBCPP_HAS_NO_EXCEPTIONS +#endif // _LIBCPP_HAS_EXCEPTIONS const_iterator __i = __u.begin(); while (__cache != nullptr && __u.size() != 0) { __cache->__upcast()->__get_value() = std::move(__u.remove(__i++)->__get_value()); @@ -1196,12 +1220,12 @@ void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign(__hash_table& __u, __node_insert_multi(__cache->__upcast()); __cache = __next; } -#ifndef _LIBCPP_HAS_NO_EXCEPTIONS +#if _LIBCPP_HAS_EXCEPTIONS } catch (...) { __deallocate_node(__cache); throw; } -#endif // _LIBCPP_HAS_NO_EXCEPTIONS +#endif // _LIBCPP_HAS_EXCEPTIONS __deallocate_node(__cache); } const_iterator __i = __u.begin(); @@ -1232,21 +1256,21 @@ void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_unique(_InputIterator __ if (bucket_count() != 0) { __next_pointer __cache = __detach(); -#ifndef _LIBCPP_HAS_NO_EXCEPTIONS +#if _LIBCPP_HAS_EXCEPTIONS try { -#endif // _LIBCPP_HAS_NO_EXCEPTIONS +#endif // _LIBCPP_HAS_EXCEPTIONS for (; __cache != nullptr && __first != __last; ++__first) { __cache->__upcast()->__get_value() = *__first; __next_pointer __next = __cache->__next_; __node_insert_unique(__cache->__upcast()); __cache = __next; } -#ifndef _LIBCPP_HAS_NO_EXCEPTIONS +#if _LIBCPP_HAS_EXCEPTIONS } catch (...) { __deallocate_node(__cache); throw; } -#endif // _LIBCPP_HAS_NO_EXCEPTIONS +#endif // _LIBCPP_HAS_EXCEPTIONS __deallocate_node(__cache); } for (; __first != __last; ++__first) @@ -1264,21 +1288,21 @@ void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_multi(_InputIterator __f " or the nodes value type"); if (bucket_count() != 0) { __next_pointer __cache = __detach(); -#ifndef _LIBCPP_HAS_NO_EXCEPTIONS +#if _LIBCPP_HAS_EXCEPTIONS try { -#endif // _LIBCPP_HAS_NO_EXCEPTIONS +#endif // _LIBCPP_HAS_EXCEPTIONS for (; __cache != nullptr && __first != __last; ++__first) { __cache->__upcast()->__get_value() = *__first; __next_pointer __next = __cache->__next_; __node_insert_multi(__cache->__upcast()); __cache = __next; } -#ifndef _LIBCPP_HAS_NO_EXCEPTIONS +#if _LIBCPP_HAS_EXCEPTIONS } catch (...) { __deallocate_node(__cache); throw; } -#endif // _LIBCPP_HAS_NO_EXCEPTIONS +#endif // _LIBCPP_HAS_EXCEPTIONS __deallocate_node(__cache); } for (; __first != __last; ++__first) @@ -1288,7 +1312,7 @@ void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_multi(_InputIterator __f template inline typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator __hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() _NOEXCEPT { - return iterator(__p1_.first().__next_); + return iterator(__first_node_.__next_); } template @@ -1300,7 +1324,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::end() _NOEXCEPT { template inline typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator __hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() const _NOEXCEPT { - return const_iterator(__p1_.first().__next_); + return const_iterator(__first_node_.__next_); } template @@ -1312,8 +1336,8 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::end() const _NOEXCEPT { template void __hash_table<_Tp, _Hash, _Equal, _Alloc>::clear() _NOEXCEPT { if (size() > 0) { - __deallocate_node(__p1_.first().__next_); - __p1_.first().__next_ = nullptr; + __deallocate_node(__first_node_.__next_); + __first_node_.__next_ = nullptr; size_type __bc = bucket_count(); for (size_type __i = 0; __i < __bc; ++__i) __bucket_list_[__i] = nullptr; @@ -1348,7 +1372,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_unique_prepare(size_t __ } if (size() + 1 > __bc * max_load_factor() || __bc == 0) { __rehash_unique(std::max( - 2 * __bc + !std::__is_hash_power2(__bc), size_type(std::ceil(float(size() + 1) / max_load_factor())))); + 2 * __bc + !std::__is_hash_power2(__bc), size_type(__math::ceil(float(size() + 1) / max_load_factor())))); } return nullptr; } @@ -1365,7 +1389,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_unique_perform(__node_po // insert_after __bucket_list_[__chash], or __first_node if bucket is null __next_pointer __pn = __bucket_list_[__chash]; if (__pn == nullptr) { - __pn = __p1_.first().__ptr(); + __pn = __first_node_.__ptr(); __nd->__next_ = __pn->__next_; __pn->__next_ = __nd->__ptr(); // fix up __bucket_list_ @@ -1408,7 +1432,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi_prepare(size_t __c size_type __bc = bucket_count(); if (size() + 1 > __bc * max_load_factor() || __bc == 0) { __rehash_multi(std::max( - 2 * __bc + !std::__is_hash_power2(__bc), size_type(std::ceil(float(size() + 1) / max_load_factor())))); + 2 * __bc + !std::__is_hash_power2(__bc), size_type(__math::ceil(float(size() + 1) / max_load_factor())))); __bc = bucket_count(); } size_t __chash = std::__constrain_hash(__cp_hash, __bc); @@ -1445,7 +1469,7 @@ void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi_perform( size_type __bc = bucket_count(); size_t __chash = std::__constrain_hash(__cp->__hash_, __bc); if (__pn == nullptr) { - __pn = __p1_.first().__ptr(); + __pn = __first_node_.__ptr(); __cp->__next_ = __pn->__next_; __pn->__next_ = __cp->__ptr(); // fix up __bucket_list_ @@ -1483,7 +1507,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi(const_iterator __p size_type __bc = bucket_count(); if (size() + 1 > __bc * max_load_factor() || __bc == 0) { __rehash_multi(std::max( - 2 * __bc + !std::__is_hash_power2(__bc), size_type(std::ceil(float(size() + 1) / max_load_factor())))); + 2 * __bc + !std::__is_hash_power2(__bc), size_type(__math::ceil(float(size() + 1) / max_load_factor())))); __bc = bucket_count(); } size_t __chash = std::__constrain_hash(__cp->__hash_, __bc); @@ -1523,14 +1547,14 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_key_args(_Key const& __node_holder __h = __construct_node_hash(__hash, std::forward<_Args>(__args)...); if (size() + 1 > __bc * max_load_factor() || __bc == 0) { __rehash_unique(std::max( - 2 * __bc + !std::__is_hash_power2(__bc), size_type(std::ceil(float(size() + 1) / max_load_factor())))); + 2 * __bc + !std::__is_hash_power2(__bc), size_type(__math::ceil(float(size() + 1) / max_load_factor())))); __bc = bucket_count(); __chash = std::__constrain_hash(__hash, __bc); } // insert_after __bucket_list_[__chash], or __first_node if bucket is null __next_pointer __pn = __bucket_list_[__chash]; if (__pn == nullptr) { - __pn = __p1_.first().__ptr(); + __pn = __first_node_.__ptr(); __h->__next_ = __pn->__next_; __pn->__next_ = __h.get()->__ptr(); // fix up __bucket_list_ @@ -1692,8 +1716,8 @@ void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__rehash(size_type __n) _LIBCPP_D else if (__n < __bc) { __n = std::max( __n, - std::__is_hash_power2(__bc) ? std::__next_hash_pow2(size_t(std::ceil(float(size()) / max_load_factor()))) - : std::__next_prime(size_t(std::ceil(float(size()) / max_load_factor())))); + std::__is_hash_power2(__bc) ? std::__next_hash_pow2(size_t(__math::ceil(float(size()) / max_load_factor()))) + : std::__next_prime(size_t(__math::ceil(float(size()) / max_load_factor())))); if (__n < __bc) __do_rehash<_UniqueKeys>(__n); } @@ -1708,7 +1732,7 @@ void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__do_rehash(size_type __nbc) { if (__nbc > 0) { for (size_type __i = 0; __i < __nbc; ++__i) __bucket_list_[__i] = nullptr; - __next_pointer __pp = __p1_.first().__ptr(); + __next_pointer __pp = __first_node_.__ptr(); __next_pointer __cp = __pp->__next_; if (__cp != nullptr) { size_type __chash = std::__constrain_hash(__cp->__hash(), __nbc); @@ -1885,7 +1909,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::remove(const_iterator __p) _NOEXCEPT { // Fix up __bucket_list_ // if __pn is not in same bucket (before begin is not in same bucket) && // if __cn->__next_ is not in same bucket (nullptr is not in same bucket) - if (__pn == __p1_.first().__ptr() || std::__constrain_hash(__pn->__hash(), __bc) != __chash) { + if (__pn == __first_node_.__ptr() || std::__constrain_hash(__pn->__hash(), __bc) != __chash) { if (__cn->__next_ == nullptr || std::__constrain_hash(__cn->__next_->__hash(), __bc) != __chash) __bucket_list_[__chash] = nullptr; } @@ -2004,14 +2028,17 @@ void __hash_table<_Tp, _Hash, _Equal, _Alloc>::swap(__hash_table& __u) std::swap(__bucket_list_.get_deleter().size(), __u.__bucket_list_.get_deleter().size()); std::__swap_allocator(__bucket_list_.get_deleter().__alloc(), __u.__bucket_list_.get_deleter().__alloc()); std::__swap_allocator(__node_alloc(), __u.__node_alloc()); - std::swap(__p1_.first().__next_, __u.__p1_.first().__next_); - __p2_.swap(__u.__p2_); - __p3_.swap(__u.__p3_); + std::swap(__first_node_.__next_, __u.__first_node_.__next_); + using std::swap; + swap(__size_, __u.__size_); + swap(__hasher_, __u.__hasher_); + swap(__max_load_factor_, __u.__max_load_factor_); + swap(__key_eq_, __u.__key_eq_); if (size() > 0) - __bucket_list_[std::__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] = __p1_.first().__ptr(); + __bucket_list_[std::__constrain_hash(__first_node_.__next_->__hash(), bucket_count())] = __first_node_.__ptr(); if (__u.size() > 0) - __u.__bucket_list_[std::__constrain_hash(__u.__p1_.first().__next_->__hash(), __u.bucket_count())] = - __u.__p1_.first().__ptr(); + __u.__bucket_list_[std::__constrain_hash(__u.__first_node_.__next_->__hash(), __u.bucket_count())] = + __u.__first_node_.__ptr(); } template diff --git a/system/lib/libcxx/include/__iterator/access.h b/system/lib/libcxx/include/__iterator/access.h index acc4f60bf697e..d42855f925487 100644 --- a/system/lib/libcxx/include/__iterator/access.h +++ b/system/lib/libcxx/include/__iterator/access.h @@ -11,7 +11,7 @@ #define _LIBCPP___ITERATOR_ACCESS_H #include <__config> -#include +#include <__cstddef/size_t.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/system/lib/libcxx/include/__iterator/advance.h b/system/lib/libcxx/include/__iterator/advance.h index 296db1aaab652..57b1b845f1afa 100644 --- a/system/lib/libcxx/include/__iterator/advance.h +++ b/system/lib/libcxx/include/__iterator/advance.h @@ -76,9 +76,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 void advance(_InputIter& __i // [range.iter.op.advance] namespace ranges { -namespace __advance { - -struct __fn { +struct __advance { private: template _LIBCPP_HIDE_FROM_ABI static constexpr void __advance_forward(_Ip& __i, iter_difference_t<_Ip> __n) { @@ -189,10 +187,8 @@ struct __fn { } }; -} // namespace __advance - inline namespace __cpo { -inline constexpr auto advance = __advance::__fn{}; +inline constexpr auto advance = __advance{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__iterator/aliasing_iterator.h b/system/lib/libcxx/include/__iterator/aliasing_iterator.h index 94ba577078b5e..e01127142ae98 100644 --- a/system/lib/libcxx/include/__iterator/aliasing_iterator.h +++ b/system/lib/libcxx/include/__iterator/aliasing_iterator.h @@ -10,10 +10,10 @@ #define _LIBCPP___ITERATOR_ALIASING_ITERATOR_H #include <__config> +#include <__cstddef/ptrdiff_t.h> #include <__iterator/iterator_traits.h> #include <__memory/pointer_traits.h> #include <__type_traits/is_trivial.h> -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -31,8 +31,8 @@ struct __aliasing_iterator_wrapper { class __iterator { _BaseIter __base_ = nullptr; - using __iter_traits = iterator_traits<_BaseIter>; - using __base_value_type = typename __iter_traits::value_type; + using __iter_traits _LIBCPP_NODEBUG = iterator_traits<_BaseIter>; + using __base_value_type _LIBCPP_NODEBUG = typename __iter_traits::value_type; static_assert(__has_random_access_iterator_category<_BaseIter>::value, "The base iterator has to be a random access iterator!"); @@ -120,7 +120,7 @@ struct __aliasing_iterator_wrapper { // This is required to avoid ADL instantiations on _BaseT template -using __aliasing_iterator = typename __aliasing_iterator_wrapper<_BaseT, _Alias>::__iterator; +using __aliasing_iterator _LIBCPP_NODEBUG = typename __aliasing_iterator_wrapper<_BaseT, _Alias>::__iterator; _LIBCPP_END_NAMESPACE_STD diff --git a/system/lib/libcxx/include/__iterator/back_insert_iterator.h b/system/lib/libcxx/include/__iterator/back_insert_iterator.h index 6d3dd4b12966f..9a59487533885 100644 --- a/system/lib/libcxx/include/__iterator/back_insert_iterator.h +++ b/system/lib/libcxx/include/__iterator/back_insert_iterator.h @@ -11,11 +11,11 @@ #define _LIBCPP___ITERATOR_BACK_INSERT_ITERATOR_H #include <__config> +#include <__cstddef/ptrdiff_t.h> #include <__iterator/iterator.h> #include <__iterator/iterator_traits.h> #include <__memory/addressof.h> #include <__utility/move.h> -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/system/lib/libcxx/include/__iterator/bounded_iter.h b/system/lib/libcxx/include/__iterator/bounded_iter.h index 8a81c9ffbfc3f..d12750d1f81ac 100644 --- a/system/lib/libcxx/include/__iterator/bounded_iter.h +++ b/system/lib/libcxx/include/__iterator/bounded_iter.h @@ -16,9 +16,13 @@ #include <__config> #include <__iterator/iterator_traits.h> #include <__memory/pointer_traits.h> +#include <__type_traits/conjunction.h> +#include <__type_traits/disjunction.h> #include <__type_traits/enable_if.h> #include <__type_traits/integral_constant.h> #include <__type_traits/is_convertible.h> +#include <__type_traits/is_same.h> +#include <__type_traits/make_const_lvalue_ref.h> #include <__utility/move.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -47,8 +51,11 @@ _LIBCPP_BEGIN_NAMESPACE_STD // pointer, it is undefined at the language level (see [expr.add]). If // bounded iterators exhibited this undefined behavior, we risk compiler // optimizations deleting non-redundant bounds checks. -template ::value > > +template struct __bounded_iter { + static_assert(__libcpp_is_contiguous_iterator<_Iterator>::value, + "Only contiguous iterators can be adapted by __bounded_iter."); + using value_type = typename iterator_traits<_Iterator>::value_type; using difference_type = typename iterator_traits<_Iterator>::difference_type; using pointer = typename iterator_traits<_Iterator>::pointer; @@ -60,14 +67,19 @@ struct __bounded_iter { // Create a singular iterator. // - // Such an iterator points past the end of an empty span, so it is not dereferenceable. - // Observing operations like comparison and assignment are valid. + // Such an iterator points past the end of an empty range, so it is not dereferenceable. + // Operations like comparison and assignment are valid. _LIBCPP_HIDE_FROM_ABI __bounded_iter() = default; _LIBCPP_HIDE_FROM_ABI __bounded_iter(__bounded_iter const&) = default; _LIBCPP_HIDE_FROM_ABI __bounded_iter(__bounded_iter&&) = default; - template ::value, int> = 0> + template < class _OtherIterator, + __enable_if_t< + _And< is_convertible, + _Or >, + is_same > > > >::value, + int> = 0> _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __bounded_iter(__bounded_iter<_OtherIterator> const& __other) _NOEXCEPT : __current_(__other.__current_), __begin_(__other.__begin_), @@ -209,9 +221,7 @@ struct __bounded_iter { operator!=(__bounded_iter const& __x, __bounded_iter const& __y) _NOEXCEPT { return __x.__current_ != __y.__current_; } -#endif - // TODO(mordante) disable these overloads in the LLVM 20 release. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR friend bool operator<(__bounded_iter const& __x, __bounded_iter const& __y) _NOEXCEPT { return __x.__current_ < __y.__current_; @@ -229,7 +239,7 @@ struct __bounded_iter { return __x.__current_ >= __y.__current_; } -#if _LIBCPP_STD_VER >= 20 +#else _LIBCPP_HIDE_FROM_ABI constexpr friend strong_ordering operator<=>(__bounded_iter const& __x, __bounded_iter const& __y) noexcept { if constexpr (three_way_comparable<_Iterator, strong_ordering>) { @@ -249,7 +259,7 @@ struct __bounded_iter { private: template friend struct pointer_traits; - template + template friend struct __bounded_iter; _Iterator __current_; // current iterator _Iterator __begin_, __end_; // valid range represented as [begin, end] diff --git a/system/lib/libcxx/include/__iterator/common_iterator.h b/system/lib/libcxx/include/__iterator/common_iterator.h index 199de2cc7337b..31fc8267e5afb 100644 --- a/system/lib/libcxx/include/__iterator/common_iterator.h +++ b/system/lib/libcxx/include/__iterator/common_iterator.h @@ -26,6 +26,7 @@ #include <__iterator/iterator_traits.h> #include <__iterator/readable_traits.h> #include <__memory/addressof.h> +#include <__type_traits/conditional.h> #include <__type_traits/is_pointer.h> #include <__utility/declval.h> #include @@ -235,7 +236,7 @@ class common_iterator { return std::__unchecked_get<_Sent>(__x.__hold_) - std::__unchecked_get<_I2>(__y.__hold_); } - _LIBCPP_HIDE_FROM_ABI friend constexpr iter_rvalue_reference_t<_Iter> + _LIBCPP_HIDE_FROM_ABI friend constexpr decltype(auto) iter_move(const common_iterator& __i) noexcept(noexcept(ranges::iter_move(std::declval()))) requires input_iterator<_Iter> { diff --git a/system/lib/libcxx/include/__iterator/concepts.h b/system/lib/libcxx/include/__iterator/concepts.h index 0a4878308d55f..6e5ac1d3af37b 100644 --- a/system/lib/libcxx/include/__iterator/concepts.h +++ b/system/lib/libcxx/include/__iterator/concepts.h @@ -26,7 +26,6 @@ #include <__concepts/semiregular.h> #include <__concepts/totally_ordered.h> #include <__config> -#include <__functional/invoke.h> #include <__iterator/incrementable_traits.h> #include <__iterator/iter_move.h> #include <__iterator/iterator_traits.h> @@ -34,7 +33,10 @@ #include <__memory/pointer_traits.h> #include <__type_traits/add_pointer.h> #include <__type_traits/common_reference.h> +#include <__type_traits/integral_constant.h> +#include <__type_traits/invoke.h> #include <__type_traits/is_pointer.h> +#include <__type_traits/is_primary_template.h> #include <__type_traits/is_reference.h> #include <__type_traits/remove_cv.h> #include <__type_traits/remove_cvref.h> @@ -64,8 +66,33 @@ concept __indirectly_readable_impl = template concept indirectly_readable = __indirectly_readable_impl>; +template +using __projected_iterator_t _LIBCPP_NODEBUG = typename _Tp::__projected_iterator; + +template +using __projected_projection_t _LIBCPP_NODEBUG = typename _Tp::__projected_projection; + +template +concept __specialization_of_projected = requires { + typename __projected_iterator_t<_Tp>; + typename __projected_projection_t<_Tp>; +} && __is_primary_template<_Tp>::value; + +template +struct __indirect_value_t_impl { + using type = iter_value_t<_Tp>&; +}; +template <__specialization_of_projected _Tp> +struct __indirect_value_t_impl<_Tp> { + using type = invoke_result_t<__projected_projection_t<_Tp>&, + typename __indirect_value_t_impl<__projected_iterator_t<_Tp>>::type>; +}; + +template +using __indirect_value_t _LIBCPP_NODEBUG = typename __indirect_value_t_impl<_Tp>::type; + template -using iter_common_reference_t = common_reference_t, iter_value_t<_Tp>&>; +using iter_common_reference_t = common_reference_t, __indirect_value_t<_Tp>>; // [iterator.concept.writable] template @@ -176,43 +203,45 @@ concept __has_arrow = input_iterator<_Ip> && (is_pointer_v<_Ip> || requires(_Ip // [indirectcallable.indirectinvocable] template concept indirectly_unary_invocable = - indirectly_readable<_It> && copy_constructible<_Fp> && invocable<_Fp&, iter_value_t<_It>&> && + indirectly_readable<_It> && copy_constructible<_Fp> && invocable<_Fp&, __indirect_value_t<_It>> && invocable<_Fp&, iter_reference_t<_It>> && - common_reference_with< invoke_result_t<_Fp&, iter_value_t<_It>&>, invoke_result_t<_Fp&, iter_reference_t<_It>>>; + common_reference_with< invoke_result_t<_Fp&, __indirect_value_t<_It>>, + invoke_result_t<_Fp&, iter_reference_t<_It>>>; template concept indirectly_regular_unary_invocable = - indirectly_readable<_It> && copy_constructible<_Fp> && regular_invocable<_Fp&, iter_value_t<_It>&> && + indirectly_readable<_It> && copy_constructible<_Fp> && regular_invocable<_Fp&, __indirect_value_t<_It>> && regular_invocable<_Fp&, iter_reference_t<_It>> && - common_reference_with< invoke_result_t<_Fp&, iter_value_t<_It>&>, invoke_result_t<_Fp&, iter_reference_t<_It>>>; + common_reference_with< invoke_result_t<_Fp&, __indirect_value_t<_It>>, + invoke_result_t<_Fp&, iter_reference_t<_It>>>; template concept indirect_unary_predicate = - indirectly_readable<_It> && copy_constructible<_Fp> && predicate<_Fp&, iter_value_t<_It>&> && + indirectly_readable<_It> && copy_constructible<_Fp> && predicate<_Fp&, __indirect_value_t<_It>> && predicate<_Fp&, iter_reference_t<_It>>; template concept indirect_binary_predicate = indirectly_readable<_It1> && indirectly_readable<_It2> && copy_constructible<_Fp> && - predicate<_Fp&, iter_value_t<_It1>&, iter_value_t<_It2>&> && - predicate<_Fp&, iter_value_t<_It1>&, iter_reference_t<_It2>> && - predicate<_Fp&, iter_reference_t<_It1>, iter_value_t<_It2>&> && + predicate<_Fp&, __indirect_value_t<_It1>, __indirect_value_t<_It2>> && + predicate<_Fp&, __indirect_value_t<_It1>, iter_reference_t<_It2>> && + predicate<_Fp&, iter_reference_t<_It1>, __indirect_value_t<_It2>> && predicate<_Fp&, iter_reference_t<_It1>, iter_reference_t<_It2>>; template concept indirect_equivalence_relation = indirectly_readable<_It1> && indirectly_readable<_It2> && copy_constructible<_Fp> && - equivalence_relation<_Fp&, iter_value_t<_It1>&, iter_value_t<_It2>&> && - equivalence_relation<_Fp&, iter_value_t<_It1>&, iter_reference_t<_It2>> && - equivalence_relation<_Fp&, iter_reference_t<_It1>, iter_value_t<_It2>&> && + equivalence_relation<_Fp&, __indirect_value_t<_It1>, __indirect_value_t<_It2>> && + equivalence_relation<_Fp&, __indirect_value_t<_It1>, iter_reference_t<_It2>> && + equivalence_relation<_Fp&, iter_reference_t<_It1>, __indirect_value_t<_It2>> && equivalence_relation<_Fp&, iter_reference_t<_It1>, iter_reference_t<_It2>>; template concept indirect_strict_weak_order = indirectly_readable<_It1> && indirectly_readable<_It2> && copy_constructible<_Fp> && - strict_weak_order<_Fp&, iter_value_t<_It1>&, iter_value_t<_It2>&> && - strict_weak_order<_Fp&, iter_value_t<_It1>&, iter_reference_t<_It2>> && - strict_weak_order<_Fp&, iter_reference_t<_It1>, iter_value_t<_It2>&> && + strict_weak_order<_Fp&, __indirect_value_t<_It1>, __indirect_value_t<_It2>> && + strict_weak_order<_Fp&, __indirect_value_t<_It1>, iter_reference_t<_It2>> && + strict_weak_order<_Fp&, iter_reference_t<_It1>, __indirect_value_t<_It2>> && strict_weak_order<_Fp&, iter_reference_t<_It1>, iter_reference_t<_It2>>; template @@ -245,7 +274,7 @@ concept indirectly_copyable_storable = #endif // _LIBCPP_STD_VER >= 20 template -using __has_random_access_iterator_category_or_concept +using __has_random_access_iterator_category_or_concept _LIBCPP_NODEBUG #if _LIBCPP_STD_VER >= 20 = integral_constant>; #else // _LIBCPP_STD_VER < 20 diff --git a/system/lib/libcxx/include/__iterator/counted_iterator.h b/system/lib/libcxx/include/__iterator/counted_iterator.h index ea2832e3b978d..65e178bc0cf21 100644 --- a/system/lib/libcxx/include/__iterator/counted_iterator.h +++ b/system/lib/libcxx/include/__iterator/counted_iterator.h @@ -11,6 +11,7 @@ #define _LIBCPP___ITERATOR_COUNTED_ITERATOR_H #include <__assert> +#include <__compare/ordering.h> #include <__concepts/assignable.h> #include <__concepts/common_with.h> #include <__concepts/constructible.h> @@ -28,7 +29,6 @@ #include <__type_traits/add_pointer.h> #include <__type_traits/conditional.h> #include <__utility/move.h> -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -132,7 +132,7 @@ class counted_iterator _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator++(int) { _LIBCPP_ASSERT_UNCATEGORIZED(__count_ > 0, "Iterator already at or past end."); --__count_; -# ifndef _LIBCPP_HAS_NO_EXCEPTIONS +# if _LIBCPP_HAS_EXCEPTIONS try { return __current_++; } catch (...) { @@ -141,7 +141,7 @@ class counted_iterator } # else return __current_++; -# endif // _LIBCPP_HAS_NO_EXCEPTIONS +# endif // _LIBCPP_HAS_EXCEPTIONS } _LIBCPP_HIDE_FROM_ABI constexpr counted_iterator operator++(int) @@ -249,7 +249,7 @@ class counted_iterator return __rhs.__count_ <=> __lhs.__count_; } - _LIBCPP_HIDE_FROM_ABI friend constexpr iter_rvalue_reference_t<_Iter> + _LIBCPP_HIDE_FROM_ABI friend constexpr decltype(auto) iter_move(const counted_iterator& __i) noexcept(noexcept(ranges::iter_move(__i.__current_))) requires input_iterator<_Iter> { diff --git a/system/lib/libcxx/include/__iterator/data.h b/system/lib/libcxx/include/__iterator/data.h index b7c1603652b0e..5f2624c2b819e 100644 --- a/system/lib/libcxx/include/__iterator/data.h +++ b/system/lib/libcxx/include/__iterator/data.h @@ -11,7 +11,6 @@ #define _LIBCPP___ITERATOR_DATA_H #include <__config> -#include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) diff --git a/system/lib/libcxx/include/__iterator/distance.h b/system/lib/libcxx/include/__iterator/distance.h index 75bd49c9ae732..1732aa527f64a 100644 --- a/system/lib/libcxx/include/__iterator/distance.h +++ b/system/lib/libcxx/include/__iterator/distance.h @@ -52,9 +52,7 @@ distance(_InputIter __first, _InputIter __last) { // [range.iter.op.distance] namespace ranges { -namespace __distance { - -struct __fn { +struct __distance { template _Sp> requires(!sized_sentinel_for<_Sp, _Ip>) _LIBCPP_HIDE_FROM_ABI constexpr iter_difference_t<_Ip> operator()(_Ip __first, _Sp __last) const { @@ -85,10 +83,8 @@ struct __fn { } }; -} // namespace __distance - inline namespace __cpo { -inline constexpr auto distance = __distance::__fn{}; +inline constexpr auto distance = __distance{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__iterator/empty.h b/system/lib/libcxx/include/__iterator/empty.h index 773f2776955b2..f2c653bcb329b 100644 --- a/system/lib/libcxx/include/__iterator/empty.h +++ b/system/lib/libcxx/include/__iterator/empty.h @@ -11,7 +11,6 @@ #define _LIBCPP___ITERATOR_EMPTY_H #include <__config> -#include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) diff --git a/system/lib/libcxx/include/__iterator/front_insert_iterator.h b/system/lib/libcxx/include/__iterator/front_insert_iterator.h index 7f2c54ec87442..80819cd22ae6c 100644 --- a/system/lib/libcxx/include/__iterator/front_insert_iterator.h +++ b/system/lib/libcxx/include/__iterator/front_insert_iterator.h @@ -11,11 +11,11 @@ #define _LIBCPP___ITERATOR_FRONT_INSERT_ITERATOR_H #include <__config> +#include <__cstddef/ptrdiff_t.h> #include <__iterator/iterator.h> #include <__iterator/iterator_traits.h> #include <__memory/addressof.h> #include <__utility/move.h> -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/system/lib/libcxx/include/__iterator/incrementable_traits.h b/system/lib/libcxx/include/__iterator/incrementable_traits.h index a228b228f6e55..37c8daddf8a86 100644 --- a/system/lib/libcxx/include/__iterator/incrementable_traits.h +++ b/system/lib/libcxx/include/__iterator/incrementable_traits.h @@ -12,13 +12,13 @@ #include <__concepts/arithmetic.h> #include <__config> +#include <__cstddef/ptrdiff_t.h> #include <__type_traits/conditional.h> #include <__type_traits/is_object.h> #include <__type_traits/is_primary_template.h> #include <__type_traits/make_signed.h> #include <__type_traits/remove_cvref.h> #include <__utility/declval.h> -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/system/lib/libcxx/include/__iterator/insert_iterator.h b/system/lib/libcxx/include/__iterator/insert_iterator.h index 8b7574dc9ec0a..e0ee0ce035e2a 100644 --- a/system/lib/libcxx/include/__iterator/insert_iterator.h +++ b/system/lib/libcxx/include/__iterator/insert_iterator.h @@ -11,12 +11,12 @@ #define _LIBCPP___ITERATOR_INSERT_ITERATOR_H #include <__config> +#include <__cstddef/ptrdiff_t.h> #include <__iterator/iterator.h> #include <__iterator/iterator_traits.h> #include <__memory/addressof.h> #include <__ranges/access.h> #include <__utility/move.h> -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -29,10 +29,10 @@ _LIBCPP_BEGIN_NAMESPACE_STD #if _LIBCPP_STD_VER >= 20 template -using __insert_iterator_iter_t = ranges::iterator_t<_Container>; +using __insert_iterator_iter_t _LIBCPP_NODEBUG = ranges::iterator_t<_Container>; #else template -using __insert_iterator_iter_t = typename _Container::iterator; +using __insert_iterator_iter_t _LIBCPP_NODEBUG = typename _Container::iterator; #endif _LIBCPP_SUPPRESS_DEPRECATED_PUSH diff --git a/system/lib/libcxx/include/__iterator/istream_iterator.h b/system/lib/libcxx/include/__iterator/istream_iterator.h index 58c9ac6d4ccce..a6c74d00178d2 100644 --- a/system/lib/libcxx/include/__iterator/istream_iterator.h +++ b/system/lib/libcxx/include/__iterator/istream_iterator.h @@ -11,13 +11,13 @@ #define _LIBCPP___ITERATOR_ISTREAM_ITERATOR_H #include <__config> +#include <__cstddef/ptrdiff_t.h> #include <__fwd/istream.h> #include <__fwd/string.h> #include <__iterator/default_sentinel.h> #include <__iterator/iterator.h> #include <__iterator/iterator_traits.h> #include <__memory/addressof.h> -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/system/lib/libcxx/include/__iterator/istreambuf_iterator.h b/system/lib/libcxx/include/__iterator/istreambuf_iterator.h index 51c4ecff351f5..162873b9559ec 100644 --- a/system/lib/libcxx/include/__iterator/istreambuf_iterator.h +++ b/system/lib/libcxx/include/__iterator/istreambuf_iterator.h @@ -16,6 +16,8 @@ #include <__iterator/default_sentinel.h> #include <__iterator/iterator.h> #include <__iterator/iterator_traits.h> +#include <__string/char_traits.h> +#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/system/lib/libcxx/include/__iterator/iterator.h b/system/lib/libcxx/include/__iterator/iterator.h index ba9308f3c2243..1591655313dde 100644 --- a/system/lib/libcxx/include/__iterator/iterator.h +++ b/system/lib/libcxx/include/__iterator/iterator.h @@ -11,7 +11,7 @@ #define _LIBCPP___ITERATOR_ITERATOR_H #include <__config> -#include +#include <__cstddef/ptrdiff_t.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/system/lib/libcxx/include/__iterator/iterator_traits.h b/system/lib/libcxx/include/__iterator/iterator_traits.h index 11af9e301842c..db68dd2c377ac 100644 --- a/system/lib/libcxx/include/__iterator/iterator_traits.h +++ b/system/lib/libcxx/include/__iterator/iterator_traits.h @@ -18,12 +18,15 @@ #include <__concepts/same_as.h> #include <__concepts/totally_ordered.h> #include <__config> +#include <__cstddef/ptrdiff_t.h> #include <__fwd/pair.h> #include <__iterator/incrementable_traits.h> #include <__iterator/readable_traits.h> #include <__type_traits/common_reference.h> #include <__type_traits/conditional.h> #include <__type_traits/disjunction.h> +#include <__type_traits/enable_if.h> +#include <__type_traits/integral_constant.h> #include <__type_traits/is_convertible.h> #include <__type_traits/is_object.h> #include <__type_traits/is_primary_template.h> @@ -34,7 +37,6 @@ #include <__type_traits/remove_cvref.h> #include <__type_traits/void_t.h> #include <__utility/declval.h> -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -45,7 +47,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD #if _LIBCPP_STD_VER >= 20 template -using __with_reference = _Tp&; +using __with_reference _LIBCPP_NODEBUG = _Tp&; template concept __can_reference = requires { typename __with_reference<_Tp>; }; @@ -78,19 +80,20 @@ struct __iter_traits_cache { using type = _If< __is_primary_template >::value, _Iter, iterator_traits<_Iter> >; }; template -using _ITER_TRAITS = typename __iter_traits_cache<_Iter>::type; +using _ITER_TRAITS _LIBCPP_NODEBUG = typename __iter_traits_cache<_Iter>::type; struct __iter_concept_concept_test { template - using _Apply = typename _ITER_TRAITS<_Iter>::iterator_concept; + using _Apply _LIBCPP_NODEBUG = typename _ITER_TRAITS<_Iter>::iterator_concept; }; struct __iter_concept_category_test { template - using _Apply = typename _ITER_TRAITS<_Iter>::iterator_category; + using _Apply _LIBCPP_NODEBUG = typename _ITER_TRAITS<_Iter>::iterator_category; }; struct __iter_concept_random_fallback { template - using _Apply = __enable_if_t< __is_primary_template >::value, random_access_iterator_tag >; + using _Apply _LIBCPP_NODEBUG = + __enable_if_t<__is_primary_template >::value, random_access_iterator_tag>; }; template @@ -104,7 +107,7 @@ struct __iter_concept_cache { }; template -using _ITER_CONCEPT = typename __iter_concept_cache<_Iter>::type::template _Apply<_Iter>; +using _ITER_CONCEPT _LIBCPP_NODEBUG = typename __iter_concept_cache<_Iter>::type::template _Apply<_Iter>; template struct __has_iterator_typedefs { @@ -362,7 +365,7 @@ struct __iterator_traits<_Ip> { template struct iterator_traits : __iterator_traits<_Ip> { - using __primary_template = iterator_traits; + using __primary_template _LIBCPP_NODEBUG = iterator_traits; }; #else // _LIBCPP_STD_VER >= 20 @@ -395,7 +398,7 @@ struct __iterator_traits<_Iter, true> template struct _LIBCPP_TEMPLATE_VIS iterator_traits : __iterator_traits<_Iter, __has_iterator_typedefs<_Iter>::value> { - using __primary_template = iterator_traits; + using __primary_template _LIBCPP_NODEBUG = iterator_traits; }; #endif // _LIBCPP_STD_VER >= 20 @@ -428,16 +431,19 @@ template struct __has_iterator_concept_convertible_to<_Tp, _Up, false> : false_type {}; template -using __has_input_iterator_category = __has_iterator_category_convertible_to<_Tp, input_iterator_tag>; +using __has_input_iterator_category _LIBCPP_NODEBUG = __has_iterator_category_convertible_to<_Tp, input_iterator_tag>; template -using __has_forward_iterator_category = __has_iterator_category_convertible_to<_Tp, forward_iterator_tag>; +using __has_forward_iterator_category _LIBCPP_NODEBUG = + __has_iterator_category_convertible_to<_Tp, forward_iterator_tag>; template -using __has_bidirectional_iterator_category = __has_iterator_category_convertible_to<_Tp, bidirectional_iterator_tag>; +using __has_bidirectional_iterator_category _LIBCPP_NODEBUG = + __has_iterator_category_convertible_to<_Tp, bidirectional_iterator_tag>; template -using __has_random_access_iterator_category = __has_iterator_category_convertible_to<_Tp, random_access_iterator_tag>; +using __has_random_access_iterator_category _LIBCPP_NODEBUG = + __has_iterator_category_convertible_to<_Tp, random_access_iterator_tag>; // __libcpp_is_contiguous_iterator determines if an iterator is known by // libc++ to be contiguous, either because it advertises itself as such @@ -464,48 +470,49 @@ template class __wrap_iter; template -using __has_exactly_input_iterator_category = +using __has_exactly_input_iterator_category _LIBCPP_NODEBUG = integral_constant::value && !__has_iterator_category_convertible_to<_Tp, forward_iterator_tag>::value>; template -using __has_exactly_forward_iterator_category = +using __has_exactly_forward_iterator_category _LIBCPP_NODEBUG = integral_constant::value && !__has_iterator_category_convertible_to<_Tp, bidirectional_iterator_tag>::value>; template -using __has_exactly_bidirectional_iterator_category = +using __has_exactly_bidirectional_iterator_category _LIBCPP_NODEBUG = integral_constant::value && !__has_iterator_category_convertible_to<_Tp, random_access_iterator_tag>::value>; template -using __iter_value_type = typename iterator_traits<_InputIterator>::value_type; +using __iter_value_type _LIBCPP_NODEBUG = typename iterator_traits<_InputIterator>::value_type; template -using __iter_key_type = __remove_const_t::value_type::first_type>; +using __iter_key_type _LIBCPP_NODEBUG = + __remove_const_t::value_type::first_type>; template -using __iter_mapped_type = typename iterator_traits<_InputIterator>::value_type::second_type; +using __iter_mapped_type _LIBCPP_NODEBUG = typename iterator_traits<_InputIterator>::value_type::second_type; template -using __iter_to_alloc_type = +using __iter_to_alloc_type _LIBCPP_NODEBUG = pair::value_type::first_type, typename iterator_traits<_InputIterator>::value_type::second_type>; template -using __iterator_category_type = typename iterator_traits<_Iter>::iterator_category; +using __iterator_category_type _LIBCPP_NODEBUG = typename iterator_traits<_Iter>::iterator_category; template -using __iterator_pointer_type = typename iterator_traits<_Iter>::pointer; +using __iterator_pointer_type _LIBCPP_NODEBUG = typename iterator_traits<_Iter>::pointer; template -using __iter_diff_t = typename iterator_traits<_Iter>::difference_type; +using __iter_diff_t _LIBCPP_NODEBUG = typename iterator_traits<_Iter>::difference_type; template -using __iter_reference = typename iterator_traits<_Iter>::reference; +using __iter_reference _LIBCPP_NODEBUG = typename iterator_traits<_Iter>::reference; #if _LIBCPP_STD_VER >= 20 diff --git a/system/lib/libcxx/include/__iterator/next.h b/system/lib/libcxx/include/__iterator/next.h index 21d3688ad9eb6..1f68a5bec8f39 100644 --- a/system/lib/libcxx/include/__iterator/next.h +++ b/system/lib/libcxx/include/__iterator/next.h @@ -25,7 +25,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 _InputIter +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 _InputIter next(_InputIter __x, typename iterator_traits<_InputIter>::difference_type __n = 1) { // Calling `advance` with a negative value on a non-bidirectional iterator is a no-op in the current implementation. // Note that this check duplicates the similar check in `std::advance`. @@ -41,38 +41,35 @@ next(_InputIter __x, typename iterator_traits<_InputIter>::difference_type __n = // [range.iter.op.next] namespace ranges { -namespace __next { - -struct __fn { +struct __next { template - _LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __x) const { + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __x) const { ++__x; return __x; } template - _LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __x, iter_difference_t<_Ip> __n) const { + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __x, iter_difference_t<_Ip> __n) const { ranges::advance(__x, __n); return __x; } template _Sp> - _LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __x, _Sp __bound_sentinel) const { + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __x, _Sp __bound_sentinel) const { ranges::advance(__x, __bound_sentinel); return __x; } template _Sp> - _LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __x, iter_difference_t<_Ip> __n, _Sp __bound_sentinel) const { + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Ip + operator()(_Ip __x, iter_difference_t<_Ip> __n, _Sp __bound_sentinel) const { ranges::advance(__x, __n, __bound_sentinel); return __x; } }; -} // namespace __next - inline namespace __cpo { -inline constexpr auto next = __next::__fn{}; +inline constexpr auto next = __next{}; } // namespace __cpo } // namespace ranges diff --git a/system/lib/libcxx/include/__iterator/ostream_iterator.h b/system/lib/libcxx/include/__iterator/ostream_iterator.h index 05697e62d9dcb..93ecc03010d07 100644 --- a/system/lib/libcxx/include/__iterator/ostream_iterator.h +++ b/system/lib/libcxx/include/__iterator/ostream_iterator.h @@ -11,12 +11,12 @@ #define _LIBCPP___ITERATOR_OSTREAM_ITERATOR_H #include <__config> +#include <__cstddef/ptrdiff_t.h> #include <__fwd/ostream.h> #include <__fwd/string.h> #include <__iterator/iterator.h> #include <__iterator/iterator_traits.h> #include <__memory/addressof.h> -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/system/lib/libcxx/include/__iterator/ostreambuf_iterator.h b/system/lib/libcxx/include/__iterator/ostreambuf_iterator.h index dda0094dc3f53..f00449355e4eb 100644 --- a/system/lib/libcxx/include/__iterator/ostreambuf_iterator.h +++ b/system/lib/libcxx/include/__iterator/ostreambuf_iterator.h @@ -11,10 +11,13 @@ #define _LIBCPP___ITERATOR_OSTREAMBUF_ITERATOR_H #include <__config> +#include <__cstddef/ptrdiff_t.h> +#include <__fwd/ios.h> +#include <__fwd/ostream.h> +#include <__fwd/streambuf.h> #include <__iterator/iterator.h> #include <__iterator/iterator_traits.h> -#include -#include // for forward declaration of basic_streambuf +#include // for forward declaration of ostreambuf_iterator #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -62,9 +65,11 @@ class _LIBCPP_TEMPLATE_VIS ostreambuf_iterator _LIBCPP_HIDE_FROM_ABI ostreambuf_iterator& operator++(int) { return *this; } _LIBCPP_HIDE_FROM_ABI bool failed() const _NOEXCEPT { return __sbuf_ == nullptr; } +#if _LIBCPP_HAS_LOCALIZATION template friend _LIBCPP_HIDE_FROM_ABI ostreambuf_iterator<_Ch, _Tr> __pad_and_output( ostreambuf_iterator<_Ch, _Tr> __s, const _Ch* __ob, const _Ch* __op, const _Ch* __oe, ios_base& __iob, _Ch __fl); +#endif // _LIBCPP_HAS_LOCALIZATION }; _LIBCPP_END_NAMESPACE_STD diff --git a/system/lib/libcxx/include/__iterator/prev.h b/system/lib/libcxx/include/__iterator/prev.h index 2f0e6a088edb3..bffd5527dc953 100644 --- a/system/lib/libcxx/include/__iterator/prev.h +++ b/system/lib/libcxx/include/__iterator/prev.h @@ -17,16 +17,20 @@ #include <__iterator/incrementable_traits.h> #include <__iterator/iterator_traits.h> #include <__type_traits/enable_if.h> +#include <__utility/move.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header #endif +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + _LIBCPP_BEGIN_NAMESPACE_STD template ::value, int> = 0> -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 _InputIter -prev(_InputIter __x, typename iterator_traits<_InputIter>::difference_type __n = 1) { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 _InputIter +prev(_InputIter __x, typename iterator_traits<_InputIter>::difference_type __n) { // Calling `advance` with a negative value on a non-bidirectional iterator is a no-op in the current implementation. // Note that this check duplicates the similar check in `std::advance`. _LIBCPP_ASSERT_PEDANTIC(__n <= 0 || __has_bidirectional_iterator_category<_InputIter>::value, @@ -35,37 +39,44 @@ prev(_InputIter __x, typename iterator_traits<_InputIter>::difference_type __n = return __x; } +// LWG 3197 +// It is unclear what the implications of "BidirectionalIterator" in the standard are. +// However, calling std::prev(non-bidi-iterator) is obviously an error and we should catch it at compile time. +template ::value, int> = 0> +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 _InputIter prev(_InputIter __it) { + static_assert(__has_bidirectional_iterator_category<_InputIter>::value, + "Attempt to prev(it) with a non-bidirectional iterator"); + return std::prev(std::move(__it), 1); +} + #if _LIBCPP_STD_VER >= 20 // [range.iter.op.prev] namespace ranges { -namespace __prev { - -struct __fn { +struct __prev { template - _LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __x) const { + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __x) const { --__x; return __x; } template - _LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __x, iter_difference_t<_Ip> __n) const { + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __x, iter_difference_t<_Ip> __n) const { ranges::advance(__x, -__n); return __x; } template - _LIBCPP_HIDE_FROM_ABI constexpr _Ip operator()(_Ip __x, iter_difference_t<_Ip> __n, _Ip __bound_iter) const { + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Ip + operator()(_Ip __x, iter_difference_t<_Ip> __n, _Ip __bound_iter) const { ranges::advance(__x, -__n, __bound_iter); return __x; } }; -} // namespace __prev - inline namespace __cpo { -inline constexpr auto prev = __prev::__fn{}; +inline constexpr auto prev = __prev{}; } // namespace __cpo } // namespace ranges @@ -73,4 +84,6 @@ inline constexpr auto prev = __prev::__fn{}; _LIBCPP_END_NAMESPACE_STD +_LIBCPP_POP_MACROS + #endif // _LIBCPP___ITERATOR_PREV_H diff --git a/system/lib/libcxx/include/__iterator/projected.h b/system/lib/libcxx/include/__iterator/projected.h index 463d07b0d33c2..d12f0167de1df 100644 --- a/system/lib/libcxx/include/__iterator/projected.h +++ b/system/lib/libcxx/include/__iterator/projected.h @@ -26,6 +26,10 @@ _LIBCPP_BEGIN_NAMESPACE_STD template struct __projected_impl { struct __type { + using __primary_template _LIBCPP_NODEBUG = __type; + using __projected_iterator _LIBCPP_NODEBUG = _It; + using __projected_projection _LIBCPP_NODEBUG = _Proj; + using value_type = remove_cvref_t>; indirect_result_t<_Proj&, _It> operator*() const; // not defined }; @@ -34,6 +38,10 @@ struct __projected_impl { template struct __projected_impl<_It, _Proj> { struct __type { + using __primary_template _LIBCPP_NODEBUG = __type; + using __projected_iterator _LIBCPP_NODEBUG = _It; + using __projected_projection _LIBCPP_NODEBUG = _Proj; + using value_type = remove_cvref_t>; using difference_type = iter_difference_t<_It>; indirect_result_t<_Proj&, _It> operator*() const; // not defined diff --git a/system/lib/libcxx/include/__iterator/ranges_iterator_traits.h b/system/lib/libcxx/include/__iterator/ranges_iterator_traits.h index 859e7082048ac..9a31b651eb5da 100644 --- a/system/lib/libcxx/include/__iterator/ranges_iterator_traits.h +++ b/system/lib/libcxx/include/__iterator/ranges_iterator_traits.h @@ -24,13 +24,13 @@ _LIBCPP_BEGIN_NAMESPACE_STD #if _LIBCPP_STD_VER >= 23 template -using __range_key_type = __remove_const_t::first_type>; +using __range_key_type _LIBCPP_NODEBUG = __remove_const_t::first_type>; template -using __range_mapped_type = typename ranges::range_value_t<_Range>::second_type; +using __range_mapped_type _LIBCPP_NODEBUG = typename ranges::range_value_t<_Range>::second_type; template -using __range_to_alloc_type = +using __range_to_alloc_type _LIBCPP_NODEBUG = pair::first_type, typename ranges::range_value_t<_Range>::second_type>; #endif diff --git a/system/lib/libcxx/include/__iterator/reverse_access.h b/system/lib/libcxx/include/__iterator/reverse_access.h index 54d7270b04a53..f6e60c3fb75b3 100644 --- a/system/lib/libcxx/include/__iterator/reverse_access.h +++ b/system/lib/libcxx/include/__iterator/reverse_access.h @@ -12,7 +12,6 @@ #include <__config> #include <__iterator/reverse_iterator.h> -#include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) diff --git a/system/lib/libcxx/include/__iterator/reverse_iterator.h b/system/lib/libcxx/include/__iterator/reverse_iterator.h index 50c0f21eaa286..5bd1f868d3ff3 100644 --- a/system/lib/libcxx/include/__iterator/reverse_iterator.h +++ b/system/lib/libcxx/include/__iterator/reverse_iterator.h @@ -136,10 +136,12 @@ class _LIBCPP_TEMPLATE_VIS reverse_iterator _LIBCPP_HIDE_FROM_ABI constexpr pointer operator->() const requires is_pointer_v<_Iter> || requires(const _Iter __i) { __i.operator->(); } { + _Iter __tmp = current; + --__tmp; if constexpr (is_pointer_v<_Iter>) { - return std::prev(current); + return __tmp; } else { - return std::prev(current).operator->(); + return __tmp.operator->(); } } #else @@ -327,8 +329,8 @@ __reverse_range(_Range&& __range) { template struct __unwrap_iter_impl >, __b> { - using _UnwrappedIter = decltype(__unwrap_iter_impl<_Iter>::__unwrap(std::declval<_Iter>())); - using _ReverseWrapper = reverse_iterator >; + using _UnwrappedIter _LIBCPP_NODEBUG = decltype(__unwrap_iter_impl<_Iter>::__unwrap(std::declval<_Iter>())); + using _ReverseWrapper _LIBCPP_NODEBUG = reverse_iterator >; static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ReverseWrapper __rewrap(_ReverseWrapper __orig_iter, _UnwrappedIter __unwrapped_iter) { diff --git a/system/lib/libcxx/include/__iterator/segmented_iterator.h b/system/lib/libcxx/include/__iterator/segmented_iterator.h index f3cd1e5fa1f5d..7a8e1addeacd9 100644 --- a/system/lib/libcxx/include/__iterator/segmented_iterator.h +++ b/system/lib/libcxx/include/__iterator/segmented_iterator.h @@ -41,8 +41,8 @@ // Returns the iterator composed of the segment iterator and local iterator. #include <__config> +#include <__cstddef/size_t.h> #include <__type_traits/integral_constant.h> -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -72,7 +72,7 @@ template struct __has_specialization<_Tp, sizeof(_Tp) * 0> : true_type {}; template -using __is_segmented_iterator = __has_specialization<__segmented_iterator_traits<_Iterator> >; +using __is_segmented_iterator _LIBCPP_NODEBUG = __has_specialization<__segmented_iterator_traits<_Iterator> >; _LIBCPP_END_NAMESPACE_STD diff --git a/system/lib/libcxx/include/__iterator/size.h b/system/lib/libcxx/include/__iterator/size.h index 876e6963f77d9..84e2e3b21f1d5 100644 --- a/system/lib/libcxx/include/__iterator/size.h +++ b/system/lib/libcxx/include/__iterator/size.h @@ -11,9 +11,10 @@ #define _LIBCPP___ITERATOR_SIZE_H #include <__config> +#include <__cstddef/ptrdiff_t.h> +#include <__cstddef/size_t.h> #include <__type_traits/common_type.h> #include <__type_traits/make_signed.h> -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/system/lib/libcxx/include/__iterator/static_bounded_iter.h b/system/lib/libcxx/include/__iterator/static_bounded_iter.h new file mode 100644 index 0000000000000..8f4fbdf6dff96 --- /dev/null +++ b/system/lib/libcxx/include/__iterator/static_bounded_iter.h @@ -0,0 +1,318 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___ITERATOR_STATIC_BOUNDED_ITER_H +#define _LIBCPP___ITERATOR_STATIC_BOUNDED_ITER_H + +#include <__assert> +#include <__compare/ordering.h> +#include <__compare/three_way_comparable.h> +#include <__config> +#include <__cstddef/size_t.h> +#include <__iterator/iterator_traits.h> +#include <__memory/pointer_traits.h> +#include <__type_traits/conjunction.h> +#include <__type_traits/disjunction.h> +#include <__type_traits/enable_if.h> +#include <__type_traits/integral_constant.h> +#include <__type_traits/is_convertible.h> +#include <__type_traits/is_same.h> +#include <__type_traits/make_const_lvalue_ref.h> +#include <__utility/move.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +template +struct __static_bounded_iter_storage { + _LIBCPP_HIDE_FROM_ABI __static_bounded_iter_storage() = default; + _LIBCPP_HIDE_FROM_ABI + _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __static_bounded_iter_storage(_Iterator __current, _Iterator __begin) + : __current_(__current), __begin_(__begin) {} + + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iterator& __current() _NOEXCEPT { return __current_; } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iterator __current() const _NOEXCEPT { return __current_; } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iterator __begin() const _NOEXCEPT { return __begin_; } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iterator __end() const _NOEXCEPT { return __begin_ + _Size; } + +private: + _Iterator __current_; // current iterator + _Iterator __begin_; // start of the valid range, which is [__begin_, __begin_ + _Size) +}; + +template +struct __static_bounded_iter_storage<_Iterator, 0> { + _LIBCPP_HIDE_FROM_ABI __static_bounded_iter_storage() = default; + _LIBCPP_HIDE_FROM_ABI + _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __static_bounded_iter_storage(_Iterator __current, _Iterator /* __begin */) + : __current_(__current) {} + + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iterator& __current() _NOEXCEPT { return __current_; } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iterator __current() const _NOEXCEPT { return __current_; } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iterator __begin() const _NOEXCEPT { return __current_; } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iterator __end() const _NOEXCEPT { return __current_; } + +private: + _Iterator __current_; // current iterator +}; + +// This is an iterator wrapper for contiguous iterators that points within a range +// whose size is known at compile-time. This is very similar to `__bounded_iter`, +// except that we don't have to store the end of the range in physical memory since +// it can be computed from the start of the range. +// +// The operations on which this iterator wrapper traps are the same as `__bounded_iter`. +template +struct __static_bounded_iter { + static_assert(__libcpp_is_contiguous_iterator<_Iterator>::value, + "Only contiguous iterators can be adapted by __static_bounded_iter."); + + using value_type = typename iterator_traits<_Iterator>::value_type; + using difference_type = typename iterator_traits<_Iterator>::difference_type; + using pointer = typename iterator_traits<_Iterator>::pointer; + using reference = typename iterator_traits<_Iterator>::reference; + using iterator_category = typename iterator_traits<_Iterator>::iterator_category; +#if _LIBCPP_STD_VER >= 20 + using iterator_concept = contiguous_iterator_tag; +#endif + + // Create a singular iterator. + // + // Such an iterator points past the end of an empty range, so it is not dereferenceable. + // Operations like comparison and assignment are valid. + _LIBCPP_HIDE_FROM_ABI __static_bounded_iter() = default; + + _LIBCPP_HIDE_FROM_ABI __static_bounded_iter(__static_bounded_iter const&) = default; + _LIBCPP_HIDE_FROM_ABI __static_bounded_iter(__static_bounded_iter&&) = default; + + template , + _Or >, + is_same > > > >::value, + int> = 0> + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR + __static_bounded_iter(__static_bounded_iter<_OtherIterator, _Size> const& __other) _NOEXCEPT + : __storage_(__other.__storage_.__current(), __other.__storage_.__begin()) {} + + // Assign a bounded iterator to another one, rebinding the bounds of the iterator as well. + _LIBCPP_HIDE_FROM_ABI __static_bounded_iter& operator=(__static_bounded_iter const&) = default; + _LIBCPP_HIDE_FROM_ABI __static_bounded_iter& operator=(__static_bounded_iter&&) = default; + +private: + // Create an iterator wrapping the given iterator, and whose bounds are described + // by the provided [begin, begin + _Size] range. + _LIBCPP_HIDE_FROM_ABI + _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __static_bounded_iter(_Iterator __current, _Iterator __begin) + : __storage_(__current, __begin) { + _LIBCPP_ASSERT_INTERNAL( + __begin <= __current, "__static_bounded_iter(current, begin): current and begin are inconsistent"); + _LIBCPP_ASSERT_INTERNAL( + __current <= __end(), "__static_bounded_iter(current, begin): current and (begin + Size) are inconsistent"); + } + + template + friend _LIBCPP_CONSTEXPR __static_bounded_iter<_It, _Sz> __make_static_bounded_iter(_It, _It); + +public: + // Dereference and indexing operations. + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 reference operator*() const _NOEXCEPT { + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( + __current() != __end(), "__static_bounded_iter::operator*: Attempt to dereference an iterator at the end"); + return *__current(); + } + + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pointer operator->() const _NOEXCEPT { + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( + __current() != __end(), "__static_bounded_iter::operator->: Attempt to dereference an iterator at the end"); + return std::__to_address(__current()); + } + + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 reference operator[](difference_type __n) const _NOEXCEPT { + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( + __n >= __begin() - __current(), + "__static_bounded_iter::operator[]: Attempt to index an iterator past the start"); + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( + __n < __end() - __current(), + "__static_bounded_iter::operator[]: Attempt to index an iterator at or past the end"); + return __current()[__n]; + } + + // Arithmetic operations. + // + // These operations check that the iterator remains within `[begin, end]`. + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __static_bounded_iter& operator++() _NOEXCEPT { + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( + __current() != __end(), "__static_bounded_iter::operator++: Attempt to advance an iterator past the end"); + ++__current(); + return *this; + } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __static_bounded_iter operator++(int) _NOEXCEPT { + __static_bounded_iter __tmp(*this); + ++*this; + return __tmp; + } + + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __static_bounded_iter& operator--() _NOEXCEPT { + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( + __current() != __begin(), "__static_bounded_iter::operator--: Attempt to rewind an iterator past the start"); + --__current(); + return *this; + } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __static_bounded_iter operator--(int) _NOEXCEPT { + __static_bounded_iter __tmp(*this); + --*this; + return __tmp; + } + + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __static_bounded_iter& operator+=(difference_type __n) _NOEXCEPT { + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( + __n >= __begin() - __current(), + "__static_bounded_iter::operator+=: Attempt to rewind an iterator past the start"); + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( + __n <= __end() - __current(), "__static_bounded_iter::operator+=: Attempt to advance an iterator past the end"); + __current() += __n; + return *this; + } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 friend __static_bounded_iter + operator+(__static_bounded_iter const& __self, difference_type __n) _NOEXCEPT { + __static_bounded_iter __tmp(__self); + __tmp += __n; + return __tmp; + } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 friend __static_bounded_iter + operator+(difference_type __n, __static_bounded_iter const& __self) _NOEXCEPT { + __static_bounded_iter __tmp(__self); + __tmp += __n; + return __tmp; + } + + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __static_bounded_iter& operator-=(difference_type __n) _NOEXCEPT { + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( + __n <= __current() - __begin(), + "__static_bounded_iter::operator-=: Attempt to rewind an iterator past the start"); + _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( + __n >= __current() - __end(), "__static_bounded_iter::operator-=: Attempt to advance an iterator past the end"); + __current() -= __n; + return *this; + } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 friend __static_bounded_iter + operator-(__static_bounded_iter const& __self, difference_type __n) _NOEXCEPT { + __static_bounded_iter __tmp(__self); + __tmp -= __n; + return __tmp; + } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 friend difference_type + operator-(__static_bounded_iter const& __x, __static_bounded_iter const& __y) _NOEXCEPT { + return __x.__current() - __y.__current(); + } + + // Comparison operations. + // + // These operations do not check whether the iterators are within their bounds. + // The valid range for each iterator is also not considered as part of the comparison, + // i.e. two iterators pointing to the same location will be considered equal even + // if they have different validity ranges. + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR friend bool + operator==(__static_bounded_iter const& __x, __static_bounded_iter const& __y) _NOEXCEPT { + return __x.__current() == __y.__current(); + } + +#if _LIBCPP_STD_VER <= 17 + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR friend bool + operator!=(__static_bounded_iter const& __x, __static_bounded_iter const& __y) _NOEXCEPT { + return __x.__current() != __y.__current(); + } + + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR friend bool + operator<(__static_bounded_iter const& __x, __static_bounded_iter const& __y) _NOEXCEPT { + return __x.__current() < __y.__current(); + } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR friend bool + operator>(__static_bounded_iter const& __x, __static_bounded_iter const& __y) _NOEXCEPT { + return __x.__current() > __y.__current(); + } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR friend bool + operator<=(__static_bounded_iter const& __x, __static_bounded_iter const& __y) _NOEXCEPT { + return __x.__current() <= __y.__current(); + } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR friend bool + operator>=(__static_bounded_iter const& __x, __static_bounded_iter const& __y) _NOEXCEPT { + return __x.__current() >= __y.__current(); + } + +#else + _LIBCPP_HIDE_FROM_ABI constexpr friend strong_ordering + operator<=>(__static_bounded_iter const& __x, __static_bounded_iter const& __y) noexcept { + if constexpr (three_way_comparable<_Iterator, strong_ordering>) { + return __x.__current() <=> __y.__current(); + } else { + if (__x.__current() < __y.__current()) + return strong_ordering::less; + + if (__x.__current() == __y.__current()) + return strong_ordering::equal; + + return strong_ordering::greater; + } + } +#endif // _LIBCPP_STD_VER >= 20 + +private: + template + friend struct pointer_traits; + template + friend struct __static_bounded_iter; + __static_bounded_iter_storage<_Iterator, _Size> __storage_; + + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iterator& __current() _NOEXCEPT { + return __storage_.__current(); + } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iterator __current() const _NOEXCEPT { + return __storage_.__current(); + } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iterator __begin() const _NOEXCEPT { + return __storage_.__begin(); + } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iterator __end() const _NOEXCEPT { return __storage_.__end(); } +}; + +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __static_bounded_iter<_It, _Size> +__make_static_bounded_iter(_It __it, _It __begin) { + return __static_bounded_iter<_It, _Size>(std::move(__it), std::move(__begin)); +} + +#if _LIBCPP_STD_VER <= 17 +template +struct __libcpp_is_contiguous_iterator<__static_bounded_iter<_Iterator, _Size> > : true_type {}; +#endif + +template +struct pointer_traits<__static_bounded_iter<_Iterator, _Size> > { + using pointer = __static_bounded_iter<_Iterator, _Size>; + using element_type = typename pointer_traits<_Iterator>::element_type; + using difference_type = typename pointer_traits<_Iterator>::difference_type; + + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR static element_type* to_address(pointer __it) _NOEXCEPT { + return std::__to_address(__it.__current()); + } +}; + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___ITERATOR_STATIC_BOUNDED_ITER_H diff --git a/system/lib/libcxx/include/__iterator/wrap_iter.h b/system/lib/libcxx/include/__iterator/wrap_iter.h index 56183c0ee794d..966c4675b7049 100644 --- a/system/lib/libcxx/include/__iterator/wrap_iter.h +++ b/system/lib/libcxx/include/__iterator/wrap_iter.h @@ -13,12 +13,17 @@ #include <__compare/ordering.h> #include <__compare/three_way_comparable.h> #include <__config> +#include <__cstddef/size_t.h> #include <__iterator/iterator_traits.h> #include <__memory/addressof.h> #include <__memory/pointer_traits.h> +#include <__type_traits/conjunction.h> +#include <__type_traits/disjunction.h> #include <__type_traits/enable_if.h> +#include <__type_traits/integral_constant.h> #include <__type_traits/is_convertible.h> -#include +#include <__type_traits/is_same.h> +#include <__type_traits/make_const_lvalue_ref.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -44,9 +49,14 @@ class __wrap_iter { public: _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __wrap_iter() _NOEXCEPT : __i_() {} - template ::value, int> = 0> - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __wrap_iter(const __wrap_iter<_Up>& __u) _NOEXCEPT - : __i_(__u.base()) {} + template < + class _OtherIter, + __enable_if_t< _And< is_convertible, + _Or >, + is_same > > > >::value, + int> = 0> + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __wrap_iter(const __wrap_iter<_OtherIter>& __u) _NOEXCEPT + : __i_(__u.__i_) {} _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 reference operator*() const _NOEXCEPT { return *__i_; } _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pointer operator->() const _NOEXCEPT { return std::__to_address(__i_); @@ -145,9 +155,6 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT { return !(__x == __y); } -#endif - -// TODO(mordante) disable these overloads in the LLVM 20 release. template _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT { @@ -184,7 +191,7 @@ operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEX return !(__y < __x); } -#if _LIBCPP_STD_VER >= 20 +#else template _LIBCPP_HIDE_FROM_ABI constexpr strong_ordering operator<=>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) noexcept { diff --git a/system/lib/libcxx/include/__locale b/system/lib/libcxx/include/__locale index 4b382764b4464..93187dc1d0d9c 100644 --- a/system/lib/libcxx/include/__locale +++ b/system/lib/libcxx/include/__locale @@ -11,8 +11,11 @@ #define _LIBCPP___LOCALE #include <__config> + +#if _LIBCPP_HAS_LOCALIZATION + #include <__locale_dir/locale_base_api.h> -#include <__memory/shared_ptr.h> // __shared_count +#include <__memory/shared_count.h> #include <__mutex/once_flag.h> #include <__type_traits/make_unsigned.h> #include <__utility/no_destroy.h> @@ -24,18 +27,18 @@ #include // Some platforms require more includes than others. Keep the includes on all plaforms for now. -#include -#include +# include +# include -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS -# include -#else -# include <__std_mbstate_t.h> -#endif +# if _LIBCPP_HAS_WIDE_CHARACTERS +# include +# else +# include <__std_mbstate_t.h> +# endif -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif +# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +# endif _LIBCPP_BEGIN_NAMESPACE_STD @@ -50,7 +53,7 @@ _LIBCPP_HIDE_FROM_ABI const _Facet& use_facet(const locale&); class _LIBCPP_EXPORTED_FROM_ABI locale { public: // locale is essentially a shared_ptr that doesn't support weak_ptrs and never got a move constructor. - using __trivially_relocatable = locale; + using __trivially_relocatable _LIBCPP_NODEBUG = locale; // types: class _LIBCPP_EXPORTED_FROM_ABI facet; @@ -60,8 +63,9 @@ public: static const category // values assigned here are for exposition only none = 0, - collate = LC_COLLATE_MASK, ctype = LC_CTYPE_MASK, monetary = LC_MONETARY_MASK, numeric = LC_NUMERIC_MASK, - time = LC_TIME_MASK, messages = LC_MESSAGES_MASK, all = collate | ctype | monetary | numeric | time | messages; + collate = _LIBCPP_COLLATE_MASK, ctype = _LIBCPP_CTYPE_MASK, monetary = _LIBCPP_MONETARY_MASK, + numeric = _LIBCPP_NUMERIC_MASK, time = _LIBCPP_TIME_MASK, messages = _LIBCPP_MESSAGES_MASK, + all = collate | ctype | monetary | numeric | time | messages; // construct/copy/destroy: locale() _NOEXCEPT; @@ -84,9 +88,9 @@ public: // locale operations: string name() const; bool operator==(const locale&) const; -#if _LIBCPP_STD_VER <= 17 +# if _LIBCPP_STD_VER <= 17 _LIBCPP_HIDE_FROM_ABI bool operator!=(const locale& __y) const { return !(*this == __y); } -#endif +# endif template _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS bool operator()(const basic_string<_CharT, _Traits, _Allocator>&, const basic_string<_CharT, _Traits, _Allocator>&) const; @@ -236,9 +240,9 @@ long collate<_CharT>::do_hash(const char_type* __lo, const char_type* __hi) cons } extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate; -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +# if _LIBCPP_HAS_WIDE_CHARACTERS extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate; -#endif +# endif // template class collate_byname; @@ -247,7 +251,7 @@ class _LIBCPP_TEMPLATE_VIS collate_byname; template <> class _LIBCPP_EXPORTED_FROM_ABI collate_byname : public collate { - locale_t __l_; + __locale::__locale_t __l_; public: typedef char char_type; @@ -263,10 +267,10 @@ protected: string_type do_transform(const char_type* __lo, const char_type* __hi) const override; }; -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +# if _LIBCPP_HAS_WIDE_CHARACTERS template <> class _LIBCPP_EXPORTED_FROM_ABI collate_byname : public collate { - locale_t __l_; + __locale::__locale_t __l_; public: typedef wchar_t char_type; @@ -282,7 +286,7 @@ protected: const char_type* __lo1, const char_type* __hi1, const char_type* __lo2, const char_type* __hi2) const override; string_type do_transform(const char_type* __lo, const char_type* __hi) const override; }; -#endif +# endif template bool locale::operator()(const basic_string<_CharT, _Traits, _Allocator>& __x, @@ -295,7 +299,7 @@ bool locale::operator()(const basic_string<_CharT, _Traits, _Allocator>& __x, class _LIBCPP_EXPORTED_FROM_ABI ctype_base { public: -#if defined(_LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE) +# if defined(_LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE) typedef unsigned long mask; static const mask space = 1 << 0; static const mask print = 1 << 1; @@ -307,14 +311,14 @@ public: static const mask punct = 1 << 7; static const mask xdigit = 1 << 8; static const mask blank = 1 << 9; -# if defined(__BIONIC__) +# if defined(__BIONIC__) // Historically this was a part of regex_traits rather than ctype_base. The // historical value of the constant is preserved for ABI compatibility. static const mask __regex_word = 0x8000; -# else +# else static const mask __regex_word = 1 << 10; -# endif // defined(__BIONIC__) -#elif defined(__GLIBC__) +# endif // defined(__BIONIC__) +# elif defined(__GLIBC__) typedef unsigned short mask; static const mask space = _ISspace; static const mask print = _ISprint; @@ -326,12 +330,12 @@ public: static const mask punct = _ISpunct; static const mask xdigit = _ISxdigit; static const mask blank = _ISblank; -# if defined(__mips__) || (BYTE_ORDER == BIG_ENDIAN) +# if defined(__mips__) || (BYTE_ORDER == BIG_ENDIAN) static const mask __regex_word = static_cast(_ISbit(15)); -# else +# else static const mask __regex_word = 0x80; -# endif -#elif defined(_LIBCPP_MSVCRT_LIKE) +# endif +# elif defined(_LIBCPP_MSVCRT_LIKE) typedef unsigned short mask; static const mask space = _SPACE; static const mask print = _BLANK | _PUNCT | _ALPHA | _DIGIT; @@ -344,16 +348,16 @@ public: static const mask xdigit = _HEX; static const mask blank = _BLANK; static const mask __regex_word = 0x4000; // 0x8000 and 0x0100 and 0x00ff are used -# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT -# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA -#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) -# ifdef __APPLE__ - typedef __uint32_t mask; -# elif defined(__FreeBSD__) +# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT +# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA +# elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) +# ifdef __APPLE__ + typedef uint32_t mask; +# elif defined(__FreeBSD__) typedef unsigned long mask; -# elif defined(__NetBSD__) +# elif defined(__NetBSD__) typedef unsigned short mask; -# endif +# endif static const mask space = _CTYPE_S; static const mask print = _CTYPE_R; static const mask cntrl = _CTYPE_C; @@ -364,16 +368,16 @@ public: static const mask punct = _CTYPE_P; static const mask xdigit = _CTYPE_X; -# if defined(__NetBSD__) +# if defined(__NetBSD__) static const mask blank = _CTYPE_BL; // NetBSD defines classes up to 0x2000 // see sys/ctype_bits.h, _CTYPE_Q static const mask __regex_word = 0x8000; -# else +# else static const mask blank = _CTYPE_B; static const mask __regex_word = 0x80; -# endif -#elif defined(_AIX) +# endif +# elif defined(_AIX) typedef unsigned int mask; static const mask space = _ISSPACE; static const mask print = _ISPRINT; @@ -386,7 +390,7 @@ public: static const mask xdigit = _ISXDIGIT; static const mask blank = _ISBLANK; static const mask __regex_word = 0x8000; -#elif defined(_NEWLIB_VERSION) +# elif defined(_NEWLIB_VERSION) // Same type as Newlib's _ctype_ array in newlib/libc/include/ctype.h. typedef char mask; // In case char is signed, static_cast is needed to avoid warning on @@ -403,11 +407,11 @@ public: static const mask blank = static_cast(_B); // mask is already fully saturated, use a different type in regex_type_traits. static const unsigned short __regex_word = 0x100; -# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT -# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA -# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_XDIGIT -#elif defined(__MVS__) -# if defined(__NATIVE_ASCII_F) +# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT +# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA +# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_XDIGIT +# elif defined(__MVS__) +# if defined(__NATIVE_ASCII_F) typedef unsigned int mask; static const mask space = _ISSPACE_A; static const mask print = _ISPRINT_A; @@ -419,7 +423,7 @@ public: static const mask punct = _ISPUNCT_A; static const mask xdigit = _ISXDIGIT_A; static const mask blank = _ISBLANK_A; -# else +# else typedef unsigned short mask; static const mask space = __ISSPACE; static const mask print = __ISPRINT; @@ -431,11 +435,11 @@ public: static const mask punct = __ISPUNCT; static const mask xdigit = __ISXDIGIT; static const mask blank = __ISBLANK; -# endif +# endif static const mask __regex_word = 0x8000; -#else -# error unknown rune table for this platform -- do you mean to define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE? -#endif +# else +# error unknown rune table for this platform -- do you mean to define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE? +# endif static const mask alnum = alpha | digit; static const mask graph = alnum | punct; @@ -449,7 +453,7 @@ public: template class _LIBCPP_TEMPLATE_VIS ctype; -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +# if _LIBCPP_HAS_WIDE_CHARACTERS template <> class _LIBCPP_EXPORTED_FROM_ABI ctype : public locale::facet, public ctype_base { public: @@ -514,7 +518,9 @@ protected: virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const; }; -#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS +# endif // _LIBCPP_HAS_WIDE_CHARACTERS + +inline _LIBCPP_HIDE_FROM_ABI bool __libcpp_isascii(int __c) { return (__c & ~0x7F) == 0; } template <> class _LIBCPP_EXPORTED_FROM_ABI ctype : public locale::facet, public ctype_base { @@ -527,25 +533,25 @@ public: explicit ctype(const mask* __tab = nullptr, bool __del = false, size_t __refs = 0); _LIBCPP_HIDE_FROM_ABI bool is(mask __m, char_type __c) const { - return isascii(__c) ? (__tab_[static_cast(__c)] & __m) != 0 : false; + return std::__libcpp_isascii(__c) ? (__tab_[static_cast(__c)] & __m) != 0 : false; } _LIBCPP_HIDE_FROM_ABI const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const { for (; __low != __high; ++__low, ++__vec) - *__vec = isascii(*__low) ? __tab_[static_cast(*__low)] : 0; + *__vec = std::__libcpp_isascii(*__low) ? __tab_[static_cast(*__low)] : 0; return __low; } _LIBCPP_HIDE_FROM_ABI const char_type* scan_is(mask __m, const char_type* __low, const char_type* __high) const { for (; __low != __high; ++__low) - if (isascii(*__low) && (__tab_[static_cast(*__low)] & __m)) + if (std::__libcpp_isascii(*__low) && (__tab_[static_cast(*__low)] & __m)) break; return __low; } _LIBCPP_HIDE_FROM_ABI const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const { for (; __low != __high; ++__low) - if (!isascii(*__low) || !(__tab_[static_cast(*__low)] & __m)) + if (!std::__libcpp_isascii(*__low) || !(__tab_[static_cast(*__low)] & __m)) break; return __low; } @@ -577,25 +583,25 @@ public: static locale::id id; -#ifdef _CACHED_RUNES +# ifdef _CACHED_RUNES static const size_t table_size = _CACHED_RUNES; -#else +# else static const size_t table_size = 256; // FIXME: Don't hardcode this. -#endif +# endif _LIBCPP_HIDE_FROM_ABI const mask* table() const _NOEXCEPT { return __tab_; } static const mask* classic_table() _NOEXCEPT; -#if defined(__GLIBC__) || defined(__EMSCRIPTEN__) +# if defined(__GLIBC__) || defined(__EMSCRIPTEN__) static const int* __classic_upper_table() _NOEXCEPT; static const int* __classic_lower_table() _NOEXCEPT; -#endif -#if defined(__NetBSD__) +# endif +# if defined(__NetBSD__) static const short* __classic_upper_table() _NOEXCEPT; static const short* __classic_lower_table() _NOEXCEPT; -#endif -#if defined(__MVS__) +# endif +# if defined(__MVS__) static const unsigned short* __classic_upper_table() _NOEXCEPT; static const unsigned short* __classic_lower_table() _NOEXCEPT; -#endif +# endif protected: ~ctype() override; @@ -616,7 +622,7 @@ class _LIBCPP_TEMPLATE_VIS ctype_byname; template <> class _LIBCPP_EXPORTED_FROM_ABI ctype_byname : public ctype { - locale_t __l_; + __locale::__locale_t __l_; public: explicit ctype_byname(const char*, size_t = 0); @@ -630,10 +636,10 @@ protected: const char_type* do_tolower(char_type* __low, const char_type* __high) const override; }; -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +# if _LIBCPP_HAS_WIDE_CHARACTERS template <> class _LIBCPP_EXPORTED_FROM_ABI ctype_byname : public ctype { - locale_t __l_; + __locale::__locale_t __l_; public: explicit ctype_byname(const char*, size_t = 0); @@ -655,7 +661,7 @@ protected: const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const override; }; -#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS +# endif // _LIBCPP_HAS_WIDE_CHARACTERS template inline _LIBCPP_HIDE_FROM_ABI bool isspace(_CharT __c, const locale& __loc) { @@ -821,10 +827,10 @@ protected: // template <> class codecvt -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +# if _LIBCPP_HAS_WIDE_CHARACTERS template <> class _LIBCPP_EXPORTED_FROM_ABI codecvt : public locale::facet, public codecvt_base { - locale_t __l_; + __locale::__locale_t __l_; public: typedef wchar_t intern_type; @@ -900,7 +906,7 @@ protected: virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const; virtual int do_max_length() const _NOEXCEPT; }; -#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS +# endif // _LIBCPP_HAS_WIDE_CHARACTERS // template <> class codecvt // deprecated in C++20 @@ -982,7 +988,7 @@ protected: virtual int do_max_length() const _NOEXCEPT; }; -#ifndef _LIBCPP_HAS_NO_CHAR8_T +# if _LIBCPP_HAS_CHAR8_T // template <> class codecvt // C++20 @@ -1063,7 +1069,7 @@ protected: virtual int do_max_length() const _NOEXCEPT; }; -#endif +# endif // template <> class codecvt // deprecated in C++20 @@ -1145,7 +1151,7 @@ protected: virtual int do_max_length() const _NOEXCEPT; }; -#ifndef _LIBCPP_HAS_NO_CHAR8_T +# if _LIBCPP_HAS_CHAR8_T // template <> class codecvt // C++20 @@ -1226,7 +1232,7 @@ protected: virtual int do_max_length() const _NOEXCEPT; }; -#endif +# endif // template class codecvt_byname @@ -1248,17 +1254,17 @@ codecvt_byname<_InternT, _ExternT, _StateT>::~codecvt_byname() {} _LIBCPP_SUPPRESS_DEPRECATED_POP extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname; -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +# if _LIBCPP_HAS_WIDE_CHARACTERS extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname; -#endif +# endif extern template class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname; // deprecated in C++20 extern template class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname; // deprecated in C++20 -#ifndef _LIBCPP_HAS_NO_CHAR8_T +# if _LIBCPP_HAS_CHAR8_T extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname; // C++20 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname; // C++20 -#endif +# endif template struct __narrow_to_utf8 { @@ -1438,7 +1444,7 @@ protected: string __grouping_; }; -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +# if _LIBCPP_HAS_WIDE_CHARACTERS template <> class _LIBCPP_EXPORTED_FROM_ABI numpunct : public locale::facet { public: @@ -1467,7 +1473,7 @@ protected: char_type __thousands_sep_; string __grouping_; }; -#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS +# endif // _LIBCPP_HAS_WIDE_CHARACTERS // template class numpunct_byname @@ -1490,7 +1496,7 @@ private: void __init(const char*); }; -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +# if _LIBCPP_HAS_WIDE_CHARACTERS template <> class _LIBCPP_EXPORTED_FROM_ABI numpunct_byname : public numpunct { public: @@ -1506,8 +1512,10 @@ protected: private: void __init(const char*); }; -#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS +# endif // _LIBCPP_HAS_WIDE_CHARACTERS _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_HAS_LOCALIZATION + #endif // _LIBCPP___LOCALE diff --git a/system/lib/libcxx/include/__locale_dir/locale_base_api.h b/system/lib/libcxx/include/__locale_dir/locale_base_api.h index 242441e22b7f5..552815e277226 100644 --- a/system/lib/libcxx/include/__locale_dir/locale_base_api.h +++ b/system/lib/libcxx/include/__locale_dir/locale_base_api.h @@ -9,90 +9,321 @@ #ifndef _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_H #define _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_H -#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__EMSCRIPTEN__) -# include -#elif defined(_LIBCPP_MSVCRT_LIKE) -# include <__locale_dir/locale_base_api/win32.h> -#elif defined(_AIX) || defined(__MVS__) -# include <__locale_dir/locale_base_api/ibm.h> -#elif defined(__ANDROID__) -# include <__locale_dir/locale_base_api/android.h> -#elif defined(__sun__) -# include <__locale_dir/locale_base_api/solaris.h> -#elif defined(_NEWLIB_VERSION) -# include <__locale_dir/locale_base_api/newlib.h> -#elif defined(__OpenBSD__) -# include <__locale_dir/locale_base_api/openbsd.h> -#elif defined(__Fuchsia__) -# include <__locale_dir/locale_base_api/fuchsia.h> -#elif defined(__wasi__) || defined(_LIBCPP_HAS_MUSL_LIBC) -# include <__locale_dir/locale_base_api/musl.h> -#endif +#include <__config> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header #endif -/* -The platform-specific headers have to provide the following interface: - -// TODO: rename this to __libcpp_locale_t -using locale_t = implementation-defined; - -implementation-defined __libcpp_mb_cur_max_l(locale_t); -wint_t __libcpp_btowc_l(int, locale_t); -int __libcpp_wctob_l(wint_t, locale_t); -size_t __libcpp_wcsnrtombs_l(char* dest, const wchar_t** src, size_t wide_char_count, size_t len, mbstate_t, locale_t); -size_t __libcpp_wcrtomb_l(char* str, wchar_t wide_char, mbstate_t*, locale_t); -size_t __libcpp_mbsnrtowcs_l(wchar_t* dest, const char** src, size_t max_out, size_t len, mbstate_t*, locale_t); -size_t __libcpp_mbrtowc_l(wchar_t* dest, cosnt char* src, size_t count, mbstate_t*, locale_t); -int __libcpp_mbtowc_l(wchar_t* dest, const char* src, size_t count, locale_t); -size_t __libcpp_mbrlen_l(const char* str, size_t count, mbstate_t*, locale_t); -lconv* __libcpp_localeconv_l(locale_t); -size_t __libcpp_mbsrtowcs_l(wchar_t* dest, const char** src, size_t len, mbstate_t*, locale_t); -int __libcpp_snprintf_l(char* dest, size_t buff_size, locale_t, const char* format, ...); -int __libcpp_asprintf_l(char** dest, locale_t, const char* format, ...); -int __libcpp_sscanf_l(const char* dest, locale_t, const char* format, ...); - -// TODO: change these to reserved names -float strtof_l(const char* str, char** str_end, locale_t); -double strtod_l(const char* str, char** str_end, locale_t); -long double strtold_l(const char* str, char** str_end, locale_t); -long long strtoll_l(const char* str, char** str_end, locale_t); -unsigned long long strtoull_l(const char* str, char** str_end, locale_t); - -locale_t newlocale(int category_mask, const char* locale, locale_t base); -void freelocale(locale_t); - -int islower_l(int ch, locale_t); -int isupper_l(int ch, locale_t); -int isdigit_l(int ch, locale_t); -int isxdigit_l(int ch, locale_t); -int strcoll_l(const char* lhs, const char* rhs, locale_t); -size_t strxfrm_l(char* dst, const char* src, size_t n, locale_t); -int wcscoll_l(const char* lhs, const char* rhs, locale_t); -size_t wcsxfrm_l(wchar_t* dst, const wchar_t* src, size_t n, locale_t); -int toupper_l(int ch, locale_t); -int tolower_l(int ch, locale_t); -int iswspace_l(wint_t ch, locale_t); -int iswprint_l(wint_t ch, locale_t); -int iswcntrl_l(wint_t ch, locale_t); -int iswupper_l(wint_t ch, locale_t); -int iswlower_l(wint_t ch, locale_t); -int iswalpha_l(wint_t ch, locale_t); -int iswblank_l(wint_t ch, locale_t); -int iswdigit_l(wint_t ch, locale_t); -int iswpunct_l(wint_t ch, locale_t); -int iswxdigit_l(wint_t ch, locale_t); -wint_t towupper_l(wint_t ch, locale_t); -wint_t towlower_l(wint_t ch, locale_t); -size_t strftime_l(char* str, size_t len, const char* format, const tm*, locale_t); - - -These functions are equivalent to their C counterparts, -except that locale_t is used instead of the current global locale. - -The variadic functions may be implemented as templates with a parameter pack instead of variadic functions. -*/ +// The platform-specific headers have to provide the following interface. +// +// These functions are equivalent to their C counterparts, except that __locale::__locale_t +// is used instead of the current global locale. +// +// Variadic functions may be implemented as templates with a parameter pack instead +// of C-style variadic functions. +// +// Most of these functions are only required when building the library. Functions that are also +// required when merely using the headers are marked as such below. +// +// TODO: __localeconv shouldn't take a reference, but the Windows implementation doesn't allow copying __locale_t +// TODO: Eliminate the need for any of these functions from the headers. +// +// Locale management +// ----------------- +// namespace __locale { +// using __locale_t = implementation-defined; // required by the headers +// using __lconv_t = implementation-defined; +// __locale_t __newlocale(int, const char*, __locale_t); +// void __freelocale(__locale_t); +// char* __setlocale(int, const char*); +// __lconv_t* __localeconv(__locale_t&); +// } +// +// // required by the headers +// #define _LIBCPP_COLLATE_MASK /* implementation-defined */ +// #define _LIBCPP_CTYPE_MASK /* implementation-defined */ +// #define _LIBCPP_MONETARY_MASK /* implementation-defined */ +// #define _LIBCPP_NUMERIC_MASK /* implementation-defined */ +// #define _LIBCPP_TIME_MASK /* implementation-defined */ +// #define _LIBCPP_MESSAGES_MASK /* implementation-defined */ +// #define _LIBCPP_ALL_MASK /* implementation-defined */ +// #define _LIBCPP_LC_ALL /* implementation-defined */ +// +// Strtonum functions +// ------------------ +// namespace __locale { +// // required by the headers +// float __strtof(const char*, char**, __locale_t); +// double __strtod(const char*, char**, __locale_t); +// long double __strtold(const char*, char**, __locale_t); +// long long __strtoll(const char*, char**, __locale_t); +// unsigned long long __strtoull(const char*, char**, __locale_t); +// } +// +// Character manipulation functions +// -------------------------------- +// namespace __locale { +// int __islower(int, __locale_t); +// int __isupper(int, __locale_t); +// int __isdigit(int, __locale_t); // required by the headers +// int __isxdigit(int, __locale_t); // required by the headers +// int __toupper(int, __locale_t); +// int __tolower(int, __locale_t); +// int __strcoll(const char*, const char*, __locale_t); +// size_t __strxfrm(char*, const char*, size_t, __locale_t); +// +// int __iswctype(wint_t, wctype_t, __locale_t); +// int __iswspace(wint_t, __locale_t); +// int __iswprint(wint_t, __locale_t); +// int __iswcntrl(wint_t, __locale_t); +// int __iswupper(wint_t, __locale_t); +// int __iswlower(wint_t, __locale_t); +// int __iswalpha(wint_t, __locale_t); +// int __iswblank(wint_t, __locale_t); +// int __iswdigit(wint_t, __locale_t); +// int __iswpunct(wint_t, __locale_t); +// int __iswxdigit(wint_t, __locale_t); +// wint_t __towupper(wint_t, __locale_t); +// wint_t __towlower(wint_t, __locale_t); +// int __wcscoll(const wchar_t*, const wchar_t*, __locale_t); +// size_t __wcsxfrm(wchar_t*, const wchar_t*, size_t, __locale_t); +// +// size_t __strftime(char*, size_t, const char*, const tm*, __locale_t); +// } +// +// Other functions +// --------------- +// namespace __locale { +// implementation-defined __mb_len_max(__locale_t); +// wint_t __btowc(int, __locale_t); +// int __wctob(wint_t, __locale_t); +// size_t __wcsnrtombs(char*, const wchar_t**, size_t, size_t, mbstate_t*, __locale_t); +// size_t __wcrtomb(char*, wchar_t, mbstate_t*, __locale_t); +// size_t __mbsnrtowcs(wchar_t*, const char**, size_t, size_t, mbstate_t*, __locale_t); +// size_t __mbrtowc(wchar_t*, const char*, size_t, mbstate_t*, __locale_t); +// int __mbtowc(wchar_t*, const char*, size_t, __locale_t); +// size_t __mbrlen(const char*, size_t, mbstate_t*, __locale_t); +// size_t __mbsrtowcs(wchar_t*, const char**, size_t, mbstate_t*, __locale_t); +// +// int __snprintf(char*, size_t, __locale_t, const char*, ...); // required by the headers +// int __asprintf(char**, __locale_t, const char*, ...); // required by the headers +// int __sscanf(const char*, __locale_t, const char*, ...); // required by the headers +// } + +#if _LIBCPP_HAS_LOCALIZATION + +# if defined(__APPLE__) +# include <__locale_dir/support/apple.h> +# elif defined(__FreeBSD__) +# include <__locale_dir/support/freebsd.h> +# elif defined(_LIBCPP_MSVCRT_LIKE) +# include <__locale_dir/support/windows.h> +# elif defined(__Fuchsia__) +# include <__locale_dir/support/fuchsia.h> +# else + +// TODO: This is a temporary definition to bridge between the old way we defined the locale base API +// (by providing global non-reserved names) and the new API. As we move individual platforms +// towards the new way of defining the locale base API, this should disappear since each platform +// will define those directly. +# if defined(__EMSCRIPTEN__) +# include +# elif defined(_AIX) || defined(__MVS__) +# include <__locale_dir/locale_base_api/ibm.h> +# elif defined(__ANDROID__) +# include <__locale_dir/locale_base_api/android.h> +# elif defined(__OpenBSD__) +# include <__locale_dir/locale_base_api/openbsd.h> +# elif defined(__wasi__) || _LIBCPP_HAS_MUSL_LIBC +# include <__locale_dir/locale_base_api/musl.h> +# endif + +# include <__locale_dir/locale_base_api/bsd_locale_fallbacks.h> + +# include <__cstddef/size_t.h> +# include <__utility/forward.h> +# include +# include +# include +# if _LIBCPP_HAS_WIDE_CHARACTERS +# include +# endif +_LIBCPP_BEGIN_NAMESPACE_STD +namespace __locale { +// +// Locale management +// +# define _LIBCPP_COLLATE_MASK LC_COLLATE_MASK +# define _LIBCPP_CTYPE_MASK LC_CTYPE_MASK +# define _LIBCPP_MONETARY_MASK LC_MONETARY_MASK +# define _LIBCPP_NUMERIC_MASK LC_NUMERIC_MASK +# define _LIBCPP_TIME_MASK LC_TIME_MASK +# define _LIBCPP_MESSAGES_MASK LC_MESSAGES_MASK +# define _LIBCPP_ALL_MASK LC_ALL_MASK +# define _LIBCPP_LC_ALL LC_ALL + +using __locale_t _LIBCPP_NODEBUG = locale_t; + +# if defined(_LIBCPP_BUILDING_LIBRARY) +using __lconv_t _LIBCPP_NODEBUG = lconv; + +inline _LIBCPP_HIDE_FROM_ABI __locale_t __newlocale(int __category_mask, const char* __name, __locale_t __loc) { + return newlocale(__category_mask, __name, __loc); +} + +inline _LIBCPP_HIDE_FROM_ABI char* __setlocale(int __category, char const* __locale) { + return ::setlocale(__category, __locale); +} + +inline _LIBCPP_HIDE_FROM_ABI void __freelocale(__locale_t __loc) { freelocale(__loc); } + +inline _LIBCPP_HIDE_FROM_ABI __lconv_t* __localeconv(__locale_t& __loc) { return __libcpp_localeconv_l(__loc); } +# endif // _LIBCPP_BUILDING_LIBRARY + +// +// Strtonum functions +// +inline _LIBCPP_HIDE_FROM_ABI float __strtof(const char* __nptr, char** __endptr, __locale_t __loc) { + return strtof_l(__nptr, __endptr, __loc); +} + +inline _LIBCPP_HIDE_FROM_ABI double __strtod(const char* __nptr, char** __endptr, __locale_t __loc) { + return strtod_l(__nptr, __endptr, __loc); +} + +inline _LIBCPP_HIDE_FROM_ABI long double __strtold(const char* __nptr, char** __endptr, __locale_t __loc) { + return strtold_l(__nptr, __endptr, __loc); +} + +inline _LIBCPP_HIDE_FROM_ABI long long __strtoll(const char* __nptr, char** __endptr, int __base, __locale_t __loc) { + return strtoll_l(__nptr, __endptr, __base, __loc); +} + +inline _LIBCPP_HIDE_FROM_ABI unsigned long long +__strtoull(const char* __nptr, char** __endptr, int __base, __locale_t __loc) { + return strtoull_l(__nptr, __endptr, __base, __loc); +} + +// +// Character manipulation functions +// +# if defined(_LIBCPP_BUILDING_LIBRARY) +inline _LIBCPP_HIDE_FROM_ABI int __islower(int __ch, __locale_t __loc) { return islower_l(__ch, __loc); } +inline _LIBCPP_HIDE_FROM_ABI int __isupper(int __ch, __locale_t __loc) { return isupper_l(__ch, __loc); } +# endif + +inline _LIBCPP_HIDE_FROM_ABI int __isdigit(int __ch, __locale_t __loc) { return isdigit_l(__ch, __loc); } +inline _LIBCPP_HIDE_FROM_ABI int __isxdigit(int __ch, __locale_t __loc) { return isxdigit_l(__ch, __loc); } + +# if defined(_LIBCPP_BUILDING_LIBRARY) +inline _LIBCPP_HIDE_FROM_ABI int __strcoll(const char* __s1, const char* __s2, __locale_t __loc) { + return strcoll_l(__s1, __s2, __loc); +} +inline _LIBCPP_HIDE_FROM_ABI size_t __strxfrm(char* __dest, const char* __src, size_t __n, __locale_t __loc) { + return strxfrm_l(__dest, __src, __n, __loc); +} +inline _LIBCPP_HIDE_FROM_ABI int __toupper(int __ch, __locale_t __loc) { return toupper_l(__ch, __loc); } +inline _LIBCPP_HIDE_FROM_ABI int __tolower(int __ch, __locale_t __loc) { return tolower_l(__ch, __loc); } + +# if _LIBCPP_HAS_WIDE_CHARACTERS +inline _LIBCPP_HIDE_FROM_ABI int __wcscoll(const wchar_t* __s1, const wchar_t* __s2, __locale_t __loc) { + return wcscoll_l(__s1, __s2, __loc); +} +inline _LIBCPP_HIDE_FROM_ABI size_t __wcsxfrm(wchar_t* __dest, const wchar_t* __src, size_t __n, __locale_t __loc) { + return wcsxfrm_l(__dest, __src, __n, __loc); +} +inline _LIBCPP_HIDE_FROM_ABI int __iswctype(wint_t __ch, wctype_t __type, __locale_t __loc) { + return iswctype_l(__ch, __type, __loc); +} +inline _LIBCPP_HIDE_FROM_ABI int __iswspace(wint_t __ch, __locale_t __loc) { return iswspace_l(__ch, __loc); } +inline _LIBCPP_HIDE_FROM_ABI int __iswprint(wint_t __ch, __locale_t __loc) { return iswprint_l(__ch, __loc); } +inline _LIBCPP_HIDE_FROM_ABI int __iswcntrl(wint_t __ch, __locale_t __loc) { return iswcntrl_l(__ch, __loc); } +inline _LIBCPP_HIDE_FROM_ABI int __iswupper(wint_t __ch, __locale_t __loc) { return iswupper_l(__ch, __loc); } +inline _LIBCPP_HIDE_FROM_ABI int __iswlower(wint_t __ch, __locale_t __loc) { return iswlower_l(__ch, __loc); } +inline _LIBCPP_HIDE_FROM_ABI int __iswalpha(wint_t __ch, __locale_t __loc) { return iswalpha_l(__ch, __loc); } +inline _LIBCPP_HIDE_FROM_ABI int __iswblank(wint_t __ch, __locale_t __loc) { return iswblank_l(__ch, __loc); } +inline _LIBCPP_HIDE_FROM_ABI int __iswdigit(wint_t __ch, __locale_t __loc) { return iswdigit_l(__ch, __loc); } +inline _LIBCPP_HIDE_FROM_ABI int __iswpunct(wint_t __ch, __locale_t __loc) { return iswpunct_l(__ch, __loc); } +inline _LIBCPP_HIDE_FROM_ABI int __iswxdigit(wint_t __ch, __locale_t __loc) { return iswxdigit_l(__ch, __loc); } +inline _LIBCPP_HIDE_FROM_ABI wint_t __towupper(wint_t __ch, __locale_t __loc) { return towupper_l(__ch, __loc); } +inline _LIBCPP_HIDE_FROM_ABI wint_t __towlower(wint_t __ch, __locale_t __loc) { return towlower_l(__ch, __loc); } +# endif + +inline _LIBCPP_HIDE_FROM_ABI size_t +__strftime(char* __s, size_t __max, const char* __format, const tm* __tm, __locale_t __loc) { + return strftime_l(__s, __max, __format, __tm, __loc); +} + +// +// Other functions +// +inline _LIBCPP_HIDE_FROM_ABI decltype(__libcpp_mb_cur_max_l(__locale_t())) __mb_len_max(__locale_t __loc) { + return __libcpp_mb_cur_max_l(__loc); +} +# if _LIBCPP_HAS_WIDE_CHARACTERS +inline _LIBCPP_HIDE_FROM_ABI wint_t __btowc(int __ch, __locale_t __loc) { return __libcpp_btowc_l(__ch, __loc); } +inline _LIBCPP_HIDE_FROM_ABI int __wctob(wint_t __ch, __locale_t __loc) { return __libcpp_wctob_l(__ch, __loc); } +inline _LIBCPP_HIDE_FROM_ABI size_t +__wcsnrtombs(char* __dest, const wchar_t** __src, size_t __nwc, size_t __len, mbstate_t* __ps, __locale_t __loc) { + return __libcpp_wcsnrtombs_l(__dest, __src, __nwc, __len, __ps, __loc); +} +inline _LIBCPP_HIDE_FROM_ABI size_t __wcrtomb(char* __s, wchar_t __ch, mbstate_t* __ps, __locale_t __loc) { + return __libcpp_wcrtomb_l(__s, __ch, __ps, __loc); +} +inline _LIBCPP_HIDE_FROM_ABI size_t +__mbsnrtowcs(wchar_t* __dest, const char** __src, size_t __nms, size_t __len, mbstate_t* __ps, __locale_t __loc) { + return __libcpp_mbsnrtowcs_l(__dest, __src, __nms, __len, __ps, __loc); +} +inline _LIBCPP_HIDE_FROM_ABI size_t +__mbrtowc(wchar_t* __pwc, const char* __s, size_t __n, mbstate_t* __ps, __locale_t __loc) { + return __libcpp_mbrtowc_l(__pwc, __s, __n, __ps, __loc); +} +inline _LIBCPP_HIDE_FROM_ABI int __mbtowc(wchar_t* __pwc, const char* __pmb, size_t __max, __locale_t __loc) { + return __libcpp_mbtowc_l(__pwc, __pmb, __max, __loc); +} +inline _LIBCPP_HIDE_FROM_ABI size_t __mbrlen(const char* __s, size_t __n, mbstate_t* __ps, __locale_t __loc) { + return __libcpp_mbrlen_l(__s, __n, __ps, __loc); +} +inline _LIBCPP_HIDE_FROM_ABI size_t +__mbsrtowcs(wchar_t* __dest, const char** __src, size_t __len, mbstate_t* __ps, __locale_t __loc) { + return __libcpp_mbsrtowcs_l(__dest, __src, __len, __ps, __loc); +} +# endif // _LIBCPP_HAS_WIDE_CHARACTERS +# endif // _LIBCPP_BUILDING_LIBRARY + +_LIBCPP_DIAGNOSTIC_PUSH +_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wgcc-compat") +_LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wformat-nonliteral") // GCC doesn't support [[gnu::format]] on variadic templates +# ifdef _LIBCPP_COMPILER_CLANG_BASED +# define _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(...) _LIBCPP_ATTRIBUTE_FORMAT(__VA_ARGS__) +# else +# define _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(...) /* nothing */ +# endif + +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__printf__, 4, 5) int __snprintf( + char* __s, size_t __n, __locale_t __loc, const char* __format, _Args&&... __args) { + return std::__libcpp_snprintf_l(__s, __n, __loc, __format, std::forward<_Args>(__args)...); +} +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__printf__, 3, 4) int __asprintf( + char** __s, __locale_t __loc, const char* __format, _Args&&... __args) { + return std::__libcpp_asprintf_l(__s, __loc, __format, std::forward<_Args>(__args)...); +} +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__scanf__, 3, 4) int __sscanf( + const char* __s, __locale_t __loc, const char* __format, _Args&&... __args) { + return std::__libcpp_sscanf_l(__s, __loc, __format, std::forward<_Args>(__args)...); +} +_LIBCPP_DIAGNOSTIC_POP +# undef _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT + +} // namespace __locale +_LIBCPP_END_NAMESPACE_STD + +# endif // Compatibility definition of locale base APIs + +#endif // _LIBCPP_HAS_LOCALIZATION #endif // _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_H diff --git a/system/lib/libcxx/include/__locale_dir/locale_base_api/android.h b/system/lib/libcxx/include/__locale_dir/locale_base_api/android.h index 9965d8bbf6a2e..36b8d93e1b228 100644 --- a/system/lib/libcxx/include/__locale_dir/locale_base_api/android.h +++ b/system/lib/libcxx/include/__locale_dir/locale_base_api/android.h @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#ifndef _LIBCPP___LOCALE_LOCALE_BASE_API_ANDROID_H -#define _LIBCPP___LOCALE_LOCALE_BASE_API_ANDROID_H +#ifndef _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_ANDROID_H +#define _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_ANDROID_H #include @@ -18,9 +18,6 @@ extern "C" { } #include -#if __ANDROID_API__ < 21 -# include <__support/xlocale/__posix_l_fallback.h> -#endif // If we do not have this header, we are in a platform build rather than an NDK // build, which will always be at least as new as the ToT NDK, in which case we @@ -30,9 +27,7 @@ extern "C" { // In NDK versions later than 16, locale-aware functions are provided by // legacy_stdlib_inlines.h # if __NDK_MAJOR__ <= 16 -# if __ANDROID_API__ < 21 -# include <__support/xlocale/__strtonum_fallback.h> -# elif __ANDROID_API__ < 26 +# if __ANDROID_API__ < 26 inline _LIBCPP_HIDE_FROM_ABI float strtof_l(const char* __nptr, char** __endptr, locale_t) { return ::strtof(__nptr, __endptr); @@ -47,4 +42,4 @@ inline _LIBCPP_HIDE_FROM_ABI double strtod_l(const char* __nptr, char** __endptr # endif // __NDK_MAJOR__ <= 16 #endif // __has_include() -#endif // _LIBCPP___LOCALE_LOCALE_BASE_API_ANDROID_H +#endif // _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_ANDROID_H diff --git a/system/lib/libcxx/include/__locale_dir/locale_base_api/bsd_locale_defaults.h b/system/lib/libcxx/include/__locale_dir/locale_base_api/bsd_locale_defaults.h deleted file mode 100644 index 1f9607209842c..0000000000000 --- a/system/lib/libcxx/include/__locale_dir/locale_base_api/bsd_locale_defaults.h +++ /dev/null @@ -1,36 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -// The BSDs have lots of *_l functions. We don't want to define those symbols -// on other platforms though, for fear of conflicts with user code. So here, -// we will define the mapping from an internal macro to the real BSD symbol. -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___LOCALE_LOCALE_BASE_API_BSD_LOCALE_DEFAULTS_H -#define _LIBCPP___LOCALE_LOCALE_BASE_API_BSD_LOCALE_DEFAULTS_H - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -#define __libcpp_mb_cur_max_l(loc) MB_CUR_MAX_L(loc) -#define __libcpp_btowc_l(ch, loc) btowc_l(ch, loc) -#define __libcpp_wctob_l(wch, loc) wctob_l(wch, loc) -#define __libcpp_wcsnrtombs_l(dst, src, nwc, len, ps, loc) wcsnrtombs_l(dst, src, nwc, len, ps, loc) -#define __libcpp_wcrtomb_l(src, wc, ps, loc) wcrtomb_l(src, wc, ps, loc) -#define __libcpp_mbsnrtowcs_l(dst, src, nms, len, ps, loc) mbsnrtowcs_l(dst, src, nms, len, ps, loc) -#define __libcpp_mbrtowc_l(pwc, s, n, ps, l) mbrtowc_l(pwc, s, n, ps, l) -#define __libcpp_mbtowc_l(pwc, pmb, max, l) mbtowc_l(pwc, pmb, max, l) -#define __libcpp_mbrlen_l(s, n, ps, l) mbrlen_l(s, n, ps, l) -#define __libcpp_localeconv_l(l) localeconv_l(l) -#define __libcpp_mbsrtowcs_l(dest, src, len, ps, l) mbsrtowcs_l(dest, src, len, ps, l) -#define __libcpp_snprintf_l(...) snprintf_l(__VA_ARGS__) -#define __libcpp_asprintf_l(...) asprintf_l(__VA_ARGS__) -#define __libcpp_sscanf_l(...) sscanf_l(__VA_ARGS__) - -#endif // _LIBCPP___LOCALE_LOCALE_BASE_API_BSD_LOCALE_DEFAULTS_H diff --git a/system/lib/libcxx/include/__locale_dir/locale_base_api/bsd_locale_fallbacks.h b/system/lib/libcxx/include/__locale_dir/locale_base_api/bsd_locale_fallbacks.h index 76b94287cd6cc..b62a1b737e97f 100644 --- a/system/lib/libcxx/include/__locale_dir/locale_base_api/bsd_locale_fallbacks.h +++ b/system/lib/libcxx/include/__locale_dir/locale_base_api/bsd_locale_fallbacks.h @@ -10,15 +10,15 @@ // of those functions for non-BSD platforms. //===----------------------------------------------------------------------===// -#ifndef _LIBCPP___LOCALE_LOCALE_BASE_API_BSD_LOCALE_FALLBACKS_H -#define _LIBCPP___LOCALE_LOCALE_BASE_API_BSD_LOCALE_FALLBACKS_H +#ifndef _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_BSD_LOCALE_FALLBACKS_H +#define _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_BSD_LOCALE_FALLBACKS_H -#include <__locale_dir/locale_base_api/locale_guard.h> -#include +#include #include +#include #include -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +#if _LIBCPP_HAS_WIDE_CHARACTERS # include #endif @@ -28,65 +28,79 @@ _LIBCPP_BEGIN_NAMESPACE_STD +struct __locale_guard { + _LIBCPP_HIDE_FROM_ABI __locale_guard(locale_t& __loc) : __old_loc_(::uselocale(__loc)) {} + + _LIBCPP_HIDE_FROM_ABI ~__locale_guard() { + if (__old_loc_) + ::uselocale(__old_loc_); + } + + locale_t __old_loc_; + + __locale_guard(__locale_guard const&) = delete; + __locale_guard& operator=(__locale_guard const&) = delete; +}; + inline _LIBCPP_HIDE_FROM_ABI decltype(MB_CUR_MAX) __libcpp_mb_cur_max_l(locale_t __l) { - __libcpp_locale_guard __current(__l); + __locale_guard __current(__l); return MB_CUR_MAX; } -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +#if _LIBCPP_HAS_WIDE_CHARACTERS inline _LIBCPP_HIDE_FROM_ABI wint_t __libcpp_btowc_l(int __c, locale_t __l) { - __libcpp_locale_guard __current(__l); + __locale_guard __current(__l); return btowc(__c); } inline _LIBCPP_HIDE_FROM_ABI int __libcpp_wctob_l(wint_t __c, locale_t __l) { - __libcpp_locale_guard __current(__l); + __locale_guard __current(__l); return wctob(__c); } inline _LIBCPP_HIDE_FROM_ABI size_t __libcpp_wcsnrtombs_l(char* __dest, const wchar_t** __src, size_t __nwc, size_t __len, mbstate_t* __ps, locale_t __l) { - __libcpp_locale_guard __current(__l); + __locale_guard __current(__l); return wcsnrtombs(__dest, __src, __nwc, __len, __ps); } inline _LIBCPP_HIDE_FROM_ABI size_t __libcpp_wcrtomb_l(char* __s, wchar_t __wc, mbstate_t* __ps, locale_t __l) { - __libcpp_locale_guard __current(__l); + __locale_guard __current(__l); return wcrtomb(__s, __wc, __ps); } inline _LIBCPP_HIDE_FROM_ABI size_t __libcpp_mbsnrtowcs_l(wchar_t* __dest, const char** __src, size_t __nms, size_t __len, mbstate_t* __ps, locale_t __l) { - __libcpp_locale_guard __current(__l); + __locale_guard __current(__l); return mbsnrtowcs(__dest, __src, __nms, __len, __ps); } inline _LIBCPP_HIDE_FROM_ABI size_t __libcpp_mbrtowc_l(wchar_t* __pwc, const char* __s, size_t __n, mbstate_t* __ps, locale_t __l) { - __libcpp_locale_guard __current(__l); + __locale_guard __current(__l); return mbrtowc(__pwc, __s, __n, __ps); } inline _LIBCPP_HIDE_FROM_ABI int __libcpp_mbtowc_l(wchar_t* __pwc, const char* __pmb, size_t __max, locale_t __l) { - __libcpp_locale_guard __current(__l); + __locale_guard __current(__l); return mbtowc(__pwc, __pmb, __max); } inline _LIBCPP_HIDE_FROM_ABI size_t __libcpp_mbrlen_l(const char* __s, size_t __n, mbstate_t* __ps, locale_t __l) { - __libcpp_locale_guard __current(__l); + __locale_guard __current(__l); return mbrlen(__s, __n, __ps); } -#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS +#endif // _LIBCPP_HAS_WIDE_CHARACTERS -inline _LIBCPP_HIDE_FROM_ABI lconv* __libcpp_localeconv_l(locale_t __l) { - __libcpp_locale_guard __current(__l); +inline _LIBCPP_HIDE_FROM_ABI lconv* __libcpp_localeconv_l(locale_t& __l) { + __locale_guard __current(__l); return localeconv(); } -#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS +#if _LIBCPP_HAS_WIDE_CHARACTERS inline _LIBCPP_HIDE_FROM_ABI size_t __libcpp_mbsrtowcs_l(wchar_t* __dest, const char** __src, size_t __len, mbstate_t* __ps, locale_t __l) { - __libcpp_locale_guard __current(__l); + __locale_guard __current(__l); return mbsrtowcs(__dest, __src, __len, __ps); } #endif @@ -95,7 +109,7 @@ inline _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 4, 5) int __libcpp_snprintf_l( char* __s, size_t __n, locale_t __l, const char* __format, ...) { va_list __va; va_start(__va, __format); - __libcpp_locale_guard __current(__l); + __locale_guard __current(__l); int __res = vsnprintf(__s, __n, __format, __va); va_end(__va); return __res; @@ -105,7 +119,7 @@ inline _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 3, 4) int __libcpp_asprintf_l( char** __s, locale_t __l, const char* __format, ...) { va_list __va; va_start(__va, __format); - __libcpp_locale_guard __current(__l); + __locale_guard __current(__l); int __res = vasprintf(__s, __format, __va); va_end(__va); return __res; @@ -115,7 +129,7 @@ inline _LIBCPP_ATTRIBUTE_FORMAT(__scanf__, 3, 4) int __libcpp_sscanf_l( const char* __s, locale_t __l, const char* __format, ...) { va_list __va; va_start(__va, __format); - __libcpp_locale_guard __current(__l); + __locale_guard __current(__l); int __res = vsscanf(__s, __format, __va); va_end(__va); return __res; @@ -123,4 +137,4 @@ inline _LIBCPP_ATTRIBUTE_FORMAT(__scanf__, 3, 4) int __libcpp_sscanf_l( _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP___LOCALE_LOCALE_BASE_API_BSD_LOCALE_FALLBACKS_H +#endif // _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_BSD_LOCALE_FALLBACKS_H diff --git a/system/lib/libcxx/include/__locale_dir/locale_base_api/ibm.h b/system/lib/libcxx/include/__locale_dir/locale_base_api/ibm.h index 01af20194428b..1d1d15df9f799 100644 --- a/system/lib/libcxx/include/__locale_dir/locale_base_api/ibm.h +++ b/system/lib/libcxx/include/__locale_dir/locale_base_api/ibm.h @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#ifndef _LIBCPP___LOCALE_LOCALE_BASE_API_IBM_H -#define _LIBCPP___LOCALE_LOCALE_BASE_API_IBM_H +#ifndef _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_IBM_H +#define _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_IBM_H #if defined(__MVS__) # include <__support/ibm/locale_mgmt_zos.h> @@ -82,7 +82,7 @@ strtoull_l(const char* __nptr, char** __endptr, int __base, locale_t locale) { inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 2, 0) int vasprintf(char** strp, const char* fmt, va_list ap) { const size_t buff_size = 256; - if ((*strp = (char*)malloc(buff_size)) == NULL) { + if ((*strp = (char*)malloc(buff_size)) == nullptr) { return -1; } @@ -97,7 +97,7 @@ _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 2, 0) int vasprintf(char** strp, const char va_end(ap_copy); if ((size_t)str_size >= buff_size) { - if ((*strp = (char*)realloc(*strp, str_size + 1)) == NULL) { + if ((*strp = (char*)realloc(*strp, str_size + 1)) == nullptr) { return -1; } str_size = vsnprintf(*strp, str_size + 1, fmt, ap); @@ -105,4 +105,4 @@ _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 2, 0) int vasprintf(char** strp, const char return str_size; } -#endif // _LIBCPP___LOCALE_LOCALE_BASE_API_IBM_H +#endif // _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_IBM_H diff --git a/system/lib/libcxx/include/__locale_dir/locale_base_api/locale_guard.h b/system/lib/libcxx/include/__locale_dir/locale_base_api/locale_guard.h deleted file mode 100644 index 2baacb51cd065..0000000000000 --- a/system/lib/libcxx/include/__locale_dir/locale_base_api/locale_guard.h +++ /dev/null @@ -1,78 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___LOCALE_LOCALE_BASE_API_LOCALE_GUARD_H -#define _LIBCPP___LOCALE_LOCALE_BASE_API_LOCALE_GUARD_H - -#include <__config> -#include <__locale> // for locale_t -#include - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -#if !defined(_LIBCPP_LOCALE__L_EXTENSIONS) -struct __libcpp_locale_guard { - _LIBCPP_HIDE_FROM_ABI __libcpp_locale_guard(locale_t& __loc) : __old_loc_(uselocale(__loc)) {} - - _LIBCPP_HIDE_FROM_ABI ~__libcpp_locale_guard() { - if (__old_loc_) - uselocale(__old_loc_); - } - - locale_t __old_loc_; - - __libcpp_locale_guard(__libcpp_locale_guard const&) = delete; - __libcpp_locale_guard& operator=(__libcpp_locale_guard const&) = delete; -}; -#elif defined(_LIBCPP_MSVCRT_LIKE) -struct __libcpp_locale_guard { - __libcpp_locale_guard(locale_t __l) : __status(_configthreadlocale(_ENABLE_PER_THREAD_LOCALE)) { - // Setting the locale can be expensive even when the locale given is - // already the current locale, so do an explicit check to see if the - // current locale is already the one we want. - const char* __lc = __setlocale(nullptr); - // If every category is the same, the locale string will simply be the - // locale name, otherwise it will be a semicolon-separated string listing - // each category. In the second case, we know at least one category won't - // be what we want, so we only have to check the first case. - if (std::strcmp(__l.__get_locale(), __lc) != 0) { - __locale_all = _strdup(__lc); - if (__locale_all == nullptr) - __throw_bad_alloc(); - __setlocale(__l.__get_locale()); - } - } - ~__libcpp_locale_guard() { - // The CRT documentation doesn't explicitly say, but setlocale() does the - // right thing when given a semicolon-separated list of locale settings - // for the different categories in the same format as returned by - // setlocale(LC_ALL, nullptr). - if (__locale_all != nullptr) { - __setlocale(__locale_all); - free(__locale_all); - } - _configthreadlocale(__status); - } - static const char* __setlocale(const char* __locale) { - const char* __new_locale = setlocale(LC_ALL, __locale); - if (__new_locale == nullptr) - __throw_bad_alloc(); - return __new_locale; - } - int __status; - char* __locale_all = nullptr; -}; -#endif - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___LOCALE_LOCALE_BASE_API_LOCALE_GUARD_H diff --git a/system/lib/libcxx/include/__locale_dir/locale_base_api/musl.h b/system/lib/libcxx/include/__locale_dir/locale_base_api/musl.h index bf7b849d58634..1653214cdba1e 100644 --- a/system/lib/libcxx/include/__locale_dir/locale_base_api/musl.h +++ b/system/lib/libcxx/include/__locale_dir/locale_base_api/musl.h @@ -14,8 +14,8 @@ // in Musl. //===----------------------------------------------------------------------===// -#ifndef _LIBCPP___LOCALE_LOCALE_BASE_API_MUSL_H -#define _LIBCPP___LOCALE_LOCALE_BASE_API_MUSL_H +#ifndef _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_MUSL_H +#define _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_MUSL_H #include #include @@ -28,4 +28,4 @@ inline _LIBCPP_HIDE_FROM_ABI unsigned long long strtoull_l(const char* __nptr, c return ::strtoull(__nptr, __endptr, __base); } -#endif // _LIBCPP___LOCALE_LOCALE_BASE_API_MUSL_H +#endif // _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_MUSL_H diff --git a/system/lib/libcxx/include/__locale_dir/locale_base_api/openbsd.h b/system/lib/libcxx/include/__locale_dir/locale_base_api/openbsd.h index 0c05d6a0f7887..d4fb224e0c80a 100644 --- a/system/lib/libcxx/include/__locale_dir/locale_base_api/openbsd.h +++ b/system/lib/libcxx/include/__locale_dir/locale_base_api/openbsd.h @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#ifndef _LIBCPP___LOCALE_LOCALE_BASE_API_OPENBSD_H -#define _LIBCPP___LOCALE_LOCALE_BASE_API_OPENBSD_H +#ifndef _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_OPENBSD_H +#define _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_OPENBSD_H #include <__support/xlocale/__strtonum_fallback.h> #include @@ -16,4 +16,4 @@ #include #include -#endif // _LIBCPP___LOCALE_LOCALE_BASE_API_OPENBSD_H +#endif // _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_OPENBSD_H diff --git a/system/lib/libcxx/include/__locale_dir/locale_base_api/win32.h b/system/lib/libcxx/include/__locale_dir/locale_base_api/win32.h deleted file mode 100644 index f66baffb69204..0000000000000 --- a/system/lib/libcxx/include/__locale_dir/locale_base_api/win32.h +++ /dev/null @@ -1,235 +0,0 @@ -// -*- C++ -*- -//===-----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___LOCALE_LOCALE_BASE_API_WIN32_H -#define _LIBCPP___LOCALE_LOCALE_BASE_API_WIN32_H - -#include <__config> -#include -#include // _locale_t -#include -#include - -#define _X_ALL LC_ALL -#define _X_COLLATE LC_COLLATE -#define _X_CTYPE LC_CTYPE -#define _X_MONETARY LC_MONETARY -#define _X_NUMERIC LC_NUMERIC -#define _X_TIME LC_TIME -#define _X_MAX LC_MAX -#define _X_MESSAGES 6 -#define _NCAT (_X_MESSAGES + 1) - -#define _CATMASK(n) ((1 << (n)) >> 1) -#define _M_COLLATE _CATMASK(_X_COLLATE) -#define _M_CTYPE _CATMASK(_X_CTYPE) -#define _M_MONETARY _CATMASK(_X_MONETARY) -#define _M_NUMERIC _CATMASK(_X_NUMERIC) -#define _M_TIME _CATMASK(_X_TIME) -#define _M_MESSAGES _CATMASK(_X_MESSAGES) -#define _M_ALL (_CATMASK(_NCAT) - 1) - -#define LC_COLLATE_MASK _M_COLLATE -#define LC_CTYPE_MASK _M_CTYPE -#define LC_MONETARY_MASK _M_MONETARY -#define LC_NUMERIC_MASK _M_NUMERIC -#define LC_TIME_MASK _M_TIME -#define LC_MESSAGES_MASK _M_MESSAGES -#define LC_ALL_MASK \ - (LC_COLLATE_MASK | LC_CTYPE_MASK | LC_MESSAGES_MASK | LC_MONETARY_MASK | LC_NUMERIC_MASK | LC_TIME_MASK) - -class __lconv_storage { -public: - __lconv_storage(const lconv* __lc_input) { - __lc_ = *__lc_input; - - __decimal_point_ = __lc_input->decimal_point; - __thousands_sep_ = __lc_input->thousands_sep; - __grouping_ = __lc_input->grouping; - __int_curr_symbol_ = __lc_input->int_curr_symbol; - __currency_symbol_ = __lc_input->currency_symbol; - __mon_decimal_point_ = __lc_input->mon_decimal_point; - __mon_thousands_sep_ = __lc_input->mon_thousands_sep; - __mon_grouping_ = __lc_input->mon_grouping; - __positive_sign_ = __lc_input->positive_sign; - __negative_sign_ = __lc_input->negative_sign; - - __lc_.decimal_point = const_cast(__decimal_point_.c_str()); - __lc_.thousands_sep = const_cast(__thousands_sep_.c_str()); - __lc_.grouping = const_cast(__grouping_.c_str()); - __lc_.int_curr_symbol = const_cast(__int_curr_symbol_.c_str()); - __lc_.currency_symbol = const_cast(__currency_symbol_.c_str()); - __lc_.mon_decimal_point = const_cast(__mon_decimal_point_.c_str()); - __lc_.mon_thousands_sep = const_cast(__mon_thousands_sep_.c_str()); - __lc_.mon_grouping = const_cast(__mon_grouping_.c_str()); - __lc_.positive_sign = const_cast(__positive_sign_.c_str()); - __lc_.negative_sign = const_cast(__negative_sign_.c_str()); - } - - lconv* __get() { return &__lc_; } - -private: - lconv __lc_; - std::string __decimal_point_; - std::string __thousands_sep_; - std::string __grouping_; - std::string __int_curr_symbol_; - std::string __currency_symbol_; - std::string __mon_decimal_point_; - std::string __mon_thousands_sep_; - std::string __mon_grouping_; - std::string __positive_sign_; - std::string __negative_sign_; -}; - -class locale_t { -public: - locale_t() : __locale_(nullptr), __locale_str_(nullptr), __lc_(nullptr) {} - locale_t(std::nullptr_t) : __locale_(nullptr), __locale_str_(nullptr), __lc_(nullptr) {} - locale_t(_locale_t __xlocale, const char* __xlocale_str) - : __locale_(__xlocale), __locale_str_(__xlocale_str), __lc_(nullptr) {} - locale_t(const locale_t& __l) : __locale_(__l.__locale_), __locale_str_(__l.__locale_str_), __lc_(nullptr) {} - - ~locale_t() { delete __lc_; } - - locale_t& operator=(const locale_t& __l) { - __locale_ = __l.__locale_; - __locale_str_ = __l.__locale_str_; - // __lc_ not copied - return *this; - } - - friend bool operator==(const locale_t& __left, const locale_t& __right) { - return __left.__locale_ == __right.__locale_; - } - - friend bool operator==(const locale_t& __left, int __right) { return __left.__locale_ == nullptr && __right == 0; } - - friend bool operator==(const locale_t& __left, long long __right) { - return __left.__locale_ == nullptr && __right == 0; - } - - friend bool operator==(const locale_t& __left, std::nullptr_t) { return __left.__locale_ == nullptr; } - - friend bool operator==(int __left, const locale_t& __right) { return __left == 0 && nullptr == __right.__locale_; } - - friend bool operator==(std::nullptr_t, const locale_t& __right) { return nullptr == __right.__locale_; } - - friend bool operator!=(const locale_t& __left, const locale_t& __right) { return !(__left == __right); } - - friend bool operator!=(const locale_t& __left, int __right) { return !(__left == __right); } - - friend bool operator!=(const locale_t& __left, long long __right) { return !(__left == __right); } - - friend bool operator!=(const locale_t& __left, std::nullptr_t __right) { return !(__left == __right); } - - friend bool operator!=(int __left, const locale_t& __right) { return !(__left == __right); } - - friend bool operator!=(std::nullptr_t __left, const locale_t& __right) { return !(__left == __right); } - - operator bool() const { return __locale_ != nullptr; } - - const char* __get_locale() const { return __locale_str_; } - - operator _locale_t() const { return __locale_; } - - lconv* __store_lconv(const lconv* __input_lc) { - delete __lc_; - __lc_ = new __lconv_storage(__input_lc); - return __lc_->__get(); - } - -private: - _locale_t __locale_; - const char* __locale_str_; - __lconv_storage* __lc_ = nullptr; -}; - -// Locale management functions -#define freelocale _free_locale -// FIXME: base currently unused. Needs manual work to construct the new locale -locale_t newlocale(int __mask, const char* __locale, locale_t __base); -// uselocale can't be implemented on Windows because Windows allows partial modification -// of thread-local locale and so _get_current_locale() returns a copy while uselocale does -// not create any copies. -// We can still implement raii even without uselocale though. - -lconv* localeconv_l(locale_t& __loc); -size_t mbrlen_l(const char* __restrict __s, size_t __n, mbstate_t* __restrict __ps, locale_t __loc); -size_t mbsrtowcs_l( - wchar_t* __restrict __dst, const char** __restrict __src, size_t __len, mbstate_t* __restrict __ps, locale_t __loc); -size_t wcrtomb_l(char* __restrict __s, wchar_t __wc, mbstate_t* __restrict __ps, locale_t __loc); -size_t mbrtowc_l( - wchar_t* __restrict __pwc, const char* __restrict __s, size_t __n, mbstate_t* __restrict __ps, locale_t __loc); -size_t mbsnrtowcs_l(wchar_t* __restrict __dst, - const char** __restrict __src, - size_t __nms, - size_t __len, - mbstate_t* __restrict __ps, - locale_t __loc); -size_t wcsnrtombs_l(char* __restrict __dst, - const wchar_t** __restrict __src, - size_t __nwc, - size_t __len, - mbstate_t* __restrict __ps, - locale_t __loc); -wint_t btowc_l(int __c, locale_t __loc); -int wctob_l(wint_t __c, locale_t __loc); - -decltype(MB_CUR_MAX) MB_CUR_MAX_L(locale_t __l); - -// the *_l functions are prefixed on Windows, only available for msvcr80+, VS2005+ -#define mbtowc_l _mbtowc_l -#define strtoll_l _strtoi64_l -#define strtoull_l _strtoui64_l -#define strtod_l _strtod_l -#if defined(_LIBCPP_MSVCRT) -# define strtof_l _strtof_l -# define strtold_l _strtold_l -#else -_LIBCPP_EXPORTED_FROM_ABI float strtof_l(const char*, char**, locale_t); -_LIBCPP_EXPORTED_FROM_ABI long double strtold_l(const char*, char**, locale_t); -#endif -inline _LIBCPP_HIDE_FROM_ABI int islower_l(int __c, _locale_t __loc) { return _islower_l((int)__c, __loc); } - -inline _LIBCPP_HIDE_FROM_ABI int isupper_l(int __c, _locale_t __loc) { return _isupper_l((int)__c, __loc); } - -#define isdigit_l _isdigit_l -#define isxdigit_l _isxdigit_l -#define strcoll_l _strcoll_l -#define strxfrm_l _strxfrm_l -#define wcscoll_l _wcscoll_l -#define wcsxfrm_l _wcsxfrm_l -#define toupper_l _toupper_l -#define tolower_l _tolower_l -#define iswspace_l _iswspace_l -#define iswprint_l _iswprint_l -#define iswcntrl_l _iswcntrl_l -#define iswupper_l _iswupper_l -#define iswlower_l _iswlower_l -#define iswalpha_l _iswalpha_l -#define iswdigit_l _iswdigit_l -#define iswpunct_l _iswpunct_l -#define iswxdigit_l _iswxdigit_l -#define towupper_l _towupper_l -#define towlower_l _towlower_l -#if defined(__MINGW32__) && __MSVCRT_VERSION__ < 0x0800 -_LIBCPP_EXPORTED_FROM_ABI size_t strftime_l(char* ret, size_t n, const char* format, const struct tm* tm, locale_t loc); -#else -# define strftime_l _strftime_l -#endif -#define sscanf_l(__s, __l, __f, ...) _sscanf_l(__s, __f, __l, __VA_ARGS__) -_LIBCPP_EXPORTED_FROM_ABI int snprintf_l(char* __ret, size_t __n, locale_t __loc, const char* __format, ...); -_LIBCPP_EXPORTED_FROM_ABI int asprintf_l(char** __ret, locale_t __loc, const char* __format, ...); -_LIBCPP_EXPORTED_FROM_ABI int vasprintf_l(char** __ret, locale_t __loc, const char* __format, va_list __ap); - -// not-so-pressing FIXME: use locale to determine blank characters -inline int iswblank_l(wint_t __c, locale_t /*loc*/) { return (__c == L' ' || __c == L'\t'); } - -#endif // _LIBCPP___LOCALE_LOCALE_BASE_API_WIN32_H diff --git a/system/lib/libcxx/include/__locale_dir/pad_and_output.h b/system/lib/libcxx/include/__locale_dir/pad_and_output.h new file mode 100644 index 0000000000000..a1cb37d0786da --- /dev/null +++ b/system/lib/libcxx/include/__locale_dir/pad_and_output.h @@ -0,0 +1,88 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___LOCALE_DIR_PAD_AND_OUTPUT_H +#define _LIBCPP___LOCALE_DIR_PAD_AND_OUTPUT_H + +#include <__config> + +#if _LIBCPP_HAS_LOCALIZATION + +# include + +# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +# endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template +_LIBCPP_HIDE_FROM_ABI _OutputIterator __pad_and_output( + _OutputIterator __s, const _CharT* __ob, const _CharT* __op, const _CharT* __oe, ios_base& __iob, _CharT __fl) { + streamsize __sz = __oe - __ob; + streamsize __ns = __iob.width(); + if (__ns > __sz) + __ns -= __sz; + else + __ns = 0; + for (; __ob < __op; ++__ob, ++__s) + *__s = *__ob; + for (; __ns; --__ns, ++__s) + *__s = __fl; + for (; __ob < __oe; ++__ob, ++__s) + *__s = *__ob; + __iob.width(0); + return __s; +} + +template +_LIBCPP_HIDE_FROM_ABI ostreambuf_iterator<_CharT, _Traits> __pad_and_output( + ostreambuf_iterator<_CharT, _Traits> __s, + const _CharT* __ob, + const _CharT* __op, + const _CharT* __oe, + ios_base& __iob, + _CharT __fl) { + if (__s.__sbuf_ == nullptr) + return __s; + streamsize __sz = __oe - __ob; + streamsize __ns = __iob.width(); + if (__ns > __sz) + __ns -= __sz; + else + __ns = 0; + streamsize __np = __op - __ob; + if (__np > 0) { + if (__s.__sbuf_->sputn(__ob, __np) != __np) { + __s.__sbuf_ = nullptr; + return __s; + } + } + if (__ns > 0) { + basic_string<_CharT, _Traits> __sp(__ns, __fl); + if (__s.__sbuf_->sputn(__sp.data(), __ns) != __ns) { + __s.__sbuf_ = nullptr; + return __s; + } + } + __np = __oe - __op; + if (__np > 0) { + if (__s.__sbuf_->sputn(__op, __np) != __np) { + __s.__sbuf_ = nullptr; + return __s; + } + } + __iob.width(0); + return __s; +} + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_HAS_LOCALIZATION + +#endif // _LIBCPP___LOCALE_DIR_PAD_AND_OUTPUT_H diff --git a/system/lib/libcxx/include/locale.h b/system/lib/libcxx/include/__locale_dir/support/apple.h similarity index 56% rename from system/lib/libcxx/include/locale.h rename to system/lib/libcxx/include/__locale_dir/support/apple.h index 425bf47d437ac..62eb79c30d435 100644 --- a/system/lib/libcxx/include/locale.h +++ b/system/lib/libcxx/include/__locale_dir/support/apple.h @@ -1,5 +1,4 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// +//===-----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -7,31 +6,8 @@ // //===----------------------------------------------------------------------===// -#ifndef _LIBCPP_LOCALE_H -#define _LIBCPP_LOCALE_H - -/* - locale.h synopsis - -Macros: - - LC_ALL - LC_COLLATE - LC_CTYPE - LC_MONETARY - LC_NUMERIC - LC_TIME - -Types: - - lconv - -Functions: - - setlocale - localeconv - -*/ +#ifndef _LIBCPP___LOCALE_DIR_SUPPORT_APPLE_H +#define _LIBCPP___LOCALE_DIR_SUPPORT_APPLE_H #include <__config> @@ -39,8 +15,6 @@ # pragma GCC system_header #endif -#if __has_include_next() -# include_next -#endif +#include <__locale_dir/support/bsd_like.h> -#endif // _LIBCPP_LOCALE_H +#endif // _LIBCPP___LOCALE_DIR_SUPPORT_APPLE_H diff --git a/system/lib/libcxx/include/__locale_dir/support/bsd_like.h b/system/lib/libcxx/include/__locale_dir/support/bsd_like.h new file mode 100644 index 0000000000000..405f1589c8c94 --- /dev/null +++ b/system/lib/libcxx/include/__locale_dir/support/bsd_like.h @@ -0,0 +1,234 @@ +//===-----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___LOCALE_DIR_SUPPORT_BSD_LIKE_H +#define _LIBCPP___LOCALE_DIR_SUPPORT_BSD_LIKE_H + +#include <__config> +#include <__cstddef/size_t.h> +#include <__std_mbstate_t.h> +#include <__utility/forward.h> +#include // std::lconv +#include +#include +#include +#include +#include +#if _LIBCPP_HAS_WIDE_CHARACTERS +# include +# include +#endif + +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD +namespace __locale { + +// +// Locale management +// +#define _LIBCPP_COLLATE_MASK LC_COLLATE_MASK +#define _LIBCPP_CTYPE_MASK LC_CTYPE_MASK +#define _LIBCPP_MONETARY_MASK LC_MONETARY_MASK +#define _LIBCPP_NUMERIC_MASK LC_NUMERIC_MASK +#define _LIBCPP_TIME_MASK LC_TIME_MASK +#define _LIBCPP_MESSAGES_MASK LC_MESSAGES_MASK +#define _LIBCPP_ALL_MASK LC_ALL_MASK +#define _LIBCPP_LC_ALL LC_ALL + +using __locale_t = ::locale_t; +#if defined(_LIBCPP_BUILDING_LIBRARY) +using __lconv_t = std::lconv; + +inline _LIBCPP_HIDE_FROM_ABI __locale_t __newlocale(int __category_mask, const char* __locale, __locale_t __base) { + return ::newlocale(__category_mask, __locale, __base); +} + +inline _LIBCPP_HIDE_FROM_ABI void __freelocale(__locale_t __loc) { ::freelocale(__loc); } + +inline _LIBCPP_HIDE_FROM_ABI char* __setlocale(int __category, char const* __locale) { + return ::setlocale(__category, __locale); +} + +inline _LIBCPP_HIDE_FROM_ABI __lconv_t* __localeconv(__locale_t& __loc) { return ::localeconv_l(__loc); } +#endif // _LIBCPP_BUILDING_LIBRARY + +// +// Strtonum functions +// +inline _LIBCPP_HIDE_FROM_ABI float __strtof(const char* __nptr, char** __endptr, __locale_t __loc) { + return ::strtof_l(__nptr, __endptr, __loc); +} + +inline _LIBCPP_HIDE_FROM_ABI double __strtod(const char* __nptr, char** __endptr, __locale_t __loc) { + return ::strtod_l(__nptr, __endptr, __loc); +} + +inline _LIBCPP_HIDE_FROM_ABI long double __strtold(const char* __nptr, char** __endptr, __locale_t __loc) { + return ::strtold_l(__nptr, __endptr, __loc); +} + +inline _LIBCPP_HIDE_FROM_ABI long long __strtoll(const char* __nptr, char** __endptr, int __base, __locale_t __loc) { + return ::strtoll_l(__nptr, __endptr, __base, __loc); +} + +inline _LIBCPP_HIDE_FROM_ABI unsigned long long +__strtoull(const char* __nptr, char** __endptr, int __base, __locale_t __loc) { + return ::strtoull_l(__nptr, __endptr, __base, __loc); +} + +// +// Character manipulation functions +// +#if defined(_LIBCPP_BUILDING_LIBRARY) +inline _LIBCPP_HIDE_FROM_ABI int __islower(int __c, __locale_t __loc) { return ::islower_l(__c, __loc); } + +inline _LIBCPP_HIDE_FROM_ABI int __isupper(int __c, __locale_t __loc) { return ::isupper_l(__c, __loc); } +#endif + +inline _LIBCPP_HIDE_FROM_ABI int __isdigit(int __c, __locale_t __loc) { return ::isdigit_l(__c, __loc); } + +inline _LIBCPP_HIDE_FROM_ABI int __isxdigit(int __c, __locale_t __loc) { return ::isxdigit_l(__c, __loc); } + +#if defined(_LIBCPP_BUILDING_LIBRARY) +inline _LIBCPP_HIDE_FROM_ABI int __toupper(int __c, __locale_t __loc) { return ::toupper_l(__c, __loc); } + +inline _LIBCPP_HIDE_FROM_ABI int __tolower(int __c, __locale_t __loc) { return ::tolower_l(__c, __loc); } + +inline _LIBCPP_HIDE_FROM_ABI int __strcoll(const char* __s1, const char* __s2, __locale_t __loc) { + return ::strcoll_l(__s1, __s2, __loc); +} + +inline _LIBCPP_HIDE_FROM_ABI size_t __strxfrm(char* __dest, const char* __src, size_t __n, __locale_t __loc) { + return ::strxfrm_l(__dest, __src, __n, __loc); +} + +# if _LIBCPP_HAS_WIDE_CHARACTERS +inline _LIBCPP_HIDE_FROM_ABI int __iswctype(wint_t __c, wctype_t __type, __locale_t __loc) { + return ::iswctype_l(__c, __type, __loc); +} + +inline _LIBCPP_HIDE_FROM_ABI int __iswspace(wint_t __c, __locale_t __loc) { return ::iswspace_l(__c, __loc); } + +inline _LIBCPP_HIDE_FROM_ABI int __iswprint(wint_t __c, __locale_t __loc) { return ::iswprint_l(__c, __loc); } + +inline _LIBCPP_HIDE_FROM_ABI int __iswcntrl(wint_t __c, __locale_t __loc) { return ::iswcntrl_l(__c, __loc); } + +inline _LIBCPP_HIDE_FROM_ABI int __iswupper(wint_t __c, __locale_t __loc) { return ::iswupper_l(__c, __loc); } + +inline _LIBCPP_HIDE_FROM_ABI int __iswlower(wint_t __c, __locale_t __loc) { return ::iswlower_l(__c, __loc); } + +inline _LIBCPP_HIDE_FROM_ABI int __iswalpha(wint_t __c, __locale_t __loc) { return ::iswalpha_l(__c, __loc); } + +inline _LIBCPP_HIDE_FROM_ABI int __iswblank(wint_t __c, __locale_t __loc) { return ::iswblank_l(__c, __loc); } + +inline _LIBCPP_HIDE_FROM_ABI int __iswdigit(wint_t __c, __locale_t __loc) { return ::iswdigit_l(__c, __loc); } + +inline _LIBCPP_HIDE_FROM_ABI int __iswpunct(wint_t __c, __locale_t __loc) { return ::iswpunct_l(__c, __loc); } + +inline _LIBCPP_HIDE_FROM_ABI int __iswxdigit(wint_t __c, __locale_t __loc) { return ::iswxdigit_l(__c, __loc); } + +inline _LIBCPP_HIDE_FROM_ABI wint_t __towupper(wint_t __c, __locale_t __loc) { return ::towupper_l(__c, __loc); } + +inline _LIBCPP_HIDE_FROM_ABI wint_t __towlower(wint_t __c, __locale_t __loc) { return ::towlower_l(__c, __loc); } + +inline _LIBCPP_HIDE_FROM_ABI int __wcscoll(const wchar_t* __ws1, const wchar_t* __ws2, __locale_t __loc) { + return ::wcscoll_l(__ws1, __ws2, __loc); +} + +inline _LIBCPP_HIDE_FROM_ABI size_t __wcsxfrm(wchar_t* __dest, const wchar_t* __src, size_t __n, __locale_t __loc) { + return ::wcsxfrm_l(__dest, __src, __n, __loc); +} +# endif // _LIBCPP_HAS_WIDE_CHARACTERS + +inline _LIBCPP_HIDE_FROM_ABI size_t +__strftime(char* __s, size_t __max, const char* __format, const struct tm* __tm, __locale_t __loc) { + return ::strftime_l(__s, __max, __format, __tm, __loc); +} + +// +// Other functions +// +inline _LIBCPP_HIDE_FROM_ABI decltype(MB_CUR_MAX) __mb_len_max(__locale_t __loc) { return MB_CUR_MAX_L(__loc); } + +# if _LIBCPP_HAS_WIDE_CHARACTERS +inline _LIBCPP_HIDE_FROM_ABI wint_t __btowc(int __c, __locale_t __loc) { return ::btowc_l(__c, __loc); } + +inline _LIBCPP_HIDE_FROM_ABI int __wctob(wint_t __c, __locale_t __loc) { return ::wctob_l(__c, __loc); } + +inline _LIBCPP_HIDE_FROM_ABI size_t +__wcsnrtombs(char* __dest, const wchar_t** __src, size_t __nwc, size_t __len, mbstate_t* __ps, __locale_t __loc) { + return ::wcsnrtombs_l(__dest, __src, __nwc, __len, __ps, __loc); // wcsnrtombs is a POSIX extension +} + +inline _LIBCPP_HIDE_FROM_ABI size_t __wcrtomb(char* __s, wchar_t __wc, mbstate_t* __ps, __locale_t __loc) { + return ::wcrtomb_l(__s, __wc, __ps, __loc); +} + +inline _LIBCPP_HIDE_FROM_ABI size_t +__mbsnrtowcs(wchar_t* __dest, const char** __src, size_t __nms, size_t __len, mbstate_t* __ps, __locale_t __loc) { + return ::mbsnrtowcs_l(__dest, __src, __nms, __len, __ps, __loc); // mbsnrtowcs is a POSIX extension +} + +inline _LIBCPP_HIDE_FROM_ABI size_t +__mbrtowc(wchar_t* __pwc, const char* __s, size_t __n, mbstate_t* __ps, __locale_t __loc) { + return ::mbrtowc_l(__pwc, __s, __n, __ps, __loc); +} + +inline _LIBCPP_HIDE_FROM_ABI int __mbtowc(wchar_t* __pwc, const char* __pmb, size_t __max, __locale_t __loc) { + return ::mbtowc_l(__pwc, __pmb, __max, __loc); +} + +inline _LIBCPP_HIDE_FROM_ABI size_t __mbrlen(const char* __s, size_t __n, mbstate_t* __ps, __locale_t __loc) { + return ::mbrlen_l(__s, __n, __ps, __loc); +} + +inline _LIBCPP_HIDE_FROM_ABI size_t +__mbsrtowcs(wchar_t* __dest, const char** __src, size_t __len, mbstate_t* __ps, __locale_t __loc) { + return ::mbsrtowcs_l(__dest, __src, __len, __ps, __loc); +} +# endif // _LIBCPP_HAS_WIDE_CHARACTERS +#endif // _LIBCPP_BUILDING_LIBRARY + +_LIBCPP_DIAGNOSTIC_PUSH +_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wgcc-compat") +_LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wformat-nonliteral") // GCC doesn't support [[gnu::format]] on variadic templates +#ifdef _LIBCPP_COMPILER_CLANG_BASED +# define _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(...) _LIBCPP_ATTRIBUTE_FORMAT(__VA_ARGS__) +#else +# define _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(...) /* nothing */ +#endif + +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__printf__, 4, 5) int __snprintf( + char* __s, size_t __n, __locale_t __loc, const char* __format, _Args&&... __args) { + return ::snprintf_l(__s, __n, __loc, __format, std::forward<_Args>(__args)...); +} + +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__printf__, 3, 4) int __asprintf( + char** __s, __locale_t __loc, const char* __format, _Args&&... __args) { + return ::asprintf_l(__s, __loc, __format, std::forward<_Args>(__args)...); // non-standard +} + +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__scanf__, 3, 4) int __sscanf( + const char* __s, __locale_t __loc, const char* __format, _Args&&... __args) { + return ::sscanf_l(__s, __loc, __format, std::forward<_Args>(__args)...); +} +_LIBCPP_DIAGNOSTIC_POP +#undef _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT + +} // namespace __locale +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___LOCALE_DIR_SUPPORT_BSD_LIKE_H diff --git a/system/lib/libcxx/include/__locale_dir/locale_base_api/fuchsia.h b/system/lib/libcxx/include/__locale_dir/support/freebsd.h similarity index 54% rename from system/lib/libcxx/include/__locale_dir/locale_base_api/fuchsia.h rename to system/lib/libcxx/include/__locale_dir/support/freebsd.h index 4c3440f981c6d..5c6e21e387271 100644 --- a/system/lib/libcxx/include/__locale_dir/locale_base_api/fuchsia.h +++ b/system/lib/libcxx/include/__locale_dir/support/freebsd.h @@ -1,4 +1,3 @@ -// -*- C++ -*- //===-----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. @@ -7,12 +6,15 @@ // //===----------------------------------------------------------------------===// -#ifndef _LIBCPP___LOCALE_LOCALE_BASE_API_FUCHSIA_H -#define _LIBCPP___LOCALE_LOCALE_BASE_API_FUCHSIA_H +#ifndef _LIBCPP___LOCALE_DIR_SUPPORT_FREEBSD_H +#define _LIBCPP___LOCALE_DIR_SUPPORT_FREEBSD_H -#include <__support/xlocale/__posix_l_fallback.h> -#include <__support/xlocale/__strtonum_fallback.h> -#include -#include +#include <__config> -#endif // _LIBCPP___LOCALE_LOCALE_BASE_API_FUCHSIA_H +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#include <__locale_dir/support/bsd_like.h> + +#endif // _LIBCPP___LOCALE_DIR_SUPPORT_FREEBSD_H diff --git a/system/lib/libcxx/include/__locale_dir/support/fuchsia.h b/system/lib/libcxx/include/__locale_dir/support/fuchsia.h new file mode 100644 index 0000000000000..fb9de74ab7c7b --- /dev/null +++ b/system/lib/libcxx/include/__locale_dir/support/fuchsia.h @@ -0,0 +1,160 @@ +//===-----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___LOCALE_DIR_SUPPORT_FUCHSIA_H +#define _LIBCPP___LOCALE_DIR_SUPPORT_FUCHSIA_H + +#include <__config> +#include <__utility/forward.h> +#include // uselocale & friends +#include +#include +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD +namespace __locale { + +struct __locale_guard { + _LIBCPP_HIDE_FROM_ABI __locale_guard(locale_t& __loc) : __old_loc_(::uselocale(__loc)) {} + + _LIBCPP_HIDE_FROM_ABI ~__locale_guard() { + if (__old_loc_) + ::uselocale(__old_loc_); + } + + locale_t __old_loc_; + + __locale_guard(__locale_guard const&) = delete; + __locale_guard& operator=(__locale_guard const&) = delete; +}; + +// +// Locale management +// +#define _LIBCPP_COLLATE_MASK LC_COLLATE_MASK +#define _LIBCPP_CTYPE_MASK LC_CTYPE_MASK +#define _LIBCPP_MONETARY_MASK LC_MONETARY_MASK +#define _LIBCPP_NUMERIC_MASK LC_NUMERIC_MASK +#define _LIBCPP_TIME_MASK LC_TIME_MASK +#define _LIBCPP_MESSAGES_MASK LC_MESSAGES_MASK +#define _LIBCPP_ALL_MASK LC_ALL_MASK +#define _LIBCPP_LC_ALL LC_ALL + +using __locale_t = locale_t; + +#if defined(_LIBCPP_BUILDING_LIBRARY) +using __lconv_t = std::lconv; + +inline _LIBCPP_HIDE_FROM_ABI __locale_t __newlocale(int __category_mask, const char* __name, __locale_t __loc) { + return ::newlocale(__category_mask, __name, __loc); +} + +inline _LIBCPP_HIDE_FROM_ABI void __freelocale(__locale_t __loc) { ::freelocale(__loc); } + +inline _LIBCPP_HIDE_FROM_ABI char* __setlocale(int __category, char const* __locale) { + return ::setlocale(__category, __locale); +} + +inline _LIBCPP_HIDE_FROM_ABI __lconv_t* __localeconv(__locale_t& __loc) { + __locale_guard __current(__loc); + return std::localeconv(); +} + +// +// Other functions +// +inline _LIBCPP_HIDE_FROM_ABI decltype(MB_CUR_MAX) __mb_len_max(__locale_t __loc) { + __locale_guard __current(__loc); + return MB_CUR_MAX; +} +# if _LIBCPP_HAS_WIDE_CHARACTERS +inline _LIBCPP_HIDE_FROM_ABI wint_t __btowc(int __ch, __locale_t __loc) { + __locale_guard __current(__loc); + return std::btowc(__ch); +} +inline _LIBCPP_HIDE_FROM_ABI int __wctob(wint_t __ch, __locale_t __loc) { + __locale_guard __current(__loc); + return std::wctob(__ch); +} +inline _LIBCPP_HIDE_FROM_ABI size_t +__wcsnrtombs(char* __dest, const wchar_t** __src, size_t __nwc, size_t __len, mbstate_t* __ps, __locale_t __loc) { + __locale_guard __current(__loc); + return ::wcsnrtombs(__dest, __src, __nwc, __len, __ps); // non-standard +} +inline _LIBCPP_HIDE_FROM_ABI size_t __wcrtomb(char* __s, wchar_t __ch, mbstate_t* __ps, __locale_t __loc) { + __locale_guard __current(__loc); + return std::wcrtomb(__s, __ch, __ps); +} +inline _LIBCPP_HIDE_FROM_ABI size_t +__mbsnrtowcs(wchar_t* __dest, const char** __src, size_t __nms, size_t __len, mbstate_t* __ps, __locale_t __loc) { + __locale_guard __current(__loc); + return ::mbsnrtowcs(__dest, __src, __nms, __len, __ps); // non-standard +} +inline _LIBCPP_HIDE_FROM_ABI size_t +__mbrtowc(wchar_t* __pwc, const char* __s, size_t __n, mbstate_t* __ps, __locale_t __loc) { + __locale_guard __current(__loc); + return std::mbrtowc(__pwc, __s, __n, __ps); +} +inline _LIBCPP_HIDE_FROM_ABI int __mbtowc(wchar_t* __pwc, const char* __pmb, size_t __max, __locale_t __loc) { + __locale_guard __current(__loc); + return std::mbtowc(__pwc, __pmb, __max); +} +inline _LIBCPP_HIDE_FROM_ABI size_t __mbrlen(const char* __s, size_t __n, mbstate_t* __ps, __locale_t __loc) { + __locale_guard __current(__loc); + return std::mbrlen(__s, __n, __ps); +} +inline _LIBCPP_HIDE_FROM_ABI size_t +__mbsrtowcs(wchar_t* __dest, const char** __src, size_t __len, mbstate_t* __ps, __locale_t __loc) { + __locale_guard __current(__loc); + return ::mbsrtowcs(__dest, __src, __len, __ps); +} +# endif // _LIBCPP_HAS_WIDE_CHARACTERS +#endif // _LIBCPP_BUILDING_LIBRARY + +_LIBCPP_DIAGNOSTIC_PUSH +_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wgcc-compat") +_LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wformat-nonliteral") // GCC doesn't support [[gnu::format]] on variadic templates +#ifdef _LIBCPP_COMPILER_CLANG_BASED +# define _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(...) _LIBCPP_ATTRIBUTE_FORMAT(__VA_ARGS__) +#else +# define _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(...) /* nothing */ +#endif + +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__printf__, 4, 5) int __snprintf( + char* __s, size_t __n, __locale_t __loc, const char* __format, _Args&&... __args) { + __locale_guard __current(__loc); + return std::snprintf(__s, __n, __format, std::forward<_Args>(__args)...); +} +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__printf__, 3, 4) int __asprintf( + char** __s, __locale_t __loc, const char* __format, _Args&&... __args) { + __locale_guard __current(__loc); + return ::asprintf(__s, __format, std::forward<_Args>(__args)...); // non-standard +} +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__scanf__, 3, 4) int __sscanf( + const char* __s, __locale_t __loc, const char* __format, _Args&&... __args) { + __locale_guard __current(__loc); + return std::sscanf(__s, __format, std::forward<_Args>(__args)...); +} + +_LIBCPP_DIAGNOSTIC_POP +#undef _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT + +} // namespace __locale +_LIBCPP_END_NAMESPACE_STD + +#include <__locale_dir/support/no_locale/characters.h> +#include <__locale_dir/support/no_locale/strtonum.h> + +#endif // _LIBCPP___LOCALE_DIR_SUPPORT_FUCHSIA_H diff --git a/system/lib/libcxx/include/__locale_dir/support/no_locale/characters.h b/system/lib/libcxx/include/__locale_dir/support/no_locale/characters.h new file mode 100644 index 0000000000000..4fb48ed9ceac1 --- /dev/null +++ b/system/lib/libcxx/include/__locale_dir/support/no_locale/characters.h @@ -0,0 +1,102 @@ +//===-----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___LOCALE_DIR_SUPPORT_NO_LOCALE_CHARACTERS_H +#define _LIBCPP___LOCALE_DIR_SUPPORT_NO_LOCALE_CHARACTERS_H + +#include <__config> +#include <__cstddef/size_t.h> +#include +#include +#include +#include +#if _LIBCPP_HAS_WIDE_CHARACTERS +# include +#endif + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD +namespace __locale { + +// +// Character manipulation functions +// +#if defined(_LIBCPP_BUILDING_LIBRARY) +inline _LIBCPP_HIDE_FROM_ABI int __islower(int __c, __locale_t) { return std::islower(__c); } + +inline _LIBCPP_HIDE_FROM_ABI int __isupper(int __c, __locale_t) { return std::isupper(__c); } +#endif + +inline _LIBCPP_HIDE_FROM_ABI int __isdigit(int __c, __locale_t) { return std::isdigit(__c); } + +inline _LIBCPP_HIDE_FROM_ABI int __isxdigit(int __c, __locale_t) { return std::isxdigit(__c); } + +#if defined(_LIBCPP_BUILDING_LIBRARY) +inline _LIBCPP_HIDE_FROM_ABI int __toupper(int __c, __locale_t) { return std::toupper(__c); } + +inline _LIBCPP_HIDE_FROM_ABI int __tolower(int __c, __locale_t) { return std::tolower(__c); } + +inline _LIBCPP_HIDE_FROM_ABI int __strcoll(const char* __s1, const char* __s2, __locale_t) { + return std::strcoll(__s1, __s2); +} + +inline _LIBCPP_HIDE_FROM_ABI size_t __strxfrm(char* __dest, const char* __src, size_t __n, __locale_t) { + return std::strxfrm(__dest, __src, __n); +} + +# if _LIBCPP_HAS_WIDE_CHARACTERS +inline _LIBCPP_HIDE_FROM_ABI int __iswctype(wint_t __c, wctype_t __type, __locale_t) { + return std::iswctype(__c, __type); +} + +inline _LIBCPP_HIDE_FROM_ABI int __iswspace(wint_t __c, __locale_t) { return std::iswspace(__c); } + +inline _LIBCPP_HIDE_FROM_ABI int __iswprint(wint_t __c, __locale_t) { return std::iswprint(__c); } + +inline _LIBCPP_HIDE_FROM_ABI int __iswcntrl(wint_t __c, __locale_t) { return std::iswcntrl(__c); } + +inline _LIBCPP_HIDE_FROM_ABI int __iswupper(wint_t __c, __locale_t) { return std::iswupper(__c); } + +inline _LIBCPP_HIDE_FROM_ABI int __iswlower(wint_t __c, __locale_t) { return std::iswlower(__c); } + +inline _LIBCPP_HIDE_FROM_ABI int __iswalpha(wint_t __c, __locale_t) { return std::iswalpha(__c); } + +inline _LIBCPP_HIDE_FROM_ABI int __iswblank(wint_t __c, __locale_t) { return std::iswblank(__c); } + +inline _LIBCPP_HIDE_FROM_ABI int __iswdigit(wint_t __c, __locale_t) { return std::iswdigit(__c); } + +inline _LIBCPP_HIDE_FROM_ABI int __iswpunct(wint_t __c, __locale_t) { return std::iswpunct(__c); } + +inline _LIBCPP_HIDE_FROM_ABI int __iswxdigit(wint_t __c, __locale_t) { return std::iswxdigit(__c); } + +inline _LIBCPP_HIDE_FROM_ABI wint_t __towupper(wint_t __c, __locale_t) { return std::towupper(__c); } + +inline _LIBCPP_HIDE_FROM_ABI wint_t __towlower(wint_t __c, __locale_t) { return std::towlower(__c); } + +inline _LIBCPP_HIDE_FROM_ABI int __wcscoll(const wchar_t* __ws1, const wchar_t* __ws2, __locale_t) { + return std::wcscoll(__ws1, __ws2); +} + +inline _LIBCPP_HIDE_FROM_ABI size_t __wcsxfrm(wchar_t* __dest, const wchar_t* __src, size_t __n, __locale_t) { + return std::wcsxfrm(__dest, __src, __n); +} +# endif // _LIBCPP_HAS_WIDE_CHARACTERS + +inline _LIBCPP_HIDE_FROM_ABI size_t +__strftime(char* __s, size_t __max, const char* __format, const struct tm* __tm, __locale_t) { + return std::strftime(__s, __max, __format, __tm); +} +#endif // _LIBCPP_BUILDING_LIBRARY + +} // namespace __locale +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___LOCALE_DIR_SUPPORT_NO_LOCALE_CHARACTERS_H diff --git a/system/lib/libcxx/include/__locale_dir/support/no_locale/strtonum.h b/system/lib/libcxx/include/__locale_dir/support/no_locale/strtonum.h new file mode 100644 index 0000000000000..0e7a32993e736 --- /dev/null +++ b/system/lib/libcxx/include/__locale_dir/support/no_locale/strtonum.h @@ -0,0 +1,49 @@ +//===-----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___LOCALE_DIR_SUPPORT_NO_LOCALE_STRTONUM_H +#define _LIBCPP___LOCALE_DIR_SUPPORT_NO_LOCALE_STRTONUM_H + +#include <__config> +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD +namespace __locale { + +// +// Strtonum functions +// +inline _LIBCPP_HIDE_FROM_ABI float __strtof(const char* __nptr, char** __endptr, __locale_t) { + return std::strtof(__nptr, __endptr); +} + +inline _LIBCPP_HIDE_FROM_ABI double __strtod(const char* __nptr, char** __endptr, __locale_t) { + return std::strtod(__nptr, __endptr); +} + +inline _LIBCPP_HIDE_FROM_ABI long double __strtold(const char* __nptr, char** __endptr, __locale_t) { + return std::strtold(__nptr, __endptr); +} + +inline _LIBCPP_HIDE_FROM_ABI long long __strtoll(const char* __nptr, char** __endptr, int __base, __locale_t) { + return std::strtoll(__nptr, __endptr, __base); +} + +inline _LIBCPP_HIDE_FROM_ABI unsigned long long +__strtoull(const char* __nptr, char** __endptr, int __base, __locale_t) { + return std::strtoull(__nptr, __endptr, __base); +} + +} // namespace __locale +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___LOCALE_DIR_SUPPORT_NO_LOCALE_STRTONUM_H diff --git a/system/lib/libcxx/include/__locale_dir/support/windows.h b/system/lib/libcxx/include/__locale_dir/support/windows.h new file mode 100644 index 0000000000000..56d34c6f0e6ca --- /dev/null +++ b/system/lib/libcxx/include/__locale_dir/support/windows.h @@ -0,0 +1,343 @@ +//===-----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___LOCALE_DIR_SUPPORT_WINDOWS_H +#define _LIBCPP___LOCALE_DIR_SUPPORT_WINDOWS_H + +#include <__config> +#include <__cstddef/nullptr_t.h> +#include <__utility/forward.h> +#include // std::lconv & friends +#include +#include // ::_isupper_l & friends +#include // ::_locale_t +#include // ::_sscanf_l +#include // ::_strtod_l & friends +#include // ::_strcoll_l +#include +#include // ::_strftime_l + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD +namespace __locale { + +using __lconv_t = std::lconv; + +class __lconv_storage { +public: + __lconv_storage(const __lconv_t* __lc_input) { + __lc_ = *__lc_input; + + __decimal_point_ = __lc_input->decimal_point; + __thousands_sep_ = __lc_input->thousands_sep; + __grouping_ = __lc_input->grouping; + __int_curr_symbol_ = __lc_input->int_curr_symbol; + __currency_symbol_ = __lc_input->currency_symbol; + __mon_decimal_point_ = __lc_input->mon_decimal_point; + __mon_thousands_sep_ = __lc_input->mon_thousands_sep; + __mon_grouping_ = __lc_input->mon_grouping; + __positive_sign_ = __lc_input->positive_sign; + __negative_sign_ = __lc_input->negative_sign; + + __lc_.decimal_point = const_cast(__decimal_point_.c_str()); + __lc_.thousands_sep = const_cast(__thousands_sep_.c_str()); + __lc_.grouping = const_cast(__grouping_.c_str()); + __lc_.int_curr_symbol = const_cast(__int_curr_symbol_.c_str()); + __lc_.currency_symbol = const_cast(__currency_symbol_.c_str()); + __lc_.mon_decimal_point = const_cast(__mon_decimal_point_.c_str()); + __lc_.mon_thousands_sep = const_cast(__mon_thousands_sep_.c_str()); + __lc_.mon_grouping = const_cast(__mon_grouping_.c_str()); + __lc_.positive_sign = const_cast(__positive_sign_.c_str()); + __lc_.negative_sign = const_cast(__negative_sign_.c_str()); + } + + __lconv_t* __get() { return &__lc_; } + +private: + __lconv_t __lc_; + std::string __decimal_point_; + std::string __thousands_sep_; + std::string __grouping_; + std::string __int_curr_symbol_; + std::string __currency_symbol_; + std::string __mon_decimal_point_; + std::string __mon_thousands_sep_; + std::string __mon_grouping_; + std::string __positive_sign_; + std::string __negative_sign_; +}; + +// +// Locale management +// +#define _CATMASK(n) ((1 << (n)) >> 1) +#define _LIBCPP_COLLATE_MASK _CATMASK(LC_COLLATE) +#define _LIBCPP_CTYPE_MASK _CATMASK(LC_CTYPE) +#define _LIBCPP_MONETARY_MASK _CATMASK(LC_MONETARY) +#define _LIBCPP_NUMERIC_MASK _CATMASK(LC_NUMERIC) +#define _LIBCPP_TIME_MASK _CATMASK(LC_TIME) +#define _LIBCPP_MESSAGES_MASK _CATMASK(6) +#define _LIBCPP_ALL_MASK \ + (_LIBCPP_COLLATE_MASK | _LIBCPP_CTYPE_MASK | _LIBCPP_MESSAGES_MASK | _LIBCPP_MONETARY_MASK | _LIBCPP_NUMERIC_MASK | \ + _LIBCPP_TIME_MASK) +#define _LIBCPP_LC_ALL LC_ALL + +class __locale_t { +public: + __locale_t() : __locale_(nullptr), __locale_str_(nullptr), __lc_(nullptr) {} + __locale_t(std::nullptr_t) : __locale_(nullptr), __locale_str_(nullptr), __lc_(nullptr) {} + __locale_t(::_locale_t __loc, const char* __loc_str) : __locale_(__loc), __locale_str_(__loc_str), __lc_(nullptr) {} + __locale_t(const __locale_t& __loc) + : __locale_(__loc.__locale_), __locale_str_(__loc.__locale_str_), __lc_(nullptr) {} + + ~__locale_t() { delete __lc_; } + + __locale_t& operator=(const __locale_t& __loc) { + __locale_ = __loc.__locale_; + __locale_str_ = __loc.__locale_str_; + // __lc_ not copied + return *this; + } + + friend bool operator==(const __locale_t& __left, const __locale_t& __right) { + return __left.__locale_ == __right.__locale_; + } + + friend bool operator==(const __locale_t& __left, int __right) { return __left.__locale_ == nullptr && __right == 0; } + + friend bool operator==(const __locale_t& __left, long long __right) { + return __left.__locale_ == nullptr && __right == 0; + } + + friend bool operator==(const __locale_t& __left, std::nullptr_t) { return __left.__locale_ == nullptr; } + + friend bool operator==(int __left, const __locale_t& __right) { return __left == 0 && nullptr == __right.__locale_; } + + friend bool operator==(std::nullptr_t, const __locale_t& __right) { return nullptr == __right.__locale_; } + + friend bool operator!=(const __locale_t& __left, const __locale_t& __right) { return !(__left == __right); } + + friend bool operator!=(const __locale_t& __left, int __right) { return !(__left == __right); } + + friend bool operator!=(const __locale_t& __left, long long __right) { return !(__left == __right); } + + friend bool operator!=(const __locale_t& __left, std::nullptr_t __right) { return !(__left == __right); } + + friend bool operator!=(int __left, const __locale_t& __right) { return !(__left == __right); } + + friend bool operator!=(std::nullptr_t __left, const __locale_t& __right) { return !(__left == __right); } + + operator bool() const { return __locale_ != nullptr; } + + const char* __get_locale() const { return __locale_str_; } + + operator ::_locale_t() const { return __locale_; } + + __lconv_t* __store_lconv(const __lconv_t* __input_lc) { + delete __lc_; + __lc_ = new __lconv_storage(__input_lc); + return __lc_->__get(); + } + +private: + ::_locale_t __locale_; + const char* __locale_str_; + __lconv_storage* __lc_ = nullptr; +}; + +#if defined(_LIBCPP_BUILDING_LIBRARY) +_LIBCPP_EXPORTED_FROM_ABI __locale_t __newlocale(int __mask, const char* __locale, __locale_t __base); +inline _LIBCPP_HIDE_FROM_ABI void __freelocale(__locale_t __loc) { ::_free_locale(__loc); } +inline _LIBCPP_HIDE_FROM_ABI char* __setlocale(int __category, const char* __locale) { + char* __new_locale = ::setlocale(__category, __locale); + if (__new_locale == nullptr) + std::__throw_bad_alloc(); + return __new_locale; +} +_LIBCPP_EXPORTED_FROM_ABI __lconv_t* __localeconv(__locale_t& __loc); +#endif // _LIBCPP_BUILDING_LIBRARY + +// +// Strtonum functions +// + +// the *_l functions are prefixed on Windows, only available for msvcr80+, VS2005+ +#if defined(_LIBCPP_MSVCRT) +inline _LIBCPP_HIDE_FROM_ABI float __strtof(const char* __nptr, char** __endptr, __locale_t __loc) { + return ::_strtof_l(__nptr, __endptr, __loc); +} +inline _LIBCPP_HIDE_FROM_ABI long double __strtold(const char* __nptr, char** __endptr, __locale_t __loc) { + return ::_strtold_l(__nptr, __endptr, __loc); +} +#else +_LIBCPP_EXPORTED_FROM_ABI float __strtof(const char*, char**, __locale_t); +_LIBCPP_EXPORTED_FROM_ABI long double __strtold(const char*, char**, __locale_t); +#endif + +inline _LIBCPP_HIDE_FROM_ABI double __strtod(const char* __nptr, char** __endptr, __locale_t __loc) { + return ::_strtod_l(__nptr, __endptr, __loc); +} + +inline _LIBCPP_HIDE_FROM_ABI long long __strtoll(const char* __nptr, char** __endptr, int __base, __locale_t __loc) { + return ::_strtoi64_l(__nptr, __endptr, __base, __loc); +} +inline _LIBCPP_HIDE_FROM_ABI unsigned long long +__strtoull(const char* __nptr, char** __endptr, int __base, __locale_t __loc) { + return ::_strtoui64_l(__nptr, __endptr, __base, __loc); +} + +// +// Character manipulation functions +// +#if defined(_LIBCPP_BUILDING_LIBRARY) +inline _LIBCPP_HIDE_FROM_ABI int __islower(int __c, __locale_t __loc) { return _islower_l(__c, __loc); } + +inline _LIBCPP_HIDE_FROM_ABI int __isupper(int __c, __locale_t __loc) { return _isupper_l(__c, __loc); } +#endif + +inline _LIBCPP_HIDE_FROM_ABI int __isdigit(int __c, __locale_t __loc) { return _isdigit_l(__c, __loc); } + +inline _LIBCPP_HIDE_FROM_ABI int __isxdigit(int __c, __locale_t __loc) { return _isxdigit_l(__c, __loc); } + +#if defined(_LIBCPP_BUILDING_LIBRARY) +inline _LIBCPP_HIDE_FROM_ABI int __toupper(int __c, __locale_t __loc) { return ::_toupper_l(__c, __loc); } + +inline _LIBCPP_HIDE_FROM_ABI int __tolower(int __c, __locale_t __loc) { return ::_tolower_l(__c, __loc); } + +inline _LIBCPP_HIDE_FROM_ABI int __strcoll(const char* __s1, const char* __s2, __locale_t __loc) { + return ::_strcoll_l(__s1, __s2, __loc); +} + +inline _LIBCPP_HIDE_FROM_ABI size_t __strxfrm(char* __dest, const char* __src, size_t __n, __locale_t __loc) { + return ::_strxfrm_l(__dest, __src, __n, __loc); +} + +# if _LIBCPP_HAS_WIDE_CHARACTERS +inline _LIBCPP_HIDE_FROM_ABI int __iswctype(wint_t __c, wctype_t __type, __locale_t __loc) { + return ::_iswctype_l(__c, __type, __loc); +} +inline _LIBCPP_HIDE_FROM_ABI int __iswspace(wint_t __c, __locale_t __loc) { return ::_iswspace_l(__c, __loc); } +inline _LIBCPP_HIDE_FROM_ABI int __iswprint(wint_t __c, __locale_t __loc) { return ::_iswprint_l(__c, __loc); } +inline _LIBCPP_HIDE_FROM_ABI int __iswcntrl(wint_t __c, __locale_t __loc) { return ::_iswcntrl_l(__c, __loc); } +inline _LIBCPP_HIDE_FROM_ABI int __iswupper(wint_t __c, __locale_t __loc) { return ::_iswupper_l(__c, __loc); } +inline _LIBCPP_HIDE_FROM_ABI int __iswlower(wint_t __c, __locale_t __loc) { return ::_iswlower_l(__c, __loc); } +inline _LIBCPP_HIDE_FROM_ABI int __iswalpha(wint_t __c, __locale_t __loc) { return ::_iswalpha_l(__c, __loc); } +// TODO: use locale to determine blank characters +inline _LIBCPP_HIDE_FROM_ABI int __iswblank(wint_t __c, __locale_t /*loc*/) { return (__c == L' ' || __c == L'\t'); } +inline _LIBCPP_HIDE_FROM_ABI int __iswdigit(wint_t __c, __locale_t __loc) { return ::_iswdigit_l(__c, __loc); } +inline _LIBCPP_HIDE_FROM_ABI int __iswpunct(wint_t __c, __locale_t __loc) { return ::_iswpunct_l(__c, __loc); } +inline _LIBCPP_HIDE_FROM_ABI int __iswxdigit(wint_t __c, __locale_t __loc) { return ::_iswxdigit_l(__c, __loc); } +inline _LIBCPP_HIDE_FROM_ABI wint_t __towupper(wint_t __c, __locale_t __loc) { return ::_towupper_l(__c, __loc); } +inline _LIBCPP_HIDE_FROM_ABI wint_t __towlower(wint_t __c, __locale_t __loc) { return ::_towlower_l(__c, __loc); } + +inline _LIBCPP_HIDE_FROM_ABI int __wcscoll(const wchar_t* __ws1, const wchar_t* __ws2, __locale_t __loc) { + return ::_wcscoll_l(__ws1, __ws2, __loc); +} + +inline _LIBCPP_HIDE_FROM_ABI size_t __wcsxfrm(wchar_t* __dest, const wchar_t* __src, size_t __n, __locale_t __loc) { + return ::_wcsxfrm_l(__dest, __src, __n, __loc); +} +# endif // _LIBCPP_HAS_WIDE_CHARACTERS + +# if defined(__MINGW32__) && __MSVCRT_VERSION__ < 0x0800 +_LIBCPP_EXPORTED_FROM_ABI size_t __strftime(char*, size_t, const char*, const struct tm*, __locale_t); +# else +inline _LIBCPP_HIDE_FROM_ABI size_t +__strftime(char* __ret, size_t __n, const char* __format, const struct tm* __tm, __locale_t __loc) { + return ::_strftime_l(__ret, __n, __format, __tm, __loc); +} +# endif + +// +// Other functions +// +_LIBCPP_EXPORTED_FROM_ABI decltype(MB_CUR_MAX) __mb_len_max(__locale_t); +_LIBCPP_EXPORTED_FROM_ABI wint_t __btowc(int, __locale_t); +_LIBCPP_EXPORTED_FROM_ABI int __wctob(wint_t, __locale_t); +_LIBCPP_EXPORTED_FROM_ABI size_t +__wcsnrtombs(char* __restrict, const wchar_t** __restrict, size_t, size_t, mbstate_t* __restrict, __locale_t); +_LIBCPP_EXPORTED_FROM_ABI size_t __wcrtomb(char* __restrict, wchar_t, mbstate_t* __restrict, __locale_t); +_LIBCPP_EXPORTED_FROM_ABI size_t +__mbsnrtowcs(wchar_t* __restrict, const char** __restrict, size_t, size_t, mbstate_t* __restrict, __locale_t); +_LIBCPP_EXPORTED_FROM_ABI size_t +__mbrtowc(wchar_t* __restrict, const char* __restrict, size_t, mbstate_t* __restrict, __locale_t); + +inline _LIBCPP_HIDE_FROM_ABI int __mbtowc(wchar_t* __pwc, const char* __pmb, size_t __max, __locale_t __loc) { + return ::_mbtowc_l(__pwc, __pmb, __max, __loc); +} + +_LIBCPP_EXPORTED_FROM_ABI size_t __mbrlen(const char* __restrict, size_t, mbstate_t* __restrict, __locale_t); + +_LIBCPP_EXPORTED_FROM_ABI size_t +__mbsrtowcs(wchar_t* __restrict, const char** __restrict, size_t, mbstate_t* __restrict, __locale_t); +#endif // _LIBCPP_BUILDING_LIBRARY + +_LIBCPP_EXPORTED_FROM_ABI _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 4, 5) int __snprintf( + char* __ret, size_t __n, __locale_t __loc, const char* __format, ...); + +_LIBCPP_EXPORTED_FROM_ABI +_LIBCPP_ATTRIBUTE_FORMAT(__printf__, 3, 4) int __asprintf(char** __ret, __locale_t __loc, const char* __format, ...); + +_LIBCPP_DIAGNOSTIC_PUSH +_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wgcc-compat") +_LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wformat-nonliteral") // GCC doesn't support [[gnu::format]] on variadic templates +#ifdef _LIBCPP_COMPILER_CLANG_BASED +# define _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(...) _LIBCPP_ATTRIBUTE_FORMAT(__VA_ARGS__) +#else +# define _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(...) /* nothing */ +#endif + +template +_LIBCPP_HIDE_FROM_ABI _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT(__scanf__, 3, 4) int __sscanf( + const char* __dest, __locale_t __loc, const char* __format, _Args&&... __args) { + return ::_sscanf_l(__dest, __format, __loc, std::forward<_Args>(__args)...); +} +_LIBCPP_DIAGNOSTIC_POP +#undef _LIBCPP_VARIADIC_ATTRIBUTE_FORMAT + +#if defined(_LIBCPP_BUILDING_LIBRARY) +struct __locale_guard { + _LIBCPP_HIDE_FROM_ABI __locale_guard(__locale_t __l) : __status(_configthreadlocale(_ENABLE_PER_THREAD_LOCALE)) { + // Setting the locale can be expensive even when the locale given is + // already the current locale, so do an explicit check to see if the + // current locale is already the one we want. + const char* __lc = __locale::__setlocale(LC_ALL, nullptr); + // If every category is the same, the locale string will simply be the + // locale name, otherwise it will be a semicolon-separated string listing + // each category. In the second case, we know at least one category won't + // be what we want, so we only have to check the first case. + if (std::strcmp(__l.__get_locale(), __lc) != 0) { + __locale_all = _strdup(__lc); + if (__locale_all == nullptr) + __throw_bad_alloc(); + __locale::__setlocale(LC_ALL, __l.__get_locale()); + } + } + _LIBCPP_HIDE_FROM_ABI ~__locale_guard() { + // The CRT documentation doesn't explicitly say, but setlocale() does the + // right thing when given a semicolon-separated list of locale settings + // for the different categories in the same format as returned by + // setlocale(LC_ALL, nullptr). + if (__locale_all != nullptr) { + __locale::__setlocale(LC_ALL, __locale_all); + free(__locale_all); + } + _configthreadlocale(__status); + } + int __status; + char* __locale_all = nullptr; +}; +#endif // _LIBCPP_BUILDING_LIBRARY + +} // namespace __locale +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___LOCALE_DIR_SUPPORT_WINDOWS_H diff --git a/system/lib/libcxx/include/__math/abs.h b/system/lib/libcxx/include/__math/abs.h index ab82a2800f53c..fc3bf3a2c7c32 100644 --- a/system/lib/libcxx/include/__math/abs.h +++ b/system/lib/libcxx/include/__math/abs.h @@ -23,19 +23,19 @@ namespace __math { // fabs -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float fabs(float __x) _NOEXCEPT { return __builtin_fabsf(__x); } +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI float fabs(float __x) _NOEXCEPT { return __builtin_fabsf(__x); } template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI double fabs(double __x) _NOEXCEPT { +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI double fabs(double __x) _NOEXCEPT { return __builtin_fabs(__x); } -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI long double fabs(long double __x) _NOEXCEPT { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI long double fabs(long double __x) _NOEXCEPT { return __builtin_fabsl(__x); } template ::value, int> = 0> -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI double fabs(_A1 __x) _NOEXCEPT { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI double fabs(_A1 __x) _NOEXCEPT { return __builtin_fabs((double)__x); } diff --git a/system/lib/libcxx/include/__math/copysign.h b/system/lib/libcxx/include/__math/copysign.h index b38690bb581a1..c3ca6a3b0370b 100644 --- a/system/lib/libcxx/include/__math/copysign.h +++ b/system/lib/libcxx/include/__math/copysign.h @@ -13,7 +13,6 @@ #include <__type_traits/enable_if.h> #include <__type_traits/is_arithmetic.h> #include <__type_traits/promote.h> -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -25,16 +24,16 @@ namespace __math { // copysign -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float copysign(float __x, float __y) _NOEXCEPT { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI float copysign(float __x, float __y) _NOEXCEPT { return ::__builtin_copysignf(__x, __y); } -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI long double copysign(long double __x, long double __y) _NOEXCEPT { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI long double copysign(long double __x, long double __y) _NOEXCEPT { return ::__builtin_copysignl(__x, __y); } template ::value && is_arithmetic<_A2>::value, int> = 0> -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type copysign(_A1 __x, _A2 __y) _NOEXCEPT { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type copysign(_A1 __x, _A2 __y) _NOEXCEPT { return ::__builtin_copysign(__x, __y); } diff --git a/system/lib/libcxx/include/__math/hypot.h b/system/lib/libcxx/include/__math/hypot.h index b992163711010..b2bf8e11c8ec2 100644 --- a/system/lib/libcxx/include/__math/hypot.h +++ b/system/lib/libcxx/include/__math/hypot.h @@ -9,16 +9,15 @@ #ifndef _LIBCPP___MATH_HYPOT_H #define _LIBCPP___MATH_HYPOT_H -#include <__algorithm/max.h> #include <__config> #include <__math/abs.h> #include <__math/exponential_functions.h> +#include <__math/min_max.h> #include <__math/roots.h> #include <__type_traits/enable_if.h> #include <__type_traits/is_arithmetic.h> #include <__type_traits/is_same.h> #include <__type_traits/promote.h> -#include <__utility/pair.h> #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -63,7 +62,7 @@ _LIBCPP_HIDE_FROM_ABI _Real __hypot(_Real __x, _Real __y, _Real __z) { const _Real __overflow_scale = __math::ldexp(_Real(1), -(__exp + 20)); // Scale arguments depending on their size - const _Real __max_abs = std::max(__math::fabs(__x), std::max(__math::fabs(__y), __math::fabs(__z))); + const _Real __max_abs = __math::fmax(__math::fabs(__x), __math::fmax(__math::fabs(__y), __math::fabs(__z))); _Real __scale; if (__max_abs > __overflow_threshold) { // x*x + y*y + z*z might overflow __scale = __overflow_scale; diff --git a/system/lib/libcxx/include/__math/min_max.h b/system/lib/libcxx/include/__math/min_max.h index 27997b44910a1..db900c849e722 100644 --- a/system/lib/libcxx/include/__math/min_max.h +++ b/system/lib/libcxx/include/__math/min_max.h @@ -25,21 +25,21 @@ namespace __math { // fmax -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float fmax(float __x, float __y) _NOEXCEPT { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI float fmax(float __x, float __y) _NOEXCEPT { return __builtin_fmaxf(__x, __y); } template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI double fmax(double __x, double __y) _NOEXCEPT { +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI double fmax(double __x, double __y) _NOEXCEPT { return __builtin_fmax(__x, __y); } -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI long double fmax(long double __x, long double __y) _NOEXCEPT { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI long double fmax(long double __x, long double __y) _NOEXCEPT { return __builtin_fmaxl(__x, __y); } template ::value && is_arithmetic<_A2>::value, int> = 0> -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type fmax(_A1 __x, _A2 __y) _NOEXCEPT { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type fmax(_A1 __x, _A2 __y) _NOEXCEPT { using __result_type = typename __promote<_A1, _A2>::type; static_assert(!(_IsSame<_A1, __result_type>::value && _IsSame<_A2, __result_type>::value), ""); return __math::fmax((__result_type)__x, (__result_type)__y); @@ -47,21 +47,21 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::typ // fmin -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float fmin(float __x, float __y) _NOEXCEPT { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI float fmin(float __x, float __y) _NOEXCEPT { return __builtin_fminf(__x, __y); } template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI double fmin(double __x, double __y) _NOEXCEPT { +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI double fmin(double __x, double __y) _NOEXCEPT { return __builtin_fmin(__x, __y); } -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI long double fmin(long double __x, long double __y) _NOEXCEPT { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI long double fmin(long double __x, long double __y) _NOEXCEPT { return __builtin_fminl(__x, __y); } template ::value && is_arithmetic<_A2>::value, int> = 0> -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type fmin(_A1 __x, _A2 __y) _NOEXCEPT { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type fmin(_A1 __x, _A2 __y) _NOEXCEPT { using __result_type = typename __promote<_A1, _A2>::type; static_assert(!(_IsSame<_A1, __result_type>::value && _IsSame<_A2, __result_type>::value), ""); return __math::fmin((__result_type)__x, (__result_type)__y); diff --git a/system/lib/libcxx/include/__math/remainder.h b/system/lib/libcxx/include/__math/remainder.h index 0fbf0b8ef97b9..0adb7f3af5de2 100644 --- a/system/lib/libcxx/include/__math/remainder.h +++ b/system/lib/libcxx/include/__math/remainder.h @@ -14,7 +14,6 @@ #include <__type_traits/is_arithmetic.h> #include <__type_traits/is_same.h> #include <__type_traits/promote.h> -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/system/lib/libcxx/include/__math/roots.h b/system/lib/libcxx/include/__math/roots.h index 359fd747cfbef..cef376fb008cf 100644 --- a/system/lib/libcxx/include/__math/roots.h +++ b/system/lib/libcxx/include/__math/roots.h @@ -39,19 +39,19 @@ inline _LIBCPP_HIDE_FROM_ABI double sqrt(_A1 __x) _NOEXCEPT { // cbrt -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float cbrt(float __x) _NOEXCEPT { return __builtin_cbrtf(__x); } +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI float cbrt(float __x) _NOEXCEPT { return __builtin_cbrtf(__x); } template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI double cbrt(double __x) _NOEXCEPT { +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI double cbrt(double __x) _NOEXCEPT { return __builtin_cbrt(__x); } -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI long double cbrt(long double __x) _NOEXCEPT { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI long double cbrt(long double __x) _NOEXCEPT { return __builtin_cbrtl(__x); } template ::value, int> = 0> -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI double cbrt(_A1 __x) _NOEXCEPT { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI double cbrt(_A1 __x) _NOEXCEPT { return __builtin_cbrt((double)__x); } diff --git a/system/lib/libcxx/include/__math/rounding_functions.h b/system/lib/libcxx/include/__math/rounding_functions.h index f7246ba7fed0d..474f585a62f15 100644 --- a/system/lib/libcxx/include/__math/rounding_functions.h +++ b/system/lib/libcxx/include/__math/rounding_functions.h @@ -26,37 +26,37 @@ namespace __math { // ceil -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float ceil(float __x) _NOEXCEPT { return __builtin_ceilf(__x); } +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI float ceil(float __x) _NOEXCEPT { return __builtin_ceilf(__x); } template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI double ceil(double __x) _NOEXCEPT { +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI double ceil(double __x) _NOEXCEPT { return __builtin_ceil(__x); } -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI long double ceil(long double __x) _NOEXCEPT { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI long double ceil(long double __x) _NOEXCEPT { return __builtin_ceill(__x); } template ::value, int> = 0> -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI double ceil(_A1 __x) _NOEXCEPT { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI double ceil(_A1 __x) _NOEXCEPT { return __builtin_ceil((double)__x); } // floor -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float floor(float __x) _NOEXCEPT { return __builtin_floorf(__x); } +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI float floor(float __x) _NOEXCEPT { return __builtin_floorf(__x); } template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI double floor(double __x) _NOEXCEPT { +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI double floor(double __x) _NOEXCEPT { return __builtin_floor(__x); } -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI long double floor(long double __x) _NOEXCEPT { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI long double floor(long double __x) _NOEXCEPT { return __builtin_floorl(__x); } template ::value, int> = 0> -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI double floor(_A1 __x) _NOEXCEPT { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI double floor(_A1 __x) _NOEXCEPT { return __builtin_floor((double)__x); } @@ -126,21 +126,21 @@ inline _LIBCPP_HIDE_FROM_ABI long lround(_A1 __x) _NOEXCEPT { // nearbyint -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float nearbyint(float __x) _NOEXCEPT { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI float nearbyint(float __x) _NOEXCEPT { return __builtin_nearbyintf(__x); } template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI double nearbyint(double __x) _NOEXCEPT { +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI double nearbyint(double __x) _NOEXCEPT { return __builtin_nearbyint(__x); } -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI long double nearbyint(long double __x) _NOEXCEPT { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI long double nearbyint(long double __x) _NOEXCEPT { return __builtin_nearbyintl(__x); } template ::value, int> = 0> -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI double nearbyint(_A1 __x) _NOEXCEPT { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI double nearbyint(_A1 __x) _NOEXCEPT { return __builtin_nearbyint((double)__x); } @@ -186,55 +186,55 @@ inline _LIBCPP_HIDE_FROM_ABI double nexttoward(_A1 __x, long double __y) _NOEXCE // rint -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float rint(float __x) _NOEXCEPT { return __builtin_rintf(__x); } +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI float rint(float __x) _NOEXCEPT { return __builtin_rintf(__x); } template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI double rint(double __x) _NOEXCEPT { +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI double rint(double __x) _NOEXCEPT { return __builtin_rint(__x); } -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI long double rint(long double __x) _NOEXCEPT { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI long double rint(long double __x) _NOEXCEPT { return __builtin_rintl(__x); } template ::value, int> = 0> -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI double rint(_A1 __x) _NOEXCEPT { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI double rint(_A1 __x) _NOEXCEPT { return __builtin_rint((double)__x); } // round -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float round(float __x) _NOEXCEPT { return __builtin_round(__x); } +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI float round(float __x) _NOEXCEPT { return __builtin_round(__x); } template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI double round(double __x) _NOEXCEPT { +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI double round(double __x) _NOEXCEPT { return __builtin_round(__x); } -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI long double round(long double __x) _NOEXCEPT { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI long double round(long double __x) _NOEXCEPT { return __builtin_roundl(__x); } template ::value, int> = 0> -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI double round(_A1 __x) _NOEXCEPT { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI double round(_A1 __x) _NOEXCEPT { return __builtin_round((double)__x); } // trunc -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float trunc(float __x) _NOEXCEPT { return __builtin_trunc(__x); } +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI float trunc(float __x) _NOEXCEPT { return __builtin_trunc(__x); } template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI double trunc(double __x) _NOEXCEPT { +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI double trunc(double __x) _NOEXCEPT { return __builtin_trunc(__x); } -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI long double trunc(long double __x) _NOEXCEPT { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI long double trunc(long double __x) _NOEXCEPT { return __builtin_truncl(__x); } template ::value, int> = 0> -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI double trunc(_A1 __x) _NOEXCEPT { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI double trunc(_A1 __x) _NOEXCEPT { return __builtin_trunc((double)__x); } diff --git a/system/lib/libcxx/include/__math/traits.h b/system/lib/libcxx/include/__math/traits.h index 27ec52ecef022..0c96f766a767e 100644 --- a/system/lib/libcxx/include/__math/traits.h +++ b/system/lib/libcxx/include/__math/traits.h @@ -12,11 +12,9 @@ #include <__config> #include <__type_traits/enable_if.h> #include <__type_traits/is_arithmetic.h> -#include <__type_traits/is_floating_point.h> #include <__type_traits/is_integral.h> #include <__type_traits/is_signed.h> #include <__type_traits/promote.h> -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -28,115 +26,131 @@ namespace __math { // signbit -template ::value, int> = 0> -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool signbit(_A1 __x) _NOEXCEPT { +// TODO(LLVM 22): Remove conditional once support for Clang 19 is dropped. +#if defined(_LIBCPP_COMPILER_GCC) || __has_constexpr_builtin(__builtin_signbit) +# define _LIBCPP_SIGNBIT_CONSTEXPR _LIBCPP_CONSTEXPR_SINCE_CXX23 +#else +# define _LIBCPP_SIGNBIT_CONSTEXPR +#endif + +// The universal C runtime (UCRT) in the WinSDK provides floating point overloads +// for std::signbit(). By defining our overloads as templates, we can work around +// this issue as templates are less preferred than non-template functions. +template +[[__nodiscard__]] inline _LIBCPP_SIGNBIT_CONSTEXPR _LIBCPP_HIDE_FROM_ABI bool signbit(float __x) _NOEXCEPT { + return __builtin_signbit(__x); +} + +template +[[__nodiscard__]] inline _LIBCPP_SIGNBIT_CONSTEXPR _LIBCPP_HIDE_FROM_ABI bool signbit(double __x) _NOEXCEPT { + return __builtin_signbit(__x); +} + +template +[[__nodiscard__]] inline _LIBCPP_SIGNBIT_CONSTEXPR _LIBCPP_HIDE_FROM_ABI bool signbit(long double __x) _NOEXCEPT { return __builtin_signbit(__x); } template ::value && is_signed<_A1>::value, int> = 0> -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool signbit(_A1 __x) _NOEXCEPT { +[[__nodiscard__]] inline _LIBCPP_SIGNBIT_CONSTEXPR _LIBCPP_HIDE_FROM_ABI bool signbit(_A1 __x) _NOEXCEPT { return __x < 0; } template ::value && !is_signed<_A1>::value, int> = 0> -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool signbit(_A1) _NOEXCEPT { +[[__nodiscard__]] inline _LIBCPP_SIGNBIT_CONSTEXPR _LIBCPP_HIDE_FROM_ABI bool signbit(_A1) _NOEXCEPT { return false; } // isfinite -template ::value && numeric_limits<_A1>::has_infinity, int> = 0> -_LIBCPP_NODISCARD _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isfinite(_A1 __x) _NOEXCEPT { - return __builtin_isfinite((typename __promote<_A1>::type)__x); -} - -template ::value && !numeric_limits<_A1>::has_infinity, int> = 0> -_LIBCPP_NODISCARD _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isfinite(_A1) _NOEXCEPT { +template ::value, int> = 0> +[[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isfinite(_A1) _NOEXCEPT { return true; } -_LIBCPP_NODISCARD inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isfinite(float __x) _NOEXCEPT { +[[__nodiscard__]] inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isfinite(float __x) _NOEXCEPT { return __builtin_isfinite(__x); } -_LIBCPP_NODISCARD inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isfinite(double __x) _NOEXCEPT { +[[__nodiscard__]] inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isfinite(double __x) _NOEXCEPT { return __builtin_isfinite(__x); } -_LIBCPP_NODISCARD inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isfinite(long double __x) _NOEXCEPT { +[[__nodiscard__]] inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isfinite(long double __x) _NOEXCEPT { return __builtin_isfinite(__x); } // isinf -template ::value && numeric_limits<_A1>::has_infinity, int> = 0> -_LIBCPP_NODISCARD _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isinf(_A1 __x) _NOEXCEPT { - return __builtin_isinf((typename __promote<_A1>::type)__x); -} - -template ::value && !numeric_limits<_A1>::has_infinity, int> = 0> -_LIBCPP_NODISCARD _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isinf(_A1) _NOEXCEPT { +template ::value, int> = 0> +[[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isinf(_A1) _NOEXCEPT { return false; } -#ifdef _LIBCPP_PREFERRED_OVERLOAD -_LIBCPP_NODISCARD inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isinf(float __x) _NOEXCEPT { +[[__nodiscard__]] inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isinf(float __x) _NOEXCEPT { return __builtin_isinf(__x); } -_LIBCPP_NODISCARD inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD bool -isinf(double __x) _NOEXCEPT { +[[__nodiscard__]] inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI +#ifdef _LIBCPP_PREFERRED_OVERLOAD +_LIBCPP_PREFERRED_OVERLOAD +#endif + bool + isinf(double __x) _NOEXCEPT { return __builtin_isinf(__x); } -_LIBCPP_NODISCARD inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isinf(long double __x) _NOEXCEPT { +[[__nodiscard__]] inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isinf(long double __x) _NOEXCEPT { return __builtin_isinf(__x); } -#endif // isnan -template ::value, int> = 0> -_LIBCPP_NODISCARD _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnan(_A1 __x) _NOEXCEPT { - return __builtin_isnan(__x); -} - template ::value, int> = 0> -_LIBCPP_NODISCARD _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnan(_A1) _NOEXCEPT { +[[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnan(_A1) _NOEXCEPT { return false; } -#ifdef _LIBCPP_PREFERRED_OVERLOAD -_LIBCPP_NODISCARD inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnan(float __x) _NOEXCEPT { +[[__nodiscard__]] inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnan(float __x) _NOEXCEPT { return __builtin_isnan(__x); } -_LIBCPP_NODISCARD inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD bool -isnan(double __x) _NOEXCEPT { +[[__nodiscard__]] inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI +#ifdef _LIBCPP_PREFERRED_OVERLOAD +_LIBCPP_PREFERRED_OVERLOAD +#endif + bool + isnan(double __x) _NOEXCEPT { return __builtin_isnan(__x); } -_LIBCPP_NODISCARD inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnan(long double __x) _NOEXCEPT { +[[__nodiscard__]] inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnan(long double __x) _NOEXCEPT { return __builtin_isnan(__x); } -#endif // isnormal -template ::value, int> = 0> -_LIBCPP_NODISCARD _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnormal(_A1 __x) _NOEXCEPT { +template ::value, int> = 0> +[[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnormal(_A1 __x) _NOEXCEPT { + return __x != 0; +} + +[[__nodiscard__]] inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnormal(float __x) _NOEXCEPT { return __builtin_isnormal(__x); } -template ::value, int> = 0> -_LIBCPP_NODISCARD _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnormal(_A1 __x) _NOEXCEPT { - return __x != 0; +[[__nodiscard__]] inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnormal(double __x) _NOEXCEPT { + return __builtin_isnormal(__x); +} + +[[__nodiscard__]] inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnormal(long double __x) _NOEXCEPT { + return __builtin_isnormal(__x); } // isgreater template ::value && is_arithmetic<_A2>::value, int> = 0> -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool isgreater(_A1 __x, _A2 __y) _NOEXCEPT { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI bool isgreater(_A1 __x, _A2 __y) _NOEXCEPT { using type = typename __promote<_A1, _A2>::type; return __builtin_isgreater((type)__x, (type)__y); } @@ -144,7 +158,7 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool isgreater(_A1 __x, _A2 __y) // isgreaterequal template ::value && is_arithmetic<_A2>::value, int> = 0> -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool isgreaterequal(_A1 __x, _A2 __y) _NOEXCEPT { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI bool isgreaterequal(_A1 __x, _A2 __y) _NOEXCEPT { using type = typename __promote<_A1, _A2>::type; return __builtin_isgreaterequal((type)__x, (type)__y); } @@ -152,7 +166,7 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool isgreaterequal(_A1 __x, _A2 // isless template ::value && is_arithmetic<_A2>::value, int> = 0> -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool isless(_A1 __x, _A2 __y) _NOEXCEPT { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI bool isless(_A1 __x, _A2 __y) _NOEXCEPT { using type = typename __promote<_A1, _A2>::type; return __builtin_isless((type)__x, (type)__y); } @@ -160,7 +174,7 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool isless(_A1 __x, _A2 __y) _NO // islessequal template ::value && is_arithmetic<_A2>::value, int> = 0> -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool islessequal(_A1 __x, _A2 __y) _NOEXCEPT { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI bool islessequal(_A1 __x, _A2 __y) _NOEXCEPT { using type = typename __promote<_A1, _A2>::type; return __builtin_islessequal((type)__x, (type)__y); } @@ -168,7 +182,7 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool islessequal(_A1 __x, _A2 __y // islessgreater template ::value && is_arithmetic<_A2>::value, int> = 0> -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool islessgreater(_A1 __x, _A2 __y) _NOEXCEPT { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI bool islessgreater(_A1 __x, _A2 __y) _NOEXCEPT { using type = typename __promote<_A1, _A2>::type; return __builtin_islessgreater((type)__x, (type)__y); } @@ -176,7 +190,7 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool islessgreater(_A1 __x, _A2 _ // isunordered template ::value && is_arithmetic<_A2>::value, int> = 0> -_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool isunordered(_A1 __x, _A2 __y) _NOEXCEPT { +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI bool isunordered(_A1 __x, _A2 __y) _NOEXCEPT { using type = typename __promote<_A1, _A2>::type; return __builtin_isunordered((type)__x, (type)__y); } diff --git a/system/lib/libcxx/include/__mbstate_t.h b/system/lib/libcxx/include/__mbstate_t.h index bfa6d617e2b8f..e013384454b41 100644 --- a/system/lib/libcxx/include/__mbstate_t.h +++ b/system/lib/libcxx/include/__mbstate_t.h @@ -35,7 +35,7 @@ # define __CORRECT_ISO_CPP_WCHAR_H_PROTO #endif -#if defined(_LIBCPP_HAS_MUSL_LIBC) +#if _LIBCPP_HAS_MUSL_LIBC # define __NEED_mbstate_t # include # undef __NEED_mbstate_t @@ -43,7 +43,7 @@ # include // works on most Unixes #elif __has_include() # include // works on Darwin -#elif !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS) && __has_include_next() +#elif _LIBCPP_HAS_WIDE_CHARACTERS && __has_include_next() # include_next // fall back to the C standard provider of mbstate_t #elif __has_include_next() # include_next // is also required to make mbstate_t visible diff --git a/system/lib/libcxx/include/__mdspan/default_accessor.h b/system/lib/libcxx/include/__mdspan/default_accessor.h index 1cc5f15545fc8..d6f3ddb998e96 100644 --- a/system/lib/libcxx/include/__mdspan/default_accessor.h +++ b/system/lib/libcxx/include/__mdspan/default_accessor.h @@ -18,12 +18,11 @@ #define _LIBCPP___MDSPAN_DEFAULT_ACCESSOR_H #include <__config> +#include <__cstddef/size_t.h> #include <__type_traits/is_abstract.h> #include <__type_traits/is_array.h> #include <__type_traits/is_convertible.h> #include <__type_traits/remove_const.h> -#include -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/system/lib/libcxx/include/__mdspan/extents.h b/system/lib/libcxx/include/__mdspan/extents.h index 95082ef3d11ac..65a697769bdaa 100644 --- a/system/lib/libcxx/include/__mdspan/extents.h +++ b/system/lib/libcxx/include/__mdspan/extents.h @@ -19,6 +19,9 @@ #include <__assert> #include <__config> + +#include <__concepts/arithmetic.h> +#include <__cstddef/byte.h> #include <__type_traits/common_type.h> #include <__type_traits/is_convertible.h> #include <__type_traits/is_nothrow_constructible.h> @@ -27,9 +30,7 @@ #include <__utility/integer_sequence.h> #include <__utility/unreachable.h> #include -#include #include -#include #include #include @@ -128,14 +129,14 @@ struct __maybe_static_array { // Static values member static constexpr size_t __size_ = sizeof...(_Values); static constexpr size_t __size_dynamic_ = ((_Values == _DynTag) + ... + 0); - using _StaticValues = __static_array<_TStatic, _Values...>; - using _DynamicValues = __possibly_empty_array<_TDynamic, __size_dynamic_>; + using _StaticValues _LIBCPP_NODEBUG = __static_array<_TStatic, _Values...>; + using _DynamicValues _LIBCPP_NODEBUG = __possibly_empty_array<_TDynamic, __size_dynamic_>; // Dynamic values member _LIBCPP_NO_UNIQUE_ADDRESS _DynamicValues __dyn_vals_; // static mapping of indices to the position in the dynamic values array - using _DynamicIdxMap = __static_partial_sums(_Values == _DynTag)...>; + using _DynamicIdxMap _LIBCPP_NODEBUG = __static_partial_sums(_Values == _DynTag)...>; template _LIBCPP_HIDE_FROM_ABI static constexpr _DynamicValues __zeros(index_sequence<_Indices...>) noexcept { @@ -282,8 +283,7 @@ class extents { using size_type = make_unsigned_t; using rank_type = size_t; - static_assert(is_integral::value && !is_same::value, - "extents::index_type must be a signed or unsigned integer type"); + static_assert(__libcpp_integer, "extents::index_type must be a signed or unsigned integer type"); static_assert(((__mdspan_detail::__is_representable_as(_Extents) || (_Extents == dynamic_extent)) && ...), "extents ctor: arguments must be representable as index_type and nonnegative"); @@ -292,7 +292,8 @@ class extents { static constexpr rank_type __rank_dynamic_ = ((_Extents == dynamic_extent) + ... + 0); // internal storage type using __maybe_static_array - using _Values = __mdspan_detail::__maybe_static_array<_IndexType, size_t, dynamic_extent, _Extents...>; + using _Values _LIBCPP_NODEBUG = + __mdspan_detail::__maybe_static_array<_IndexType, size_t, dynamic_extent, _Extents...>; [[no_unique_address]] _Values __vals_; public: @@ -448,7 +449,7 @@ struct __make_dextents< _IndexType, 0, extents<_IndexType, _ExtentsPack...>> { using type = extents<_IndexType, _ExtentsPack...>; }; -} // end namespace __mdspan_detail +} // namespace __mdspan_detail // [mdspan.extents.dextents], alias template template diff --git a/system/lib/libcxx/include/__mdspan/layout_left.h b/system/lib/libcxx/include/__mdspan/layout_left.h index d058cbccffd96..288b3dd8038ee 100644 --- a/system/lib/libcxx/include/__mdspan/layout_left.h +++ b/system/lib/libcxx/include/__mdspan/layout_left.h @@ -21,14 +21,12 @@ #include <__config> #include <__fwd/mdspan.h> #include <__mdspan/extents.h> +#include <__type_traits/common_type.h> #include <__type_traits/is_constructible.h> #include <__type_traits/is_convertible.h> #include <__type_traits/is_nothrow_constructible.h> #include <__utility/integer_sequence.h> #include -#include -#include -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/system/lib/libcxx/include/__mdspan/layout_right.h b/system/lib/libcxx/include/__mdspan/layout_right.h index 6842e9dc37fdc..72922d1049c7a 100644 --- a/system/lib/libcxx/include/__mdspan/layout_right.h +++ b/system/lib/libcxx/include/__mdspan/layout_right.h @@ -19,15 +19,14 @@ #include <__assert> #include <__config> +#include <__cstddef/size_t.h> #include <__fwd/mdspan.h> #include <__mdspan/extents.h> +#include <__type_traits/common_type.h> #include <__type_traits/is_constructible.h> #include <__type_traits/is_convertible.h> #include <__type_traits/is_nothrow_constructible.h> #include <__utility/integer_sequence.h> -#include -#include -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/system/lib/libcxx/include/__mdspan/layout_stride.h b/system/lib/libcxx/include/__mdspan/layout_stride.h index 86148ac849eca..bb93de9775145 100644 --- a/system/lib/libcxx/include/__mdspan/layout_stride.h +++ b/system/lib/libcxx/include/__mdspan/layout_stride.h @@ -18,19 +18,22 @@ #define _LIBCPP___MDSPAN_LAYOUT_STRIDE_H #include <__assert> +#include <__concepts/same_as.h> #include <__config> #include <__fwd/mdspan.h> #include <__mdspan/extents.h> +#include <__type_traits/common_type.h> #include <__type_traits/is_constructible.h> #include <__type_traits/is_convertible.h> +#include <__type_traits/is_integral.h> #include <__type_traits/is_nothrow_constructible.h> +#include <__type_traits/is_same.h> #include <__utility/as_const.h> #include <__utility/integer_sequence.h> #include <__utility/swap.h> #include -#include -#include #include +#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/system/lib/libcxx/include/__mdspan/mdspan.h b/system/lib/libcxx/include/__mdspan/mdspan.h index 1ff4fd4ba4a82..3f9b35b185b16 100644 --- a/system/lib/libcxx/include/__mdspan/mdspan.h +++ b/system/lib/libcxx/include/__mdspan/mdspan.h @@ -37,9 +37,6 @@ #include <__type_traits/remove_reference.h> #include <__utility/integer_sequence.h> #include -#include -#include -#include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) diff --git a/system/lib/libcxx/include/__memory/addressof.h b/system/lib/libcxx/include/__memory/addressof.h index fa590212c49b9..98b08958a6a93 100644 --- a/system/lib/libcxx/include/__memory/addressof.h +++ b/system/lib/libcxx/include/__memory/addressof.h @@ -23,17 +23,15 @@ inline _LIBCPP_CONSTEXPR_SINCE_CXX17 _LIBCPP_NO_CFI _LIBCPP_HIDE_FROM_ABI _Tp* a return __builtin_addressof(__x); } -#if defined(_LIBCPP_HAS_OBJC_ARC) && !defined(_LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF) +#if _LIBCPP_HAS_OBJC_ARC // Objective-C++ Automatic Reference Counting uses qualified pointers -// that require special addressof() signatures. When -// _LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF is defined, the compiler -// itself is providing these definitions. Otherwise, we provide them. +// that require special addressof() signatures. template inline _LIBCPP_HIDE_FROM_ABI __strong _Tp* addressof(__strong _Tp& __x) _NOEXCEPT { return &__x; } -# ifdef _LIBCPP_HAS_OBJC_ARC_WEAK +# if _LIBCPP_HAS_OBJC_ARC_WEAK template inline _LIBCPP_HIDE_FROM_ABI __weak _Tp* addressof(__weak _Tp& __x) _NOEXCEPT { return &__x; diff --git a/system/lib/libcxx/include/__memory/align.h b/system/lib/libcxx/include/__memory/align.h index bbb995f4a8c8e..402eac3380925 100644 --- a/system/lib/libcxx/include/__memory/align.h +++ b/system/lib/libcxx/include/__memory/align.h @@ -10,7 +10,7 @@ #define _LIBCPP___MEMORY_ALIGN_H #include <__config> -#include +#include <__cstddef/size_t.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header diff --git a/system/lib/libcxx/include/__memory/aligned_alloc.h b/system/lib/libcxx/include/__memory/aligned_alloc.h index cb424328bcafc..fb36983d9c3dc 100644 --- a/system/lib/libcxx/include/__memory/aligned_alloc.h +++ b/system/lib/libcxx/include/__memory/aligned_alloc.h @@ -10,7 +10,6 @@ #define _LIBCPP___MEMORY_ALIGNED_ALLOC_H #include <__config> -#include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -19,7 +18,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD -#ifndef _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION +#if _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION // Low-level helpers to call the aligned allocation and deallocation functions // on the target platform. This is used to implement libc++'s own memory @@ -30,7 +29,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD inline _LIBCPP_HIDE_FROM_ABI void* __libcpp_aligned_alloc(std::size_t __alignment, std::size_t __size) { # if defined(_LIBCPP_MSVCRT_LIKE) return ::_aligned_malloc(__size, __alignment); -# elif _LIBCPP_STD_VER >= 17 && !defined(_LIBCPP_HAS_NO_C11_ALIGNED_ALLOC) +# elif _LIBCPP_STD_VER >= 17 && _LIBCPP_HAS_C11_ALIGNED_ALLOC // aligned_alloc() requires that __size is a multiple of __alignment, // but for C++ [new.delete.general], only states "if the value of an // alignment argument passed to any of these functions is not a valid @@ -57,7 +56,7 @@ inline _LIBCPP_HIDE_FROM_ABI void __libcpp_aligned_free(void* __ptr) { # endif } -#endif // !_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION +#endif // _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION _LIBCPP_END_NAMESPACE_STD diff --git a/system/lib/libcxx/include/__memory/allocate_at_least.h b/system/lib/libcxx/include/__memory/allocate_at_least.h index df73d9a2e94aa..9b5a8bcbd4596 100644 --- a/system/lib/libcxx/include/__memory/allocate_at_least.h +++ b/system/lib/libcxx/include/__memory/allocate_at_least.h @@ -10,8 +10,8 @@ #define _LIBCPP___MEMORY_ALLOCATE_AT_LEAST_H #include <__config> +#include <__cstddef/size_t.h> #include <__memory/allocator_traits.h> -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -35,7 +35,7 @@ struct __allocation_result { }; template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __allocation_result::pointer> __allocate_at_least(_Alloc& __alloc, size_t __n) { return {__alloc.allocate(__n), __n}; diff --git a/system/lib/libcxx/include/__memory/allocation_guard.h b/system/lib/libcxx/include/__memory/allocation_guard.h index cb870af7be676..66edcd92ed618 100644 --- a/system/lib/libcxx/include/__memory/allocation_guard.h +++ b/system/lib/libcxx/include/__memory/allocation_guard.h @@ -14,7 +14,6 @@ #include <__memory/addressof.h> #include <__memory/allocator_traits.h> #include <__utility/move.h> -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -46,8 +45,8 @@ _LIBCPP_BEGIN_NAMESPACE_STD // custom allocator. template struct __allocation_guard { - using _Pointer = typename allocator_traits<_Alloc>::pointer; - using _Size = typename allocator_traits<_Alloc>::size_type; + using _Pointer _LIBCPP_NODEBUG = typename allocator_traits<_Alloc>::pointer; + using _Size _LIBCPP_NODEBUG = typename allocator_traits<_Alloc>::size_type; template // we perform the allocator conversion inside the constructor _LIBCPP_HIDE_FROM_ABI explicit __allocation_guard(_AllocT __alloc, _Size __n) diff --git a/system/lib/libcxx/include/__memory/allocator.h b/system/lib/libcxx/include/__memory/allocator.h index 2d8624e771bce..191a59e6614a0 100644 --- a/system/lib/libcxx/include/__memory/allocator.h +++ b/system/lib/libcxx/include/__memory/allocator.h @@ -11,17 +11,19 @@ #define _LIBCPP___MEMORY_ALLOCATOR_H #include <__config> +#include <__cstddef/ptrdiff_t.h> +#include <__cstddef/size_t.h> #include <__memory/addressof.h> #include <__memory/allocate_at_least.h> #include <__memory/allocator_traits.h> +#include <__new/allocate.h> +#include <__new/exceptions.h> #include <__type_traits/is_const.h> #include <__type_traits/is_constant_evaluated.h> #include <__type_traits/is_same.h> #include <__type_traits/is_void.h> #include <__type_traits/is_volatile.h> #include <__utility/forward.h> -#include -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -47,23 +49,7 @@ class _LIBCPP_TEMPLATE_VIS allocator { typedef allocator<_Up> other; }; }; - -// TODO(LLVM 20): Remove the escape hatch -# ifdef _LIBCPP_ENABLE_REMOVED_ALLOCATOR_CONST -template <> -class _LIBCPP_TEMPLATE_VIS allocator { -public: - _LIBCPP_DEPRECATED_IN_CXX17 typedef const void* pointer; - _LIBCPP_DEPRECATED_IN_CXX17 typedef const void* const_pointer; - _LIBCPP_DEPRECATED_IN_CXX17 typedef const void value_type; - - template - struct _LIBCPP_DEPRECATED_IN_CXX17 rebind { - typedef allocator<_Up> other; - }; -}; -# endif // _LIBCPP_ENABLE_REMOVED_ALLOCATOR_CONST -#endif // _LIBCPP_STD_VER <= 17 +#endif // _LIBCPP_STD_VER <= 17 // This class provides a non-trivial default constructor to the class that derives from it // if the condition is satisfied. @@ -109,18 +95,20 @@ class _LIBCPP_TEMPLATE_VIS allocator : private __non_trivial_if::v template _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 allocator(const allocator<_Up>&) _NOEXCEPT {} - _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp* allocate(size_t __n) { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp* allocate(size_t __n) { + static_assert(sizeof(_Tp) >= 0, "cannot allocate memory for an incomplete type"); if (__n > allocator_traits::max_size(*this)) __throw_bad_array_new_length(); if (__libcpp_is_constant_evaluated()) { return static_cast<_Tp*>(::operator new(__n * sizeof(_Tp))); } else { - return static_cast<_Tp*>(std::__libcpp_allocate(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp))); + return std::__libcpp_allocate<_Tp>(__element_count(__n)); } } #if _LIBCPP_STD_VER >= 23 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr allocation_result<_Tp*> allocate_at_least(size_t __n) { + static_assert(sizeof(_Tp) >= 0, "cannot allocate memory for an incomplete type"); return {allocate(__n), __n}; } #endif @@ -129,7 +117,7 @@ class _LIBCPP_TEMPLATE_VIS allocator : private __non_trivial_if::v if (__libcpp_is_constant_evaluated()) { ::operator delete(__p); } else { - std::__libcpp_deallocate((void*)__p, __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)); + std::__libcpp_deallocate<_Tp>(__p, __element_count(__n)); } } @@ -152,7 +140,7 @@ class _LIBCPP_TEMPLATE_VIS allocator : private __non_trivial_if::v return std::addressof(__x); } - _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_IN_CXX17 _Tp* allocate(size_t __n, const void*) { + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_IN_CXX17 _Tp* allocate(size_t __n, const void*) { return allocate(__n); } @@ -169,85 +157,6 @@ class _LIBCPP_TEMPLATE_VIS allocator : private __non_trivial_if::v #endif }; -// TODO(LLVM 20): Remove the escape hatch -#ifdef _LIBCPP_ENABLE_REMOVED_ALLOCATOR_CONST -template -class _LIBCPP_TEMPLATE_VIS allocator - : private __non_trivial_if::value, allocator > { - static_assert(!is_volatile<_Tp>::value, "std::allocator does not support volatile types"); - -public: - typedef size_t size_type; - typedef ptrdiff_t difference_type; - typedef const _Tp value_type; - typedef true_type propagate_on_container_move_assignment; -# if _LIBCPP_STD_VER <= 23 || defined(_LIBCPP_ENABLE_CXX26_REMOVED_ALLOCATOR_MEMBERS) - _LIBCPP_DEPRECATED_IN_CXX23 typedef true_type is_always_equal; -# endif - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 allocator() _NOEXCEPT = default; - - template - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 allocator(const allocator<_Up>&) _NOEXCEPT {} - - _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const _Tp* allocate(size_t __n) { - if (__n > allocator_traits::max_size(*this)) - __throw_bad_array_new_length(); - if (__libcpp_is_constant_evaluated()) { - return static_cast(::operator new(__n * sizeof(_Tp))); - } else { - return static_cast(std::__libcpp_allocate(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp))); - } - } - -# if _LIBCPP_STD_VER >= 23 - [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr allocation_result allocate_at_least(size_t __n) { - return {allocate(__n), __n}; - } -# endif - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void deallocate(const _Tp* __p, size_t __n) { - if (__libcpp_is_constant_evaluated()) { - ::operator delete(const_cast<_Tp*>(__p)); - } else { - std::__libcpp_deallocate((void*)const_cast<_Tp*>(__p), __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)); - } - } - - // C++20 Removed members -# if _LIBCPP_STD_VER <= 17 - _LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp* pointer; - _LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp* const_pointer; - _LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp& reference; - _LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp& const_reference; - - template - struct _LIBCPP_DEPRECATED_IN_CXX17 rebind { - typedef allocator<_Up> other; - }; - - _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_HIDE_FROM_ABI const_pointer address(const_reference __x) const _NOEXCEPT { - return std::addressof(__x); - } - - _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_IN_CXX17 const _Tp* allocate(size_t __n, const void*) { - return allocate(__n); - } - - _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT { - return size_type(~0) / sizeof(_Tp); - } - - template - _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_HIDE_FROM_ABI void construct(_Up* __p, _Args&&... __args) { - ::new ((void*)__p) _Up(std::forward<_Args>(__args)...); - } - - _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_HIDE_FROM_ABI void destroy(pointer __p) { __p->~_Tp(); } -# endif -}; -#endif // _LIBCPP_ENABLE_REMOVED_ALLOCATOR_CONST - template inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool operator==(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT { diff --git a/system/lib/libcxx/include/__memory/allocator_arg_t.h b/system/lib/libcxx/include/__memory/allocator_arg_t.h index 7e66da740cd4f..72a0a9c399bd4 100644 --- a/system/lib/libcxx/include/__memory/allocator_arg_t.h +++ b/system/lib/libcxx/include/__memory/allocator_arg_t.h @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#ifndef _LIBCPP___FUNCTIONAL_ALLOCATOR_ARG_T_H -#define _LIBCPP___FUNCTIONAL_ALLOCATOR_ARG_T_H +#ifndef _LIBCPP___MEMORY_ALLOCATOR_ARG_T_H +#define _LIBCPP___MEMORY_ALLOCATOR_ARG_T_H #include <__config> #include <__memory/uses_allocator.h> @@ -39,10 +39,10 @@ constexpr allocator_arg_t allocator_arg = allocator_arg_t(); template struct __uses_alloc_ctor_imp { - typedef _LIBCPP_NODEBUG __remove_cvref_t<_Alloc> _RawAlloc; - static const bool __ua = uses_allocator<_Tp, _RawAlloc>::value; - static const bool __ic = is_constructible<_Tp, allocator_arg_t, _Alloc, _Args...>::value; - static const int value = __ua ? 2 - __ic : 0; + using _RawAlloc _LIBCPP_NODEBUG = __remove_cvref_t<_Alloc>; + static const bool __ua = uses_allocator<_Tp, _RawAlloc>::value; + static const bool __ic = is_constructible<_Tp, allocator_arg_t, _Alloc, _Args...>::value; + static const int value = __ua ? 2 - __ic : 0; }; template @@ -72,4 +72,4 @@ __user_alloc_construct_impl(integral_constant, _Tp* __storage, const _Al _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP___FUNCTIONAL_ALLOCATOR_ARG_T_H +#endif // _LIBCPP___MEMORY_ALLOCATOR_ARG_T_H diff --git a/system/lib/libcxx/include/__memory/allocator_destructor.h b/system/lib/libcxx/include/__memory/allocator_destructor.h index ed3d8918f5fe3..aac92a23fa0d4 100644 --- a/system/lib/libcxx/include/__memory/allocator_destructor.h +++ b/system/lib/libcxx/include/__memory/allocator_destructor.h @@ -20,11 +20,11 @@ _LIBCPP_BEGIN_NAMESPACE_STD template class __allocator_destructor { - typedef _LIBCPP_NODEBUG allocator_traits<_Alloc> __alloc_traits; + using __alloc_traits _LIBCPP_NODEBUG = allocator_traits<_Alloc>; public: - typedef _LIBCPP_NODEBUG typename __alloc_traits::pointer pointer; - typedef _LIBCPP_NODEBUG typename __alloc_traits::size_type size_type; + using pointer _LIBCPP_NODEBUG = typename __alloc_traits::pointer; + using size_type _LIBCPP_NODEBUG = typename __alloc_traits::size_type; private: _Alloc& __alloc_; diff --git a/system/lib/libcxx/include/__memory/allocator_traits.h b/system/lib/libcxx/include/__memory/allocator_traits.h index c5fcc89327b8f..2d9ab847e9f25 100644 --- a/system/lib/libcxx/include/__memory/allocator_traits.h +++ b/system/lib/libcxx/include/__memory/allocator_traits.h @@ -11,8 +11,11 @@ #define _LIBCPP___MEMORY_ALLOCATOR_TRAITS_H #include <__config> +#include <__cstddef/size_t.h> +#include <__fwd/memory.h> #include <__memory/construct_at.h> #include <__memory/pointer_traits.h> +#include <__type_traits/detected_or.h> #include <__type_traits/enable_if.h> #include <__type_traits/is_constructible.h> #include <__type_traits/is_empty.h> @@ -22,7 +25,6 @@ #include <__type_traits/void_t.h> #include <__utility/declval.h> #include <__utility/forward.h> -#include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -41,17 +43,11 @@ _LIBCPP_BEGIN_NAMESPACE_STD struct NAME<_Tp, __void_t > : true_type {} // __pointer -template , - bool = __has_pointer<_RawAlloc>::value> -struct __pointer { - using type _LIBCPP_NODEBUG = typename _RawAlloc::pointer; -}; -template -struct __pointer<_Tp, _Alloc, _RawAlloc, false> { - using type _LIBCPP_NODEBUG = _Tp*; -}; +template +using __pointer_member _LIBCPP_NODEBUG = typename _Tp::pointer; + +template +using __pointer _LIBCPP_NODEBUG = __detected_or_t<_Tp*, __pointer_member, __libcpp_remove_reference_t<_Alloc> >; // __const_pointer _LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_const_pointer, const_pointer); @@ -62,7 +58,7 @@ struct __const_pointer { template struct __const_pointer<_Tp, _Ptr, _Alloc, false> { #ifdef _LIBCPP_CXX03_LANG - using type = typename pointer_traits<_Ptr>::template rebind::other; + using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind::other; #else using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind; #endif @@ -99,13 +95,11 @@ struct __const_void_pointer<_Ptr, _Alloc, false> { }; // __size_type -_LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_size_type, size_type); -template ::value> -struct __size_type : make_unsigned<_DiffType> {}; +template +using __size_type_member _LIBCPP_NODEBUG = typename _Tp::size_type; + template -struct __size_type<_Alloc, _DiffType, true> { - using type _LIBCPP_NODEBUG = typename _Alloc::size_type; -}; +using __size_type _LIBCPP_NODEBUG = __detected_or_t<__make_unsigned_t<_DiffType>, __size_type_member, _Alloc>; // __alloc_traits_difference_type _LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_alloc_traits_difference_type, difference_type); @@ -119,40 +113,38 @@ struct __alloc_traits_difference_type<_Alloc, _Ptr, true> { }; // __propagate_on_container_copy_assignment -_LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_propagate_on_container_copy_assignment, propagate_on_container_copy_assignment); -template ::value> -struct __propagate_on_container_copy_assignment : false_type {}; +template +using __propagate_on_container_copy_assignment_member _LIBCPP_NODEBUG = + typename _Tp::propagate_on_container_copy_assignment; + template -struct __propagate_on_container_copy_assignment<_Alloc, true> { - using type _LIBCPP_NODEBUG = typename _Alloc::propagate_on_container_copy_assignment; -}; +using __propagate_on_container_copy_assignment _LIBCPP_NODEBUG = + __detected_or_t; // __propagate_on_container_move_assignment -_LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_propagate_on_container_move_assignment, propagate_on_container_move_assignment); -template ::value> -struct __propagate_on_container_move_assignment : false_type {}; +template +using __propagate_on_container_move_assignment_member _LIBCPP_NODEBUG = + typename _Tp::propagate_on_container_move_assignment; + template -struct __propagate_on_container_move_assignment<_Alloc, true> { - using type _LIBCPP_NODEBUG = typename _Alloc::propagate_on_container_move_assignment; -}; +using __propagate_on_container_move_assignment _LIBCPP_NODEBUG = + __detected_or_t; // __propagate_on_container_swap -_LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_propagate_on_container_swap, propagate_on_container_swap); -template ::value> -struct __propagate_on_container_swap : false_type {}; +template +using __propagate_on_container_swap_member _LIBCPP_NODEBUG = typename _Tp::propagate_on_container_swap; + template -struct __propagate_on_container_swap<_Alloc, true> { - using type _LIBCPP_NODEBUG = typename _Alloc::propagate_on_container_swap; -}; +using __propagate_on_container_swap _LIBCPP_NODEBUG = + __detected_or_t; // __is_always_equal -_LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_is_always_equal, is_always_equal); -template ::value> -struct __is_always_equal : is_empty<_Alloc> {}; +template +using __is_always_equal_member _LIBCPP_NODEBUG = typename _Tp::is_always_equal; + template -struct __is_always_equal<_Alloc, true> { - using type _LIBCPP_NODEBUG = typename _Alloc::is_always_equal; -}; +using __is_always_equal _LIBCPP_NODEBUG = + __detected_or_t::type, __is_always_equal_member, _Alloc>; // __allocator_traits_rebind _LIBCPP_SUPPRESS_DEPRECATED_PUSH @@ -177,7 +169,7 @@ struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, false> { _LIBCPP_SUPPRESS_DEPRECATED_POP template -using __allocator_traits_rebind_t = typename __allocator_traits_rebind<_Alloc, _Tp>::type; +using __allocator_traits_rebind_t _LIBCPP_NODEBUG = typename __allocator_traits_rebind<_Alloc, _Tp>::type; _LIBCPP_SUPPRESS_DEPRECATED_PUSH @@ -244,20 +236,18 @@ _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(allocation_result); template struct _LIBCPP_TEMPLATE_VIS allocator_traits { - using allocator_type = _Alloc; - using value_type = typename allocator_type::value_type; - using pointer = typename __pointer::type; - using const_pointer = typename __const_pointer::type; - using void_pointer = typename __void_pointer::type; - using const_void_pointer = typename __const_void_pointer::type; - using difference_type = typename __alloc_traits_difference_type::type; - using size_type = typename __size_type::type; - using propagate_on_container_copy_assignment = - typename __propagate_on_container_copy_assignment::type; - using propagate_on_container_move_assignment = - typename __propagate_on_container_move_assignment::type; - using propagate_on_container_swap = typename __propagate_on_container_swap::type; - using is_always_equal = typename __is_always_equal::type; + using allocator_type = _Alloc; + using value_type = typename allocator_type::value_type; + using pointer = __pointer; + using const_pointer = typename __const_pointer::type; + using void_pointer = typename __void_pointer::type; + using const_void_pointer = typename __const_void_pointer::type; + using difference_type = typename __alloc_traits_difference_type::type; + using size_type = __size_type; + using propagate_on_container_copy_assignment = __propagate_on_container_copy_assignment; + using propagate_on_container_move_assignment = __propagate_on_container_move_assignment; + using propagate_on_container_swap = __propagate_on_container_swap; + using is_always_equal = __is_always_equal; #ifndef _LIBCPP_CXX03_LANG template @@ -275,13 +265,13 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits { }; #endif // _LIBCPP_CXX03_LANG - _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static pointer + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static pointer allocate(allocator_type& __a, size_type __n) { return __a.allocate(__n); } template ::value, int> = 0> - _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static pointer + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static pointer allocate(allocator_type& __a, size_type __n, const_void_pointer __hint) { _LIBCPP_SUPPRESS_DEPRECATED_PUSH return __a.allocate(__n, __hint); @@ -290,7 +280,7 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits { template ::value, int> = 0> - _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static pointer + [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static pointer allocate(allocator_type& __a, size_type __n, const_void_pointer) { return __a.allocate(__n); } @@ -369,12 +359,12 @@ template using __rebind_alloc _LIBCPP_NODEBUG = typename _Traits::template rebind_alloc<_Tp>; #else template -using __rebind_alloc = typename _Traits::template rebind_alloc<_Tp>::other; +using __rebind_alloc _LIBCPP_NODEBUG = typename _Traits::template rebind_alloc<_Tp>::other; #endif template struct __check_valid_allocator : true_type { - using _Traits = std::allocator_traits<_Alloc>; + using _Traits _LIBCPP_NODEBUG = std::allocator_traits<_Alloc>; static_assert(is_same<_Alloc, __rebind_alloc<_Traits, typename _Traits::value_type> >::value, "[allocator.requirements] states that rebinding an allocator to the same type should result in the " "original allocator"); diff --git a/system/lib/libcxx/include/__memory/array_cookie.h b/system/lib/libcxx/include/__memory/array_cookie.h new file mode 100644 index 0000000000000..806a9e99ecafe --- /dev/null +++ b/system/lib/libcxx/include/__memory/array_cookie.h @@ -0,0 +1,55 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___MEMORY_ARRAY_COOKIE_H +#define _LIBCPP___MEMORY_ARRAY_COOKIE_H + +#include <__config> +#include <__configuration/abi.h> +#include <__cstddef/size_t.h> +#include <__type_traits/integral_constant.h> +#include <__type_traits/is_trivially_destructible.h> +#include <__type_traits/negation.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +// Trait representing whether a type requires an array cookie at the start of its allocation when +// allocated as `new T[n]` and deallocated as `delete[] array`. +// +// Under the Itanium C++ ABI [1], we know that an array cookie is available unless `T` is trivially +// destructible and the call to `operator delete[]` is not a sized operator delete. Under ABIs other +// than the Itanium ABI, we assume there are no array cookies. +// +// [1]: https://itanium-cxx-abi.github.io/cxx-abi/abi.html#array-cookies +#ifdef _LIBCPP_ABI_ITANIUM +// TODO: Use a builtin instead +// TODO: We should factor in the choice of the usual deallocation function in this determination. +template +struct __has_array_cookie : _Not > {}; +#else +template +struct __has_array_cookie : false_type {}; +#endif + +template +// Avoid failures when -fsanitize-address-poison-custom-array-cookie is enabled +_LIBCPP_HIDE_FROM_ABI _LIBCPP_NO_SANITIZE("address") size_t __get_array_cookie(_Tp const* __ptr) { + static_assert( + __has_array_cookie<_Tp>::value, "Trying to access the array cookie of a type that is not guaranteed to have one"); + size_t const* __cookie = reinterpret_cast(__ptr) - 1; // TODO: Use a builtin instead + return *__cookie; +} + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___MEMORY_ARRAY_COOKIE_H diff --git a/system/lib/libcxx/include/__memory/assume_aligned.h b/system/lib/libcxx/include/__memory/assume_aligned.h index 526eb3334f958..08f1772cd6dfa 100644 --- a/system/lib/libcxx/include/__memory/assume_aligned.h +++ b/system/lib/libcxx/include/__memory/assume_aligned.h @@ -12,8 +12,8 @@ #include <__assert> #include <__config> +#include <__cstddef/size_t.h> #include <__type_traits/is_constant_evaluated.h> -#include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -23,7 +23,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template -_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp* __assume_aligned(_Tp* __ptr) { +[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp* __assume_aligned(_Tp* __ptr) { static_assert(_Np != 0 && (_Np & (_Np - 1)) == 0, "std::assume_aligned(p) requires N to be a power of two"); if (__libcpp_is_constant_evaluated()) { diff --git a/system/lib/libcxx/include/__memory/builtin_new_allocator.h b/system/lib/libcxx/include/__memory/builtin_new_allocator.h deleted file mode 100644 index c6f7f3c5ff52a..0000000000000 --- a/system/lib/libcxx/include/__memory/builtin_new_allocator.h +++ /dev/null @@ -1,67 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCPP___MEMORY_BUILTIN_NEW_ALLOCATOR_H -#define _LIBCPP___MEMORY_BUILTIN_NEW_ALLOCATOR_H - -#include <__config> -#include <__memory/unique_ptr.h> -#include -#include - -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -# pragma GCC system_header -#endif - -_LIBCPP_BEGIN_NAMESPACE_STD - -// __builtin_new_allocator -- A non-templated helper for allocating and -// deallocating memory using __builtin_operator_new and -// __builtin_operator_delete. It should be used in preference to -// `std::allocator` to avoid additional instantiations. -struct __builtin_new_allocator { - struct __builtin_new_deleter { - typedef void* pointer_type; - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __builtin_new_deleter(size_t __size, size_t __align) - : __size_(__size), __align_(__align) {} - - _LIBCPP_HIDE_FROM_ABI void operator()(void* __p) const _NOEXCEPT { - std::__libcpp_deallocate(__p, __size_, __align_); - } - - private: - size_t __size_; - size_t __align_; - }; - - typedef unique_ptr __holder_t; - - _LIBCPP_HIDE_FROM_ABI static __holder_t __allocate_bytes(size_t __s, size_t __align) { - return __holder_t(std::__libcpp_allocate(__s, __align), __builtin_new_deleter(__s, __align)); - } - - _LIBCPP_HIDE_FROM_ABI static void __deallocate_bytes(void* __p, size_t __s, size_t __align) _NOEXCEPT { - std::__libcpp_deallocate(__p, __s, __align); - } - - template - _LIBCPP_NODEBUG _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI static __holder_t __allocate_type(size_t __n) { - return __allocate_bytes(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)); - } - - template - _LIBCPP_NODEBUG _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI static void - __deallocate_type(void* __p, size_t __n) _NOEXCEPT { - __deallocate_bytes(__p, __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)); - } -}; - -_LIBCPP_END_NAMESPACE_STD - -#endif // _LIBCPP___MEMORY_BUILTIN_NEW_ALLOCATOR_H diff --git a/system/lib/libcxx/include/__memory/compressed_pair.h b/system/lib/libcxx/include/__memory/compressed_pair.h index 40e5cfc35fb04..38798a21fa3c9 100644 --- a/system/lib/libcxx/include/__memory/compressed_pair.h +++ b/system/lib/libcxx/include/__memory/compressed_pair.h @@ -11,161 +11,95 @@ #define _LIBCPP___MEMORY_COMPRESSED_PAIR_H #include <__config> -#include <__fwd/tuple.h> -#include <__tuple/tuple_indices.h> -#include <__type_traits/decay.h> -#include <__type_traits/dependent_type.h> -#include <__type_traits/enable_if.h> -#include <__type_traits/is_constructible.h> +#include <__cstddef/size_t.h> +#include <__type_traits/datasizeof.h> #include <__type_traits/is_empty.h> #include <__type_traits/is_final.h> -#include <__type_traits/is_same.h> -#include <__type_traits/is_swappable.h> -#include <__utility/forward.h> -#include <__utility/move.h> -#include <__utility/piecewise_construct.h> -#include +#include <__type_traits/is_reference.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header #endif -_LIBCPP_PUSH_MACROS -#include <__undef_macros> - _LIBCPP_BEGIN_NAMESPACE_STD -// Tag used to default initialize one or both of the pair's elements. -struct __default_init_tag {}; -struct __value_init_tag {}; - -template ::value && !__libcpp_is_final<_Tp>::value> -struct __compressed_pair_elem { - using _ParamT = _Tp; - using reference = _Tp&; - using const_reference = const _Tp&; - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem(__default_init_tag) {} - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem(__value_init_tag) : __value_() {} - - template >::value, int> = 0> - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem(_Up&& __u) - : __value_(std::forward<_Up>(__u)) {} +// ================================================================================================================== // +// The utilites here are for staying ABI compatible with the legacy `__compressed_pair`. They should not be used // +// for new data structures. Use `_LIBCPP_NO_UNIQUE_ADDRESS` for new data structures instead (but make sure you // +// understand how it works). // +// ================================================================================================================== // -#ifndef _LIBCPP_CXX03_LANG - template - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 explicit __compressed_pair_elem( - piecewise_construct_t, tuple<_Args...> __args, __tuple_indices<_Indices...>) - : __value_(std::forward<_Args>(std::get<_Indices>(__args))...) {} -#endif - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 reference __get() _NOEXCEPT { return __value_; } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const_reference __get() const _NOEXCEPT { return __value_; } - -private: - _Tp __value_; -}; +// The first member is aligned to the alignment of the second member to force padding in front of the compressed pair +// in case there are members before it. +// +// For example: +// (assuming x86-64 linux) +// class SomeClass { +// uint32_t member1; +// _LIBCPP_COMPRESSED_PAIR(uint32_t, member2, uint64_t, member3); +// } +// +// The layout with __compressed_pair is: +// member1 - offset: 0, size: 4 +// padding - offset: 4, size: 4 +// member2 - offset: 8, size: 4 +// padding - offset: 12, size: 4 +// member3 - offset: 16, size: 8 +// +// If the [[gnu::aligned]] wasn't there, the layout would instead be: +// member1 - offset: 0, size: 4 +// member2 - offset: 4, size: 4 +// member3 - offset: 8, size: 8 +// +// Furthermore, that alignment must be the same as what was used in the old __compressed_pair layout, so we must +// handle reference types specially since alignof(T&) == alignof(T). +// See https://github.com/llvm/llvm-project/issues/118559. -template -struct __compressed_pair_elem<_Tp, _Idx, true> : private _Tp { - using _ParamT = _Tp; - using reference = _Tp&; - using const_reference = const _Tp&; - using __value_type = _Tp; - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem() = default; - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem(__default_init_tag) {} - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem(__value_init_tag) : __value_type() {} - - template >::value, int> = 0> - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair_elem(_Up&& __u) - : __value_type(std::forward<_Up>(__u)) {} - -#ifndef _LIBCPP_CXX03_LANG - template - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 - __compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args, __tuple_indices<_Indices...>) - : __value_type(std::forward<_Args>(std::get<_Indices>(__args))...) {} -#endif +#ifndef _LIBCPP_ABI_NO_COMPRESSED_PAIR_PADDING - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 reference __get() _NOEXCEPT { return *this; } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const_reference __get() const _NOEXCEPT { return *this; } -}; +template +inline const size_t __compressed_pair_alignment = _LIBCPP_ALIGNOF(_Tp); -template -class __compressed_pair : private __compressed_pair_elem<_T1, 0>, private __compressed_pair_elem<_T2, 1> { -public: - // NOTE: This static assert should never fire because __compressed_pair - // is *almost never* used in a scenario where it's possible for T1 == T2. - // (The exception is std::function where it is possible that the function - // object and the allocator have the same type). - static_assert( - (!is_same<_T1, _T2>::value), - "__compressed_pair cannot be instantiated when T1 and T2 are the same type; " - "The current implementation is NOT ABI-compatible with the previous implementation for this configuration"); - - using _Base1 _LIBCPP_NODEBUG = __compressed_pair_elem<_T1, 0>; - using _Base2 _LIBCPP_NODEBUG = __compressed_pair_elem<_T2, 1>; - - template , _Dummy>::value && - __dependent_type, _Dummy>::value, - int> = 0> - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair() - : _Base1(__value_init_tag()), _Base2(__value_init_tag()) {} - - template - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __compressed_pair(_U1&& __t1, _U2&& __t2) - : _Base1(std::forward<_U1>(__t1)), _Base2(std::forward<_U2>(__t2)) {} - -#ifndef _LIBCPP_CXX03_LANG - template - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 explicit __compressed_pair( - piecewise_construct_t __pc, tuple<_Args1...> __first_args, tuple<_Args2...> __second_args) - : _Base1(__pc, std::move(__first_args), typename __make_tuple_indices::type()), - _Base2(__pc, std::move(__second_args), typename __make_tuple_indices::type()) {} -#endif +template +inline const size_t __compressed_pair_alignment<_Tp&> = _LIBCPP_ALIGNOF(void*); - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 typename _Base1::reference first() _NOEXCEPT { - return static_cast<_Base1&>(*this).__get(); - } - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR typename _Base1::const_reference first() const _NOEXCEPT { - return static_cast<_Base1 const&>(*this).__get(); - } - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 typename _Base2::reference second() _NOEXCEPT { - return static_cast<_Base2&>(*this).__get(); - } - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR typename _Base2::const_reference second() const _NOEXCEPT { - return static_cast<_Base2 const&>(*this).__get(); - } - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR static _Base1* __get_first_base(__compressed_pair* __pair) _NOEXCEPT { - return static_cast<_Base1*>(__pair); - } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR static _Base2* __get_second_base(__compressed_pair* __pair) _NOEXCEPT { - return static_cast<_Base2*>(__pair); - } - - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void swap(__compressed_pair& __x) - _NOEXCEPT_(__is_nothrow_swappable_v<_T1>&& __is_nothrow_swappable_v<_T2>) { - using std::swap; - swap(first(), __x.first()); - swap(second(), __x.second()); - } +template ::value && !__libcpp_is_final<_ToPad>::value) || + is_reference<_ToPad>::value || sizeof(_ToPad) == __datasizeof_v<_ToPad>)> +class __compressed_pair_padding { + char __padding_[sizeof(_ToPad) - __datasizeof_v<_ToPad>] = {}; }; -template -inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void -swap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y) - _NOEXCEPT_(__is_nothrow_swappable_v<_T1>&& __is_nothrow_swappable_v<_T2>) { - __x.swap(__y); -} +template +class __compressed_pair_padding<_ToPad, true> {}; + +# define _LIBCPP_COMPRESSED_PAIR(T1, Initializer1, T2, Initializer2) \ + _LIBCPP_NO_UNIQUE_ADDRESS __attribute__((__aligned__(::std::__compressed_pair_alignment))) T1 Initializer1; \ + _LIBCPP_NO_UNIQUE_ADDRESS ::std::__compressed_pair_padding _LIBCPP_CONCAT3(__padding1_, __LINE__, _); \ + _LIBCPP_NO_UNIQUE_ADDRESS T2 Initializer2; \ + _LIBCPP_NO_UNIQUE_ADDRESS ::std::__compressed_pair_padding _LIBCPP_CONCAT3(__padding2_, __LINE__, _) + +# define _LIBCPP_COMPRESSED_TRIPLE(T1, Initializer1, T2, Initializer2, T3, Initializer3) \ + _LIBCPP_NO_UNIQUE_ADDRESS \ + __attribute__((__aligned__(::std::__compressed_pair_alignment), \ + __aligned__(::std::__compressed_pair_alignment))) T1 Initializer1; \ + _LIBCPP_NO_UNIQUE_ADDRESS ::std::__compressed_pair_padding _LIBCPP_CONCAT3(__padding1_, __LINE__, _); \ + _LIBCPP_NO_UNIQUE_ADDRESS T2 Initializer2; \ + _LIBCPP_NO_UNIQUE_ADDRESS ::std::__compressed_pair_padding _LIBCPP_CONCAT3(__padding2_, __LINE__, _); \ + _LIBCPP_NO_UNIQUE_ADDRESS T3 Initializer3; \ + _LIBCPP_NO_UNIQUE_ADDRESS ::std::__compressed_pair_padding _LIBCPP_CONCAT3(__padding3_, __LINE__, _) + +#else +# define _LIBCPP_COMPRESSED_PAIR(T1, Name1, T2, Name2) \ + _LIBCPP_NO_UNIQUE_ADDRESS T1 Name1; \ + _LIBCPP_NO_UNIQUE_ADDRESS T2 Name2 + +# define _LIBCPP_COMPRESSED_TRIPLE(T1, Name1, T2, Name2, T3, Name3) \ + _LIBCPP_NO_UNIQUE_ADDRESS T1 Name1; \ + _LIBCPP_NO_UNIQUE_ADDRESS T2 Name2; \ + _LIBCPP_NO_UNIQUE_ADDRESS T3 Name3 +#endif // _LIBCPP_ABI_NO_COMPRESSED_PAIR_PADDING _LIBCPP_END_NAMESPACE_STD -_LIBCPP_POP_MACROS - #endif // _LIBCPP___MEMORY_COMPRESSED_PAIR_H diff --git a/system/lib/libcxx/include/__memory/construct_at.h b/system/lib/libcxx/include/__memory/construct_at.h index eb02132480064..1f129d17970b1 100644 --- a/system/lib/libcxx/include/__memory/construct_at.h +++ b/system/lib/libcxx/include/__memory/construct_at.h @@ -14,13 +14,12 @@ #include <__config> #include <__iterator/access.h> #include <__memory/addressof.h> -#include <__memory/voidify.h> +#include <__new/placement_new_delete.h> #include <__type_traits/enable_if.h> #include <__type_traits/is_array.h> #include <__utility/declval.h> #include <__utility/forward.h> #include <__utility/move.h> -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -38,7 +37,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD template ()) _Tp(std::declval<_Args>()...))> _LIBCPP_HIDE_FROM_ABI constexpr _Tp* construct_at(_Tp* __location, _Args&&... __args) { _LIBCPP_ASSERT_NON_NULL(__location != nullptr, "null pointer given to construct_at"); - return ::new (std::__voidify(*__location)) _Tp(std::forward<_Args>(__args)...); + return ::new (static_cast(__location)) _Tp(std::forward<_Args>(__args)...); } #endif @@ -49,7 +48,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp* __construct_at(_Tp* __l return std::construct_at(__location, std::forward<_Args>(__args)...); #else return _LIBCPP_ASSERT_NON_NULL(__location != nullptr, "null pointer given to construct_at"), - ::new (std::__voidify(*__location)) _Tp(std::forward<_Args>(__args)...); + ::new (static_cast(__location)) _Tp(std::forward<_Args>(__args)...); #endif } diff --git a/system/lib/libcxx/include/__memory/destruct_n.h b/system/lib/libcxx/include/__memory/destruct_n.h index 78635ad0af04b..db227a4ea1dc7 100644 --- a/system/lib/libcxx/include/__memory/destruct_n.h +++ b/system/lib/libcxx/include/__memory/destruct_n.h @@ -10,9 +10,9 @@ #define _LIBCPP___MEMORY_DESTRUCT_N_H #include <__config> +#include <__cstddef/size_t.h> #include <__type_traits/integral_constant.h> #include <__type_traits/is_trivially_destructible.h> -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -25,35 +25,35 @@ struct __destruct_n { size_t __size_; template - _LIBCPP_HIDE_FROM_ABI void __process(_Tp* __p, false_type) _NOEXCEPT { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __process(_Tp* __p, false_type) _NOEXCEPT { for (size_t __i = 0; __i < __size_; ++__i, ++__p) __p->~_Tp(); } template - _LIBCPP_HIDE_FROM_ABI void __process(_Tp*, true_type) _NOEXCEPT {} + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __process(_Tp*, true_type) _NOEXCEPT {} - _LIBCPP_HIDE_FROM_ABI void __incr(false_type) _NOEXCEPT { ++__size_; } - _LIBCPP_HIDE_FROM_ABI void __incr(true_type) _NOEXCEPT {} + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __incr(false_type) _NOEXCEPT { ++__size_; } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __incr(true_type) _NOEXCEPT {} - _LIBCPP_HIDE_FROM_ABI void __set(size_t __s, false_type) _NOEXCEPT { __size_ = __s; } - _LIBCPP_HIDE_FROM_ABI void __set(size_t, true_type) _NOEXCEPT {} + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __set(size_t __s, false_type) _NOEXCEPT { __size_ = __s; } + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __set(size_t, true_type) _NOEXCEPT {} public: - _LIBCPP_HIDE_FROM_ABI explicit __destruct_n(size_t __s) _NOEXCEPT : __size_(__s) {} + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 explicit __destruct_n(size_t __s) _NOEXCEPT : __size_(__s) {} template - _LIBCPP_HIDE_FROM_ABI void __incr() _NOEXCEPT { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __incr() _NOEXCEPT { __incr(integral_constant::value>()); } template - _LIBCPP_HIDE_FROM_ABI void __set(size_t __s, _Tp*) _NOEXCEPT { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void __set(size_t __s, _Tp*) _NOEXCEPT { __set(__s, integral_constant::value>()); } template - _LIBCPP_HIDE_FROM_ABI void operator()(_Tp* __p) _NOEXCEPT { + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void operator()(_Tp* __p) _NOEXCEPT { __process(__p, integral_constant::value>()); } }; diff --git a/system/lib/libcxx/include/__memory/inout_ptr.h b/system/lib/libcxx/include/__memory/inout_ptr.h index e5f3ac5d027e8..b0e75937927cf 100644 --- a/system/lib/libcxx/include/__memory/inout_ptr.h +++ b/system/lib/libcxx/include/__memory/inout_ptr.h @@ -15,6 +15,7 @@ #include <__memory/pointer_traits.h> #include <__memory/shared_ptr.h> #include <__memory/unique_ptr.h> +#include <__type_traits/is_pointer.h> #include <__type_traits/is_same.h> #include <__type_traits/is_specialization.h> #include <__type_traits/is_void.h> diff --git a/system/lib/libcxx/include/__type_traits/noexcept_move_assign_container.h b/system/lib/libcxx/include/__memory/noexcept_move_assign_container.h similarity index 85% rename from system/lib/libcxx/include/__type_traits/noexcept_move_assign_container.h rename to system/lib/libcxx/include/__memory/noexcept_move_assign_container.h index baaf36d9980e9..b0063516aaafc 100644 --- a/system/lib/libcxx/include/__type_traits/noexcept_move_assign_container.h +++ b/system/lib/libcxx/include/__memory/noexcept_move_assign_container.h @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#ifndef _LIBCPP___TYPE_TRAITS_NOEXCEPT_MOVE_ASSIGN_CONTAINER_H -#define _LIBCPP___TYPE_TRAITS_NOEXCEPT_MOVE_ASSIGN_CONTAINER_H +#ifndef _LIBCPP___MEMORY_NOEXCEPT_MOVE_ASSIGN_CONTAINER_H +#define _LIBCPP___MEMORY_NOEXCEPT_MOVE_ASSIGN_CONTAINER_H #include <__config> #include <__memory/allocator_traits.h> @@ -34,4 +34,4 @@ struct __noexcept_move_assign_container _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP___TYPE_TRAITS_NOEXCEPT_MOVE_ASSIGN_CONTAINER_H +#endif // _LIBCPP___MEMORY_NOEXCEPT_MOVE_ASSIGN_CONTAINER_H diff --git a/system/lib/libcxx/include/__memory/out_ptr.h b/system/lib/libcxx/include/__memory/out_ptr.h index fd99110790cc8..030a4c3b0ed0b 100644 --- a/system/lib/libcxx/include/__memory/out_ptr.h +++ b/system/lib/libcxx/include/__memory/out_ptr.h @@ -15,6 +15,7 @@ #include <__memory/pointer_traits.h> #include <__memory/shared_ptr.h> #include <__memory/unique_ptr.h> +#include <__type_traits/is_pointer.h> #include <__type_traits/is_specialization.h> #include <__type_traits/is_void.h> #include <__utility/forward.h> diff --git a/system/lib/libcxx/include/__memory/pointer_traits.h b/system/lib/libcxx/include/__memory/pointer_traits.h index 0914aceb318b7..afe3d1bf8a2de 100644 --- a/system/lib/libcxx/include/__memory/pointer_traits.h +++ b/system/lib/libcxx/include/__memory/pointer_traits.h @@ -11,17 +11,19 @@ #define _LIBCPP___MEMORY_POINTER_TRAITS_H #include <__config> +#include <__cstddef/ptrdiff_t.h> #include <__memory/addressof.h> #include <__type_traits/conditional.h> #include <__type_traits/conjunction.h> #include <__type_traits/decay.h> +#include <__type_traits/enable_if.h> +#include <__type_traits/integral_constant.h> #include <__type_traits/is_class.h> #include <__type_traits/is_function.h> #include <__type_traits/is_void.h> #include <__type_traits/void_t.h> #include <__utility/declval.h> #include <__utility/forward.h> -#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header @@ -48,17 +50,17 @@ struct __pointer_traits_element_type {}; template struct __pointer_traits_element_type<_Ptr, true> { - typedef _LIBCPP_NODEBUG typename _Ptr::element_type type; + using type _LIBCPP_NODEBUG = typename _Ptr::element_type; }; template